The code is supposed to work out a MODulus operation to wrap a word offset from $7FFF to $0000 when incremented. I know that if I extend to long before adding 1, I get the correct answer, that's not the problem.
Code: Select all
start
clr.l d0 ; For return to SuperBASIC
move.w #$7FFF,d1 ; D1 = $xxxx 7FFF
addq.w #1,d1 ; D1 = $xxxx 8000
move.w d1,d2 ; D2 = $xxxx 8000
ext.l d1 ; D1 = $FFFF 8000
divu d2,d1 ; D1 = $FFFF 8000 WTH? Should be $0001 FFFF
swap d1 ; D1 = $8000 FFFF !!!!!!
rts

It works perfectly this way round, extending first before incrementing and the DIVU gives the correct result. This is the problem I'm demonstrating, but the result kept coming back wrong, so I had to find a small example that shows the fault.
Code: Select all
start
clr.l d0 ; For return to SuperBASIC
move.w #$7FFF,d1 ; D1 = $xxxx 7FFF
ext.l d1 ; D1 = $0000 7FFF
addq.l #1,d1 ; D1 = $0000 8000
move.w d1,d2 ; D2 = $xxxx 8000
divu d2,d1 ; D1 = $0000 0001
swap d1 ; D1 = $0001 0000
rts
If it helps any, the code is assembled with George Gwilt's GWASS assembler. Speaking of which, has anyone seen or heard anything from George? I haven't heard a thing for ages.
Cheers,
Norm.