[Gmecm] 68HC11 assembler help needed
Rob Handley
Robin
Sun Aug 26 09:00:13 UTC 2007
Many thanks Scot. :-) It hadn't occurred to me that one number might be a
fraction - but it does make the calling code make more sense!
R
----- Original Message -----
From: "Scot Sealander" <ssealander at Stny.rr.com>
To: <gmecm at diy-efi.org>
Sent: 26 August 2007 00:12
Subject: RE: [Gmecm] 68HC11 assembler help needed
> You are trying to make the code fit what you think it does, not what it
> actually does. You haven't considered the radix point of the numbers.
> ACC
> A is a fraction in this case. In your example, ACC A = 45 decimal. So
> 45/256 is 0.176. The other number in the INDEX is 571. So 0.176 times
> 571
> is 100.4, so it looks like you did the math just fine.
>
> Scot
>
> -----Original Message-----
> From: gmecm-bounces at diy-efi.org [mailto:gmecm-bounces at diy-efi.org] On
> Behalf
> Of Rob Handley
> Sent: Saturday, August 25, 2007 11:28 AM
> To: gmecm at diy-efi.org
> Subject: [Gmecm] 68HC11 assembler help needed
>
> 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
>
> _______________________________________________
> Gmecm mailing list
> Gmecm at diy-efi.org
> Subscribe: http://lists.diy-efi.org/mailman/listinfo/gmecm
> Main WWW page: http://www.diy-efi.org/gmecm
>
> _______________________________________________
> Gmecm mailing list
> Gmecm at diy-efi.org
> Subscribe: http://lists.diy-efi.org/mailman/listinfo/gmecm
> Main WWW page: http://www.diy-efi.org/gmecm
>
More information about the Gmecm
mailing list