Originally posted by: SoleGooseProductions
To be honest, I'm not sure at this point . Sadly, all I know is that my addition and subtraction routines work flawlessly, so far as I've been able to test them. Can't really argue with results, but I'm still curious about the transfer of values (or why a simple transfer won't work, but an addition is required).
The way I see it, there are 3 values:
- HexValue
- TempBinary
- carry
The Carry flag can be either 1 (if the flag is set) or 0 (if the flag is not set, or reset).
CLC means that you reset the carry flag to 00, so when you sum the value in the accumulator with the value after the opcode ADC, you will not add also +01.
Since there is not an instruction ADD WITHOUT CARRY, when you use ADC and you don't want the carry flag to influence the result, you just set the carry to 0.
In the example you posted above, you CLC twice, which is ok if it is what you need. Instead if you wish that an overflow in the first ADC adds +01 to the result of the second ADC, then you avoid that second CLC instruction.
As MegaMarioMan pointed out, this code:
LDA HexValue
STA TempBinary
is different than this code:
LDA TempBinary
CLC
ADC HexValue
STA TempBinary
Let say HexValue is == "x", TempBinary is == "y".
("x" and "y" are two values)
In the first case, after running your code, TempBinary will be == "x", because that is what you store into it with such code.
In the second case, after running your code TempBinary will be == "y"+Hex00+"x", since you load the old value, then you add the carry, and you add HexValue. In the socond case you are not moving a value from a variable to another, but you are summing, adding also the carry, the two values, and you are storing that result into TempBinary.
I feel like likely I am missing something you are trying to explain, but I think that if you look at your own two snippets of code for like 20 seconds, you will immediately realize that they don't do the same thing at all, math wise.
Hope this helps. ]]>