If you disassemble any version of Microsoft BASIC for 6502, you’ll find this code in a function that normalizes the (simulated) floating point accumulator:
NORMALIZE_FAC6: inc FAC ; MANTISSA CARRIED, SO SHIFT RIGHT beq OVERFLOW ; OVERFLOW IF EXPONENT TOO BIG ror FAC+1 ror FAC+2 ror FAC+3 ror FAC+4 ror FACEXTENSION rts
Well, not any BASIC. All versions of
- Commodore BASIC (all versions, since 1977)
- AppleSoft BASIC (all versions, since 1977)
- Microsoft BASIC for the OHIO Scientific (all versions, since 1977)
- Microsoft BASIC for the rare Mattel Intellivision Keyboard Component (1980)
use this code, but if you look at the disassembly of
- Microsoft BASIC for the MOS KIM-1 (1977)
- Microsoft BASIC for the Tangerine Microtan 65 (1979)
you will see this code instead:
NORMALIZE_FAC6: inc FAC beq OVERFLOW lda #$00 bcc @1 lda #$80 @1: lsr FAC+1 ora FAC+1 sta FAC+1 lda #$00 bcc @2 lda #$80 @2: lsr FAC+2 ora FAC+2 sta FAC+2 lda #$00 bcc @3 lda #$80 @3 lsr FAC+3 ora FAC+3 sta FAC+3 lda #$00 bcc @4 lda #$80 @4: lsr FAC+4 ora FAC+4 sta FAC+4 lda #$00 bcc @5 lda #$80 @5: lsr FACEXTENSION ora FACEXTENSION sta FACEXTENSION rts
(Actually, the OHIO Scientific and Intellivision versions work on a 3 byte (“6 digit”) instead of a 4 byte (“9 digit”) mantissa, so the “FAC+4” part is missing.)
Similar replacement has happened in other parts of the floating point library. It seems to be a compile-time option of the assembly source code.
Todays puzzle is to find out why there are two versions of this code, and why the different computer vendors chose to use one version or another.
See comments for solution.