A89: Addx


[Prev][Next][Index][Thread]

A89: Addx




 > I'm not sure if anyone other than Jimmy knows the answer to this. . . his
 > 68k guide lists addx, but I'm not clear on whether this adds what's already
 > in the X flag BEFORE adding or what's in the X flag AFTER adding (I hope
 > someone can actually understand that =).

Of course it adds what's there *before* (as described in the 68k
User's Manual, by the way ...).

It is used for adding numbers larger than 32 bit, you add the low 32
bits forst then the top ones after but to get the right result you
must add the carry from the bottom part to the top part:

foo:   ds.l   2   ; it is an 8 byte variable
bar:   ds.l   2   ; it is an other one
res:   ds.l   2   ; this will be the 8-byte result

; adds foo and bar together and stores the sum in 'res'.

foo_plus_bar:
   move.l foo+4,d0     ; fetch the low order 32 bits of foo to d0
   add.l  bar+4,d0     ; add the low o. 32 bits to it, it will set X
   move.l d0,res+4     ; store the low 32 bits of the result
   move.l foo,d0       ; load the high 32 bits of foo to d0
   addx.l bar,d0       ; add the upper 32 bits of bar *and* X to it
   move.l d0,res       ; and finally store the top 32 bits of the result

Note, that addx can not set the Z bit in the PSW, it can only clear
it, which results that after the addx the Z bit is correct (also note
that the final move will ruin in :-)

Regards,

Zoltan



References: