Page 1 of 1

ASSEMBLY coding A6 relative

Posted: Sun Jan 17, 2016 8:05 pm
by tcat
Hi,

I started a small code to compare two strings using UT.CSTR utility vectored routine. It takes str1 in A0, str2 in A1, must be relative to A6. I was suprised I actually needed to substract two adresses to get the strings relative to A6.

This works, but is there a shorter coding possible, in a single instruction?

movea.l a6,a0 strings relative to a6
suba.l str1,a0 string str1

Code follows here...

Code: Select all

; compare two strings
;
         movea.l  a6,a0      strings relative to a6
         suba.l   str1,a0    string str1
         movea.l  a6,a1    
         suba.l   str2,a1    string str2
         moveq    #$0,d0     type=0 case sensitive
;
         movea.w  $e6,a5     UT.CSTR
         jsr      (a5)
         lea      res,a5
         move.l   d0,(a5)    store result
;
         clr.b    d0
         rts
;
res      ds.l     1          result at offset 30($1e)
str1     dc.w     4,'ABCD'
str2     dc.w     3,'ABC'
         dc.w     0
;
         end
Tom

Re: ASSEMBLY coding A6 relative

Posted: Sun Jan 17, 2016 10:52 pm
by tofro
Tcat,
A6-relative just means the adddresses are added on access, so a

Code: Select all

   suba.l a6,a6               ; fast way to clear a6
   lea.l string1(pc),a0
   lea.l string2(pc),a1
   .....
works just as well. You're not in S*BASIC (I hope), so you are free to change a6. In case you need it afterwards (maybe it points to your data space), save it to the stack.

The reason for that complicated way of doing things is that when your code runs inside a BASIC context (as an S*BASIC extension or called from a CALL), everything needs to be relative to a6, because S*BASIC might move its variable area at any point in time. EXECed programs are free to use a6 for whatever purpose they want.

Regards,
Tobias

Re: ASSEMBLY coding A6 relative

Posted: Mon Jan 18, 2016 7:41 pm
by tcat
Tobias,

Ah, I see that's the S*BASIC movable area pointed to by A6.
Many thanks

Tom