Example A Program to Add TwoByte Numbers

Object: Add the two-byte number stored at $00FC and $00FD to the two-byte number stored at $00FE and $00FF. Store the two-byte result in locations $0002 and $0003. For all numbers, the least-significant byte is stored in the location with the smallest address.

11 START CLC ;CLEAR CARRY BEFORE FIRST ADD. CO00 18

12 LDA +NUM1LO ?GET LSB OF FIRST NUMBER. C001 A5 FB

13 ADC +NUM2LO ;ADD LSB OF SECOND NUMBER. C003 65 FD

14 STA +SUMLSB ;STORE IN LSB OF SUM. C005 85 02

15 LDA +NUM1HI ;GET MSB OF FIRST NUMBER. C007 A5 FC

16 ADC +NUM2HI ;ADD CARRY AND MSB OF NUM2. CO09 65 FE

17 STA +SUMMSB ; STORE SUM IN MSB OF SUM. C00B 85 03

18 RTS C00D 60

After studying Examples 4-5 and 4-6, you should see that the only point in having an add with carry (ADC) instruction is to provide for the possibility of multibyte addition. If you always restrict yourself to adding eight-bit numbers, then the carry flag is unnecessary, since you will never use it to provide a carry to a more significant byte.

0 0

Post a comment

  • Receive news updates via email from this site