[Gmecm] 68HC11 assembler help needed
Rob Handley
Robin
Sat Aug 25 15:28:17 UTC 2007
Aargh. My brain hurts. Been bashing it against the $58 code at $F650 - which
appears to be a routine to multiply a 16 bit number by an 8 bit number. But
my worked example doesn't work - so my understanding of the code must be
wrong.
In my worked example, I set the 16 bit number (pointed to by X register) to:
571 (MSB = 2, LSB = 59), and the 8 bit (stored in A register) to: 45.
Here's the code, with my worked example in [square brackets]:
; start of routine
F650: PSHX
F651: PSHA
F652: LDAB 1,X ; (8 bit) B = contents of (X+1) = LSB of incoming 16 bit
quantity [B = 59]
F654: MUL ; (16 bit) D = A * B [D = 45 * 59 = 2655 = $0A5F so
MSB(A) = 10 & LSB(B) = 95]
F655: ADCA #$00 ; A = A + 0 + carry [A = 10 + 0 + 0 = 10]
In D, we now have the 1st of the 2 part calculation - the result of the LSB
of the 16 bit quantity multiplied by the 8 bit quantity. The MSB (A) is now
saved (on the stack), but the LSB (B) seems to be lost (this can't be
right):
F657: PSHA ; Copy (8 bit) A to stack [10]
F658: LDAA 0,X ; (8 bit) A = contents of (X+0) = MSB of incoming 16 bit
quantity [A = 2]
F65A: TSX ; (16 bit) X = stack pointer+1 (so X is address of
last byte on stack)
F65B: LDAB 1,X ; B = contents of (X+1) i.e. last but one byte on stack
= incoming value of A [B = 45]
F65D: MUL ; (16 bit) D = A * B [D = 2 * 45 = 90 so MSB(A) = 0 &
LSB(B) = 90]
F65E: ADDB 0,X ; B = B + contents of (X+0) i.e. relative stack address
(-3) = earlier value of A [B = 90 + 10 = 100]
F660: ADCA #$00 ; A = A + 0 + carry [A = 0 + 0 + 0 = 0]
At this point we should have 100 in A and 95 in B, to make D = 25695 = 571 *
45, but I make the above: 0 in A and 100 in B. Help!
F662: PULX
F663: PULX
F664: RTS
; end of routine
Can someone please tell me where I'm going wrong!
Robin
More information about the Gmecm
mailing list