How to compare two characters in assembly - Motorola 68000

90 views Asked by At

I am trying to use CMP to compare a value stored in a stack frame with a character.

I have have done this but I keep getting invalid addressing mode. The only time i have got it to work is by storing 'B' into a data register. But the subroutine this is in has to be transparent as it is part of the activity, so I can't modify data registers.

CMP.B -1(A6),#'B'

I have also tried storing 'B' into the stack frame and doing

CMP.B -1(A6),-2(A6)

But this also gives invalid addressing mode. Please let me know any solutions that can keep the subroutine transparent.

2

There are 2 answers

0
chtz On

The second operand of the CMP instruction needs to be a data register. Alternatively, CMPA takes an address register as second operand, or CMPI takes an immediate value as first operand. That means, you could write:

 CMPI.B #'B',-1(A6)

Many assemblers will likely also accept cmp.b #'B',-1(A6) and translate it to a CMPI instruction.

1
vogomatix On

But the subroutine this is in has to be transparent as it is part of the activity, so I can't modify data registers.

Of course you can. You push the contents of the data registers onto the stack at the start of your subroutine, and put them back at the end

 # Save registers you're using on stack...
 MOVEM.L D0-D1,-(A7)
 # use D0 and D1 here
 MOVE.B  -2(A6),D0
 CMP.B   -1(A6),D0
 # Put data registers back to original
 MOVEM.L (A7)+,D0-D1