View Single Post
  #963  
Old 12-25-2009, 04:07 PM
b3lha's Avatar
b3lha b3lha is offline
Phil & Belha
 
Join Date: Aug 2001
Location: Alcyone Limited, Buckinghamshire UK
Posts: 2,671
Re: Memory dump of ECU

Quote:
Originally Posted by RoughSilver92 View Post
Nice.
Now I am slightly stuck with these eor commands. I've looked it up in the software manual, but the explanation doesn't make it any clearer for me. May as well make sure about the sbc also.

00E22D A422 ldy dp + 0x22 ; Read from A/D successive approximation register
00E22F 98 tya
00E230 38 sec
00E231 EDD411 sbc ax, 0x11d4
00E234 B004 bcs 0xe23a
00E236 49FFFF eor ax, #0xffff

So here the tps value from the A/D converter is loaded to index register y.
It is then transferred to register a.
The carry flag is set (C=1).
The value stored at 11d4 is subtracted from register a.
If the result is greater than or equal to zero the program branches to e23a.
I know this much.
With the carry flag set does it also subtract 1 from register a (ie. A=A-(0x11d4 +1))?
What does the eor compare? We have the value in register a and the hex value ffff, but what about them? There doesn't seem to be enough values to do anything with.

It looks like the majority of the eors use #0xff or #0xffff. I don't know what the significance of this is. Right now it is just an observation.
Very good work Andy. I'm impressed.

On this type of processor, you have to set the carry flag before a subtraction in order to get the right answer. If you look through the code you'll see an SEC before every SBC.

I can't explain it very well, but the reason is that the subtract instruction is designed so that when you are subtracting 16bit numbers, you can do it in 2 chunks of 8 bits at a time. The carry flag stores the sign of the result of each subtraction and it gets fed into the next stage of the subtraction. There's an example of this at EC68 where it subtracts a 16 bit value at 1098(and 1099) from a 16 bit value at 1096 (and 1097). But It's not really important to understand how that mechanism works, as long as you can recognise when you see it.

EOR, also known as XOR, is a boolean "exclusive-or" operation. It means either/or but not both. If you want to XOR two 8 bit numbers, you line them up on top of each other and calculate each column separately. The result is 1 if the bits are different and 0 if they are the same.

11000011
10101110
---------
01101101

An XOR by FF, in the case of a byte, or FFFF in the case of a word, is the same as a NOT operation. Every zero will be changed to a 1 and every one will be changed to a zero.

This piece of code here:
Code:
00E236    49FFFF        eor     ax, #0xffff
00E239    3A            inc     ax
Does a NOT of AX register and adds one. In "two's-complement" arithmetic, this is how you convert a negative number to a positive number or vice-versa.
For example:
11111011 is -5. If you XOR by FF (11111111) you get 00000100 which is +4. Add 1 and you get +5.

So the code is saying, do the subtraction, and if the result is negative, convert it to positive. If the result is positive then it jumps over that bit of code and continues with the positive value.

I hope that makes sense.
__________________
Subaru ECU and TCU Website
1992 Alcyone SVX Version L
1992 Alcyone SVX Version L
1994 Alcyone SVX S40-II
2004 Subaru Legacy 2.5 SE Sports Tourer
1996 Subaru Legacy 2.2 GX Wagon
1988 Subaru Justy J12 SL-II
Reply With Quote