×   Main Menu ALL The 8BS News Manuals (New menu) Links Worth a Look Tools Disc and Basic Webring Site Map 8BS Guestbook Old Guest Book Me The Barnsley Rovers   
8-Bit Software

The BBC and Master Computer Public Domain Library


BASIC IV ROM Routines


Integer Addition Routine

Submitted by Steve Fewell

Routine: iplus
Name: Integer Addition
Starting Address: &9E65
Entry criteria: IWA contains the first Integer number. ?&4 and ?&5 [The BASIC stack pointer] points to the second Integer variable. X = The next operator code (or 4, if there is no further operation).
Exit: IWA contains the result of [Integer variable + IWA]

Description:
Adds the 32-bit Integer pointed to by the BASIC Stack Pointer (&4 (lo),&5 (hi)) to the number in the IWA.  The least significant byte [&2A] is added first, followed by &2B, &2C and &2D (The most significant byte). The carry flag allows any overflow to be carried forward and updated to the next significant byte of the number.

The code from &9E82 updates the Stack pointer, so that it now points to the address after the added number. To do this, 4 bytes are added to the address pointed to by (&4, &5).

Jump to &9E4F to test the value of X [the next operator]. If X contains the operator code for '+' or '-' then send the result to the appropriate routine, for further calculation, otherwise exit the addition routine.

Disassembly for the integer addition routine

9E65   024 18 CLC
9E66   178 004 B2 04 LDA (&04)
9E68 e* 101 042 65 2A ADC &2A
9E6A * 133 042 85 2A STA &2A
9E6C   160 001 A0 01 LDY#&01
9E6E   177 004 B1 04 LDA (&04),Y
9E70 e+ 101 043 65 2B ADC &2B
9E72 + 133 043 85 2B STA &2B
9E74   200 C8 INY
9E75   177 004 B1 04 LDA (&04),Y
9E77 e, 101 044 65 2C ADC &2C
9E79 , 133 044 85 2C STA &2C
9E7B   200 C8 INY
9E7C   177 004 B1 04 LDA (&04),Y
9E7E e- 101 045 65 2D ADC &2D
9E80 - 133 045 85 2D STA &2D
9E82   024 18 CLC
9E83   165 004 A5 04 LDA &04
9E85 i 105 004 69 04 ADC#&04
9E87   133 004 85 04 STA &04
9E89 @ 169 064 A9 40 LDA#&40
9E8B   144 194 90 C2 BCC -62 --> &9E4F
9E8D   230 005 E6 05 INC &05
9E8F   128 190 80 BE BRA -66 --> &9E4F
9E4F + 224 043 E0 2B CPX#&2B
9E51   240 005 F0 05 BEQ 5 --> &9E58
9E53 - 224 045 E0 2D CPX#&2D
9E55 f 240 102 F0 66 BEQ 102 --> &9EBD
9E57 ` 096 60 RTS


 Back to 8BS
Or