Add with Carry Example
Hi,
I have been really struggling to understand this simple example from Mastering Machine Code and I wonder if anyone can help?
I have included the op codes, and my comments as to what I think is happening:
Therefore BC = 4CAE
I'm obviously getting confused because I thought with load HL etc, then the H is the last number, and L is the first.
Also the carry flag is not being set in the wrong place in my calculations, and the answer should be 44,876 (Decimal) or AF4C (Hexadecimal)!
Thanks
I have been really struggling to understand this simple example from Mastering Machine Code and I wonder if anyone can help?
I have included the op codes, and my comments as to what I think is happening:
LD DE,3385 LD HL,7BC7 LD A,L ;A = 7B ADD A,E ;A = 7B + 33 = AE LD L,A ;L = AE LD A,H ;A = C7 ADC A,D ;A = C7 + 85 = 14C so A set to 4C and carry flag set LD H,A ;H = 4C LD B,H ;B = 4C LD C,L ;C = AE RET
Therefore BC = 4CAE
I'm obviously getting confused because I thought with load HL etc, then the H is the last number, and L is the first.
Also the carry flag is not being set in the wrong place in my calculations, and the answer should be 44,876 (Decimal) or AF4C (Hexadecimal)!
Thanks
Post edited by jonesypeter on

Comments
After
D = $33
E = $85
H = $7B
L = $C7
HTH,
Derek
I thought with LD HL etc, then the number were switched around?
In the book it says with the instruction LD HL the first byte is 21h as you would expect, the second byte is the new value of L, and the third byte is the new value of H
Turns out the good folk at Intel named the H(i)L(o) register pair for a reason at the 8080 design stage...
:)