Hi there,

I thought i knew and understood how to add and subtract using the aritmetic instructions ADC and SEC, but these docs seem tp be proving me wrong.

ok in addition you CLC - clear tha carry flag and in subtraction you SEC - set the carry flag. point taken.

but whats this??

22 + 20 = 24?

and in subtraction? whats this about?

sorry if i'm being an meganoob here, but this makes no sense to me.

I thought i knew and understood how to add and subtract using the aritmetic instructions ADC and SEC, but these docs seem tp be proving me wrong.

ok in addition you CLC - clear tha carry flag and in subtraction you SEC - set the carry flag. point taken.

but whats this??

**Code:**

A 16-bit addition routine. $20,$21 + $22,$23 = $24,$25

CLC clear the carry

LDA $20 get the low byte of the first number

ADC $22 add to it the low byte of the second

STA $24 store in the low byte of the result

LDA $21 get the high byte of the first number

ADC $23 add to it the high byte of the second, plus carry

STA $25 store in high byte of the result

CLC clear the carry

LDA $20 get the low byte of the first number

ADC $22 add to it the low byte of the second

STA $24 store in the low byte of the result

LDA $21 get the high byte of the first number

ADC $23 add to it the high byte of the second, plus carry

STA $25 store in high byte of the result

22 + 20 = 24?

and in subtraction? whats this about?

**Code:**

Ex.2

----

A 16-bit subtraction routine. $20,$21 - $22,$23 = $24,$25

SEC clear the carry

LDA $20 get the low byte of the first number

SBC $22 add to it the low byte of the second

STA $24 store in the low byte of the result

LDA $21 get the high byte of the first number

SBC $23 add to it the high byte of the second, plus carry

STA $25 store in high byte of the result

----

A 16-bit subtraction routine. $20,$21 - $22,$23 = $24,$25

SEC clear the carry

LDA $20 get the low byte of the first number

SBC $22 add to it the low byte of the second

STA $24 store in the low byte of the result

LDA $21 get the high byte of the first number

SBC $23 add to it the high byte of the second, plus carry

STA $25 store in high byte of the result

sorry if i'm being an meganoob here, but this makes no sense to me.