I am working my way (very slowly) through Ian Birnbaum's excellent book on assembly language programming for the Beeb. I try as much as possible to follow along with each of his examples to make sure I'm understanding it fully. I'm stumped, though, because I've reached a point where I can't seem to re-create what he says I should be able to. There is a program in the book on page 25 (second edition) that can be used to add two unsigned bytes together where the result may be larger than 255. He later rewrites this program on page 54 using the INC command, and claims that by doing this the resulting assembled program is one byte less in size. But no matter what I try, both programs (the original and the rewritten version using INC) come out at 16 bytes in total. Am I missing something? I really do want to grasp why he says the use of INC is more efficient when adding two numbers whose result might be > 255 but I am struggling.

Original program:

Code: Select all

```
10 NUM1=&70 : NUM2=&71 : SUML=&72 : SUMH=&73
20 DIM P% 50
30 [OPT3
40 .START
50 LDA NUM1
60 CLC
70 ADC NUM2
80 STA SUML
90 LDA #0
100 STA SUMH
110 ADC SUMH
120 STA SUMH
130 RTS:]
140 REPEAT
150 INPUT"First number to be added",?NUM1
160 INPUT"Second number to be added",?NUM2
170 CALLSTART
180 PRINT?NUM1+?NUM2,256*?SUMH+?SUML
190 UNTIL FALSE
```

Code: Select all

```
10 NUM1=&70 : NUM2=&71 : SUML=&72 : SUMH=&73 : DIM START 50
20 FOR I%=0 TO 3 STEP 3 : P%=START
30 [OPTI%
50 LDA #0
60 STA SUMH
70 LDA NUM1
80 CLC
90 ADC NUM2
100 STA SUML
110 BCC NOCARRY
120 INC SUMH
130 .NOCARRY
140 RTS:]
150 NEXTI% : REPEAT
160 INPUT"First number to be added",?NUM1
170 INPUT"Second number to be added",?NUM2
180 CALLSTART
190 PRINT?NUM1+?NUM2,256*?SUMH+?SUML
200 UNTIL FALSE
```

Code: Select all

```
1A82 OPT3
1A82 .START
1A82 A5 70 LDA NUM1
1A84 18 CLC
1A85 65 71 ADC NUM2
1A87 85 72 STA SUML
1A89 A9 00 LDA #0
1A8B 85 73 STA SUMH
1A8D 65 73 ADC SUMH
1A8F 85 73 STA SUMH
1A91 60 RTS
```

Code: Select all

```
1AB8 OPTI%
1AB8 A9 00 LDA #0
1ABA 85 73 STA SUMH
1ABC A5 70 LDA NUM1
1ABE 18 CLC
1ABF 65 71 ADC NUM2
1AC1 85 72 STA SUML
1AC3 90 02 BCC NOCARRY
1AC5 E6 73 INC SUMH
1AC7 .NOCARRY
1AC7 60 RTS
```