2D Look up
#1
Member
Thread Starter
Join Date: Jul 2005
Location: CNY
Posts: 169
Likes: 0
Received 0 Likes
on
0 Posts
Car: 1991 Camaro RS
Engine: 355 Vortec TBI
Transmission: T56
2D Look up
I have been attempting to understand how the $61 code works. I've been looking at the source code for a little bit now. I've also read through various documents regarding the HC11 mcu (ie. pink book).
Now to the point. I commented a section of code, based on what I've learned so far, and was wondering if anyone would care to check my work to see if any of it is correct?
I started with a VE% adder table lookup routine and picked an arbitrary rpm value to work with. I think I screwed up somewhere around the negate instructions as the result of the routine is higher than both of the table values loaded into the accumulators.
Anyways, I would appreciate any help.
Here's the code:
;*==================================================
;* Lookup VE% from FL2 table
;*
;*
;*==================================================
LD573: 96 1B....................LDAA.......L001B..............; rpm/25 = 3300/25 = 132 = $84 ==>A
LD575: CE D2 F9...............LDX.........#$D2F9............; FL2 VE% tbl ==>0,X
LD578: BD FB 95...............JSR..........LFB95..............; Jump to 2d look up
;*==================================================
;* 2d lkup Subroutine
;* enter with A = 132 or $84
;* enter with X = #$D2F9 (FL2 VE% Table)
;*==================================================
LFB95: C6 10.....................LDAB.......#16...............; load B with 16 ==>B
LFB97: 3D.........................MUL.............................; A*B = 132*16 = 2112 = $0840 ==>AB or D
LFB98: 37.........................PSHB............................; Push B to stack = $40 = 64 *
LFB99: 16......................... TAB..............................; Transfer $08 (8) to B ==>B
LFB9A: 3A.........................ABX..............................; Add B to X = $08+D2F9 = $D301 ==>0,X
LFB9B: EC 00.....................LDD........0,X..................; Load A with 0,X (3200 rpm) = 112 = $70 ==>A
..........................................................................; Load B with 1,X (3600 rpm) = 102 = $66 ==>B
..........................................................................; OR 28774 = $7066 ==>D
;
; entry from 3d routine
;
LFB9D: 97 49.....................STAA......L0049...............; Store A at L0049 = $70 = 112 **
LFB9F: 10..........................SBA..............................; B-A = 112-102 = 10 = $0A ==>A
LFBA0: 33.........................PULB.............................; Pull B from stack = $40 = 64 ==>B
LFBA1: 25 09.....................BCS........LFBAC..............; Bra if SBA results in neg number???? False
LFBA3: 3D.........................MUL..............................; A*B = 10*64 = 640 = $0280 ==>AB or D
LFBA4: 40.........................NEGA.............................; Negate A = 0010 = 1101 = $0D = 13 ==>A
LFBA5: 9B 49.....................ADDA..... L0049...............; A+L0049 = 13+112 = 125 = $7D ==>A
LFBA7: 58.........................LSLB..............................; B*2 = 128*2 = 256 = $00 (C=1) ==>B
LFBA8: 82 00.....................SBCA......#0...................; A-M-C = 125-0-1 = 124 = $7C ==>A
LFBAA: 20 04.....................BRA........LFBB0...............; Branch to LFBB0
LFBAC: 40.........................NEGA.............................;
LFBAD: 3D.........................MUL..............................;
LFBAE: 99 49.....................ADCA......L0049...............;
LFBB0: 97 49.....................STAA......L0049...............; Store A at L0049 = $7C = 124 **
LFBB2: 39..........................RTS..............................; Return from subroutine
;*==================================================
;*
;* Back from 2d lkup subroutine
;*
;*==================================================
LD57B: 97 50.....................STAA......L0050...............; Store A at L0050 = $7C = 124 **
Now to the point. I commented a section of code, based on what I've learned so far, and was wondering if anyone would care to check my work to see if any of it is correct?
I started with a VE% adder table lookup routine and picked an arbitrary rpm value to work with. I think I screwed up somewhere around the negate instructions as the result of the routine is higher than both of the table values loaded into the accumulators.
Anyways, I would appreciate any help.
Here's the code:
;*==================================================
;* Lookup VE% from FL2 table
;*
;*
;*==================================================
LD573: 96 1B....................LDAA.......L001B..............; rpm/25 = 3300/25 = 132 = $84 ==>A
LD575: CE D2 F9...............LDX.........#$D2F9............; FL2 VE% tbl ==>0,X
LD578: BD FB 95...............JSR..........LFB95..............; Jump to 2d look up
;*==================================================
;* 2d lkup Subroutine
;* enter with A = 132 or $84
;* enter with X = #$D2F9 (FL2 VE% Table)
;*==================================================
LFB95: C6 10.....................LDAB.......#16...............; load B with 16 ==>B
LFB97: 3D.........................MUL.............................; A*B = 132*16 = 2112 = $0840 ==>AB or D
LFB98: 37.........................PSHB............................; Push B to stack = $40 = 64 *
LFB99: 16......................... TAB..............................; Transfer $08 (8) to B ==>B
LFB9A: 3A.........................ABX..............................; Add B to X = $08+D2F9 = $D301 ==>0,X
LFB9B: EC 00.....................LDD........0,X..................; Load A with 0,X (3200 rpm) = 112 = $70 ==>A
..........................................................................; Load B with 1,X (3600 rpm) = 102 = $66 ==>B
..........................................................................; OR 28774 = $7066 ==>D
;
; entry from 3d routine
;
LFB9D: 97 49.....................STAA......L0049...............; Store A at L0049 = $70 = 112 **
LFB9F: 10..........................SBA..............................; B-A = 112-102 = 10 = $0A ==>A
LFBA0: 33.........................PULB.............................; Pull B from stack = $40 = 64 ==>B
LFBA1: 25 09.....................BCS........LFBAC..............; Bra if SBA results in neg number???? False
LFBA3: 3D.........................MUL..............................; A*B = 10*64 = 640 = $0280 ==>AB or D
LFBA4: 40.........................NEGA.............................; Negate A = 0010 = 1101 = $0D = 13 ==>A
LFBA5: 9B 49.....................ADDA..... L0049...............; A+L0049 = 13+112 = 125 = $7D ==>A
LFBA7: 58.........................LSLB..............................; B*2 = 128*2 = 256 = $00 (C=1) ==>B
LFBA8: 82 00.....................SBCA......#0...................; A-M-C = 125-0-1 = 124 = $7C ==>A
LFBAA: 20 04.....................BRA........LFBB0...............; Branch to LFBB0
LFBAC: 40.........................NEGA.............................;
LFBAD: 3D.........................MUL..............................;
LFBAE: 99 49.....................ADCA......L0049...............;
LFBB0: 97 49.....................STAA......L0049...............; Store A at L0049 = $7C = 124 **
LFBB2: 39..........................RTS..............................; Return from subroutine
;*==================================================
;*
;* Back from 2d lkup subroutine
;*
;*==================================================
LD57B: 97 50.....................STAA......L0050...............; Store A at L0050 = $7C = 124 **
#2
Moderator
iTrader: (1)
Join Date: Mar 2002
Location: Chasing Electrons
Posts: 18,432
Likes: 0
Received 226 Likes
on
211 Posts
Car: check
Engine: check
Transmission: check
Yes, the negate is the issue. A NEG instruction is 2's compliment. The COM instruction is the 1's compliment. From the above code:
NEGA.............................; Negate A = 0010 = 1101 = $0D = 13 ==>A
should be:
NEGA.............................; Negate A = 0010 = 1111 1110 = $FE ==>A
(hope I got that correct)
$00 - $02 = $FE
RBob.
NEGA.............................; Negate A = 0010 = 1101 = $0D = 13 ==>A
should be:
NEGA.............................; Negate A = 0010 = 1111 1110 = $FE ==>A
(hope I got that correct)
$00 - $02 = $FE
RBob.
#3
Member
Thread Starter
Join Date: Jul 2005
Location: CNY
Posts: 169
Likes: 0
Received 0 Likes
on
0 Posts
Car: 1991 Camaro RS
Engine: 355 Vortec TBI
Transmission: T56
Ah yes... I forgot to negate the first four bits and didn't add 1 to the final result.
0000 0010 (Start)
1111 1101 (Negate)
0000 0001 (add 1)
1111 1110 (result) or $FE
Is this value considered signed at this point (-126)?
0000 0010 (Start)
1111 1101 (Negate)
0000 0001 (add 1)
1111 1110 (result) or $FE
Is this value considered signed at this point (-126)?
#4
Member
Thread Starter
Join Date: Jul 2005
Location: CNY
Posts: 169
Likes: 0
Received 0 Likes
on
0 Posts
Car: 1991 Camaro RS
Engine: 355 Vortec TBI
Transmission: T56
Just for kicks here is the corrected example. The final value appears to be correct.
;*==================================================
;* Lookup VE% from FL2 table
;*
;*
;*==================================================
LD573: 96 1B....................LDAA.......L001B..............; rpm/25 = 3300/25 = 132 = $84 ==>A
LD575: CE D2 F9...............LDX.........#$D2F9............; FL2 VE% tbl ==>0,X
LD578: BD FB 95...............JSR..........LFB95..............; Jump to 2d look up
;*==================================================
;* 2d lkup Subroutine
;* enter with A = 132 or $84
;* enter with X = #$D2F9 (FL2 VE% Table)
;*==================================================
LFB95: C6 10.....................LDAB.......#16...............; load B with 16 ==>B
LFB97: 3D.........................MUL.............................; A*B = 132*16 = 2112 = $0840 ==>AB or D
LFB98: 37.........................PSHB............................; Push B to stack = $40 = 64 *
LFB99: 16......................... TAB..............................; Transfer $08 (8) to B ==>B
LFB9A: 3A.........................ABX..............................; Add B to X = $08+D2F9 = $D301 ==>0,X
LFB9B: EC 00.....................LDD........0,X..................; Load A with 0,X (3200 rpm) = 112 = $70 ==>A
..........................................................................; Load B with 1,X (3600 rpm) = 102 = $66 ==>B
..........................................................................; OR 28774 = $7066 ==>D
;
; entry from 3d routine
;
LFB9D: 97 49.....................STAA......L0049...............; Store A at L0049 = $70 = 112 **
LFB9F: 10..........................SBA..............................; B-A = 112-102 = 10 = $0A ==>A
LFBA0: 33.........................PULB.............................; Pull B from stack = $40 = 64 ==>B
LFBA1: 25 09.....................BCS........LFBAC..............; Bra if SBA results in neg number???? False
LFBA3: 3D.........................MUL..............................; A*B = 10*64 = 640 = $0280 ==>AB or D
LFBA4: 40.........................NEGA.............................; Negate A = 0000 0010 = 1111 1110 = $FE = 254 ==>A
LFBA5: 9B 49.....................ADDA..... L0049...............; A+L0049 = 254+112 = 366 = $6E (V=1)(110) ==>A
LFBA7: 58.........................LSLB..............................; B*2 = 128*2 = 256 = $00 (C=1) ==>B
LFBA8: 82 00.....................SBCA......#0...................; A-M-C = 110-0-1 = 109 = $6D ==>A
LFBAA: 20 04.....................BRA........LFBB0...............; Branch to LFBB0
LFBAC: 40.........................NEGA.............................;
LFBAD: 3D.........................MUL..............................;
LFBAE: 99 49.....................ADCA......L0049...............;
LFBB0: 97 49.....................STAA......L0049...............; Store A at L0049 = $6D = 109 **
LFBB2: 39..........................RTS..............................; Return from subroutine
;*==================================================
;*
;* Back from 2d lkup subroutine
;*
;*==================================================
LD57B: 97 50.....................STAA......L0050...............; Store A at L0050 = $6D = 109 **
;*==================================================
;* Lookup VE% from FL2 table
;*
;*
;*==================================================
LD573: 96 1B....................LDAA.......L001B..............; rpm/25 = 3300/25 = 132 = $84 ==>A
LD575: CE D2 F9...............LDX.........#$D2F9............; FL2 VE% tbl ==>0,X
LD578: BD FB 95...............JSR..........LFB95..............; Jump to 2d look up
;*==================================================
;* 2d lkup Subroutine
;* enter with A = 132 or $84
;* enter with X = #$D2F9 (FL2 VE% Table)
;*==================================================
LFB95: C6 10.....................LDAB.......#16...............; load B with 16 ==>B
LFB97: 3D.........................MUL.............................; A*B = 132*16 = 2112 = $0840 ==>AB or D
LFB98: 37.........................PSHB............................; Push B to stack = $40 = 64 *
LFB99: 16......................... TAB..............................; Transfer $08 (8) to B ==>B
LFB9A: 3A.........................ABX..............................; Add B to X = $08+D2F9 = $D301 ==>0,X
LFB9B: EC 00.....................LDD........0,X..................; Load A with 0,X (3200 rpm) = 112 = $70 ==>A
..........................................................................; Load B with 1,X (3600 rpm) = 102 = $66 ==>B
..........................................................................; OR 28774 = $7066 ==>D
;
; entry from 3d routine
;
LFB9D: 97 49.....................STAA......L0049...............; Store A at L0049 = $70 = 112 **
LFB9F: 10..........................SBA..............................; B-A = 112-102 = 10 = $0A ==>A
LFBA0: 33.........................PULB.............................; Pull B from stack = $40 = 64 ==>B
LFBA1: 25 09.....................BCS........LFBAC..............; Bra if SBA results in neg number???? False
LFBA3: 3D.........................MUL..............................; A*B = 10*64 = 640 = $0280 ==>AB or D
LFBA4: 40.........................NEGA.............................; Negate A = 0000 0010 = 1111 1110 = $FE = 254 ==>A
LFBA5: 9B 49.....................ADDA..... L0049...............; A+L0049 = 254+112 = 366 = $6E (V=1)(110) ==>A
LFBA7: 58.........................LSLB..............................; B*2 = 128*2 = 256 = $00 (C=1) ==>B
LFBA8: 82 00.....................SBCA......#0...................; A-M-C = 110-0-1 = 109 = $6D ==>A
LFBAA: 20 04.....................BRA........LFBB0...............; Branch to LFBB0
LFBAC: 40.........................NEGA.............................;
LFBAD: 3D.........................MUL..............................;
LFBAE: 99 49.....................ADCA......L0049...............;
LFBB0: 97 49.....................STAA......L0049...............; Store A at L0049 = $6D = 109 **
LFBB2: 39..........................RTS..............................; Return from subroutine
;*==================================================
;*
;* Back from 2d lkup subroutine
;*
;*==================================================
LD57B: 97 50.....................STAA......L0050...............; Store A at L0050 = $6D = 109 **