Integer BASIC
Integer BASIC is a dialect of the BASIC programming language, developed by Steve Wozniak and implemented as an interpreter in 6502 assembly language for the Apple I and original Apple II computers.[1][2] It was designed specifically for the 6502 microprocessor, supporting signed 16-bit integer arithmetic exclusively, without floating-point capabilities, which led to its name and made it suitable for games and integer-based engineering tasks.[1][2] Released in June 1977 with the Apple II, it served as the system's built-in programming environment, accessible via a command-line interface symbolized by a right-facing arrow (>).[3]
Wozniak created Integer BASIC during evenings while employed at Hewlett-Packard, aiming to produce the first BASIC interpreter for the 6502 to accompany his custom hardware designs.[1] He initially envisioned floating-point support but simplified it to integers for quicker development, dubbing it "Game BASIC" internally, and completed the core engine in about two months using a modular syntax table and stack-based parsing.[1] The language included innovative features such as color graphics commands tailored for the Apple II, a built-in mini-assembler for direct 6502 machine code integration, and a Sweet16 virtual machine interpreter for executing 16-bit bytecode efficiently.[1][2] These elements allowed users to create interactive programs, utilities, and games, with early software like Breakout and ColorMath distributed on cassette tapes.[1]
Despite its strengths, Integer BASIC had notable limitations, including rudimentary string handling that deviated from standard Microsoft BASIC conventions and no support for floating-point math, which restricted its use in scientific or business applications requiring decimals.[1][3] It lacked a comprehensive manual, relying instead on a basic tutorial, though enthusiasts dissected its internals through publications like Call-A.P.P.L.E. magazine.[3] By 1978, growing user demand for advanced features prompted Apple to license Microsoft's floating-point BASIC, leading to Applesoft BASIC's introduction as Applesoft I in January 1978 and Applesoft II later that year, which offered high-resolution graphics and better compatibility.[3] Integer BASIC was phased out from Apple II+ ROMs to accommodate Applesoft but remained accessible via firmware cards or DOS commands (INT for Integer mode, FP for Applesoft), preserving compatibility with thousands of early programs until at least 1979.[2][3]
Historically, Integer BASIC played a pivotal role in the Apple II's success, empowering a generation of hobbyists and educators to program directly on the machine and fostering the personal computing revolution.[3] Its efficient, compact design—fitting into just 8 KB of ROM—demonstrated Wozniak's ingenuity and influenced subsequent language implementations, while its loyal user base highlighted the value of accessible, integer-focused programming in the late 1970s.[1][3]
History
Development
Integer BASIC was developed by Steve Wozniak, beginning in late 1975 and completed by early 1976, specifically for the Apple I computer, marking his effort to create the first BASIC interpreter for the 6502 microprocessor.[1] Initially referred to as "Game BASIC," the project stemmed from Wozniak's desire to provide immediate programming accessibility on a low-cost personal computer, drawing on his evenings spent coding while employed at Hewlett-Packard.[1] Lacking prior experience with BASIC, Wozniak self-taught the language's structure by studying an HP 9830 BASIC manual, the Microsoft BASIC developed by Bill Gates and Paul Allen for the Altair 8800, and the book 101 BASIC Computer Games by David Ahl, which influenced the inclusion of game-oriented features.[4][5][1]
The interpreter was entirely hand-assembled in 6502 machine code, with Wozniak manually translating assembly instructions into hexadecimal without the aid of a high-level assembler, a process he repeated frequently to test and refine the code on prototype hardware.[4][6] This labor-intensive approach took approximately two months to complete the core engine, featuring a modular design with a syntax table storing commands as text strings (such as "PRINT" represented by its five letters) and separate routines for operators and expressions.[1] Wozniak sketched syntax charts and employed stacks for nouns and verbs to parse programs efficiently, enabling the interpreter to fit within the Apple I's constrained environment.[4]
Central to the design were goals of speed and simplicity for games and educational or engineering applications on hardware limited to 4 KB of RAM, leading Wozniak to prioritize integer arithmetic over more complex floating-point operations.[1][4][6] By focusing on 16-bit signed integers ranging from -32768 to 32767, the interpreter avoided the space and time demands of floating-point support, which Wozniak estimated would have delayed development by weeks; this choice aligned with the logical, non-decimal needs of simulations and arcade-style games like Breakout.[1][5] The resulting compact implementation required users to supply at least 4 KB of RAM via external DRAM chips, emphasizing accessibility for hobbyists on a budget.[4]
Release and Adoption
Integer BASIC was first distributed with the Apple I computer in 1976, provided on a cassette tape that loaded the interpreter into memory in approximately 30 seconds.[7] The Apple I's standard configuration included 4 KB of RAM, which was the minimum required to run the interpreter, though the motherboard supported expansion up to 8 KB via additional sockets.[8] Loading from cassette often encountered issues related to audio signal quality and tape condition, leading to incomplete or corrupted loads that necessitated manual entry of program patches to resolve bugs.
With the release of the Apple II in 1977, Integer BASIC was integrated directly into the motherboard ROM as part of firmware revision 0, occupying four 2 KB EPROM chips.[9] This allowed the system to autostart the interpreter upon power-up, eliminating the need for external loading and making programming immediately accessible. Integer BASIC was bundled as the standard programming environment with all early Apple II units produced from 1977 onward, serving as the primary tool for users until the introduction of the Apple II Plus in 1979.[10] The Apple II Plus replaced Integer BASIC in ROM with the more feature-rich Applesoft BASIC, which supported floating-point arithmetic and became the default interpreter for subsequent models.[10] Despite its phase-out, Integer BASIC saw widespread adoption among educators and hobbyists in the late 1970s, powering introductory programming courses and influencing the development of the initial Apple software ecosystem, including games and utilities distributed via cassette and later floppy disk.
Language Features
Syntax and Program Editing
Integer BASIC employs a line-based program structure, where each program line begins with an integer line number ranging from 0 to 32767, followed by a statement or multiple statements separated by colons (:). Lines entered without a line number are executed immediately in direct mode, allowing for on-the-fly testing of commands or expressions without storing them in the program. This design facilitates simple program organization and execution via the RUN command, which starts from the lowest numbered line.[11]
Program editing is managed through dedicated commands that operate in direct mode. The LIST command displays the stored program lines, optionally limited to a range such as LIST 100-200 for lines 100 through 200, aiding in review and debugging. DELETE removes specified lines, as in DELETE 50-100, to refine the program without retyping. RENUMBER reassigns line numbers sequentially, starting from a specified value (e.g., RENUMBER 10), which is essential after insertions or deletions to maintain orderly jumps in control flow. The AUTO command automates line entry by prompting for new lines with incrementally numbered suggestions, such as AUTO 100,10, streamlining program creation.[11][12][13]
The interpreter uses a greater-than symbol (>) as the ready prompt in direct mode and during program pauses, indicating acceptance of input. During program execution, the INPUT statement prompts for numeric data with a # symbol, while string inputs receive no additional prompt beyond any user-supplied text. This prompt system ensures clear user interaction without unnecessary output for strings.[11][14]
Text output occurs in a 40-column text window, initially limited to uppercase characters on early Apple II models, though later systems like the Apple IIe support lowercase via hardware flashing or mode switches. The window scrolls automatically when output exceeds the bottom row, with pausing possible using Control-S. Clearing the screen is achieved with the HOME command, which repositions the cursor to the top-left and erases the display.[11]
Syntax errors during entry or execution are reported immediately with a message such as "SYNTAX ERR RETYPE LINE ?" followed by the offending line number, preventing invalid lines from being stored and prompting re-entry. This line-specific feedback helps isolate issues efficiently.[11][12]
A distinctive feature is the absence of multi-line statements; all code must fit within a single line up to 128 characters, terminated by pressing RETURN (carriage return). Multiple statements per line are permitted using colons, but continuation across lines is not supported, enforcing concise code organization.[13][11]
Data Types and Variables
Integer BASIC primarily supports a single data type in its core language: 16-bit signed integers, ranging from -32,768 to 32,767.[15] This design choice optimized for the limited memory and processing capabilities of early microcomputers like the Apple II, where floating-point operations were absent to ensure faster execution and simpler implementation. All numeric variables and expressions are thus restricted to whole numbers within this range.[16]
Variable names in Integer BASIC can be up to 100 alphanumeric characters long, must begin with a letter (A-Z), and may include digits thereafter, though they cannot incorporate certain reserved substrings such as "AND", "OR", "NOT", "MOD", "AT", "TO", "STEP", or "THEN", nor start with "END", "IF", "INPUT", "LET", "ON", or "REM".[15] Notably, there are no strict reserved words preventing the use of command names as variables; for instance, "PRINT" can serve as a valid variable name, as the parser tokenizes keywords separately from identifiers.[17] Names are case-insensitive during parsing but preserved as entered in memory, allowing flexibility in program readability while maintaining compatibility with the system's uppercase-centric input. String variables are denoted by appending "" to the name (e.g., `A`), and are treated fundamentally as fixed-length arrays of characters rather than distinct types.[15]
Arrays are supported only in one dimension and must be explicitly dimensioned using the DIM statement before use, such as DIM A(10) to allocate space for 11 elements (indices 0 through 10).[15] Numeric arrays allocate approximately 2 bytes per element for integer storage, plus overhead for the array header, while strings can be dimensioned to a maximum length of 255 characters using DIM A$(255).[15] Sizing is dynamic in the sense that the last-declared array can be redimensioned with a subsequent DIM call, but attempting to resize a previously defined array results in an error; the maximum size is constrained by available RAM rather than a fixed limit, though practical bounds in minimal configurations often cap elements at around 255 due to addressing constraints.[14] There are no provisions for user-defined types or structures beyond these basics.
All variables, including arrays, are stored in dynamic RAM starting from address $0800 (decimal 2048) and growing upward until encountering the program's memory area, which expands downward from the top of available RAM (typically set by HIMEM).[15] Undeclared variables are automatically created upon first assignment and initialized to 0 for numerics or empty for strings; arrays are zero-filled upon dimensioning.[16] The total number of variables is limited solely by free memory after accounting for the program, stack, and system overhead—for example, in a basic 4 KB RAM configuration, roughly 100 simple numeric variables could be accommodated, consuming about 2 bytes of data plus 3-5 bytes of naming and linking overhead each.[16] Exceeding available space triggers a "MEM FULL ERR".[15]
Mathematical Operations
Integer BASIC supports a set of basic arithmetic operators for numerical computations, limited to 16-bit signed integers ranging from -32768 to 32767. The operators include addition (+), subtraction (-), multiplication (*), division (/), and exponentiation (^). Division performs integer truncation toward zero, such that 5 / 2 yields 2, while the remainder is obtained using the MOD function, as in 5 MOD 2 = 1. Exponentiation is implemented through repeated multiplication, restricting its use to non-negative integer exponents to avoid errors, and results are subject to the integer range limits.[15]
The language provides three built-in mathematical functions: ABS(expr), which returns the absolute value of the expression; SGN(expr), which returns -1 if expr is negative, 0 if zero, and 1 if positive; and RND(expr), which generates a pseudo-random integer. For RND, if expr is positive, it returns a value from 0 to expr-1 inclusive; if expr is zero, it repeats the previous random value; if expr is negative, it returns a value from 0 to -expr-1 inclusive. The random sequence is pseudo-random, starting from an initial seed of 1, and can be reseeded by directly modifying the generator's state in memory via POKE to location 78 (the low byte of the seed).[15][18]
Numerical computations in Integer BASIC lack advanced functions such as trigonometric operations (e.g., SIN, COS) or logarithms, requiring users to implement approximations using integer arithmetic if needed. Arithmetic overflow occurs when results exceed the 16-bit signed range, triggering an error message like ">32767 ERR" or "<-32768 ERR" and halting execution, rather than wrapping around silently. This behavior enforces strict bounds on calculations, emphasizing the language's design for simple, integer-based tasks.[15][18]
Example of integer division and modulo:
10 LET A = 17
20 LET B = 5
30 PRINT A / B REM Outputs 3
40 PRINT A MOD B REM Outputs 2
10 LET A = 17
20 LET B = 5
30 PRINT A / B REM Outputs 3
40 PRINT A MOD B REM Outputs 2
[15]
Example of random number generation:
10 PRINT RND(10) REM Outputs random integer 0-9
20 PRINT RND(0) REM Repeats previous value
30 PRINT RND(-5) REM Outputs random integer 0-4
10 PRINT RND(10) REM Outputs random integer 0-9
20 PRINT RND(0) REM Repeats previous value
30 PRINT RND(-5) REM Outputs random integer 0-4
[18]
String Handling
In Integer BASIC, strings are handled as a distinct data type, represented by variables suffixed with a dollar sign (e.g., A$), and treated as fixed-length arrays of characters with a maximum capacity of 255 characters.[13][19] These variables are implicitly declared upon first use, though they can be dimensioned with the DIM statement to set a maximum length (e.g., DIM B$(10) allocates space for B$ up to 10 characters, treating it as an array of characters).[19] Storage occurs in memory with a leading byte indicating the string's length, followed by the character data, enabling efficient but limited manipulation compared to later dialects like Applesoft BASIC.[13]
String concatenation is performed using the + operator, which combines two strings into a new one, subject to the 255-character limit; exceeding this triggers a "?STRING TOO LONG ERROR" (error code 176).[19] For example, if A$ = "HELLO" and B$ = " WORLD", then C$ = A$ + B$ results in C$ holding "HELLO WORLD".[19] In output contexts, the semicolon (;) can juxtapose strings without spaces in a PRINT statement (e.g., PRINT A$; B$), but this does not create a new concatenated variable.[19]
Key built-in functions for string manipulation include LEN(A$), which returns an integer representing the number of characters in the string (ranging from 0 to 255), and ASC(A$), which returns the ASCII code (0-255) of the string's first character.[13][19] For instance, PRINT LEN("ABC") outputs 3, and PRINT ASC("A") outputs 65.[19] There is no native CHR$ function to convert an integer ASCII code back to a character; programmers must use direct keyboard input or machine code routines for such conversions.
Substring extraction is supported using the syntax A(start, length), where start and length are integers, with 1-based indexing for the starting position. For example, A(3,5) returns the substring starting at the 3rd character for 5 characters. Individual characters can be accessed as A(i,1) or shorthand A(i).[20][11]
String comparisons use relational operators such as =, <, >, <=, >=, and # (for inequality), performed lexicographically based on ASCII values in a case-sensitive manner.[13][19] For example, "[ABC](/page/ABC)" < "DEF" evaluates to true because the ASCII value of 'A' (65) is less than 'D' (68), and comparisons proceed character by character until a difference is found or one string ends.[19] Shorter strings are considered less than longer ones if prefixes match (e.g., "AB" < "ABC").[13]
Input of strings is handled primarily through the INPUT statement, which reads user input from the keyboard into a string variable, optionally preceded by a prompt string (e.g., INPUT "Enter name: "; NAME$).[19] The input terminates with Enter, and the resulting string is trimmed of leading/trailing spaces unless specified otherwise; multiple variables can be read in one statement separated by commas.[13] Output uses the PRINT statement to display strings, with semicolons or commas controlling spacing and line breaks (e.g., PRINT NAME$; suppresses a trailing space and newline).[19] These mechanisms integrate strings into control structures like IF for conditional logic based on user-provided text.[13]
Control Structures and Debugging
Integer BASIC provides a set of basic control structures for managing program flow, including conditional branching, unconditional jumps, subroutines, and loops, all implemented using line-numbered statements typical of early BASIC dialects.[15] These structures rely on integer expressions for line references and variable conditions, emphasizing simplicity for the Apple II's limited resources. Notably, Integer BASIC lacks dedicated WHILE or DO loops, requiring programmers to simulate them using combinations of IF-THEN and GOTO statements.[13]
The IF-THEN statement enables conditional execution: IF expression THEN statement evaluates the expression (true if non-zero), and if true, executes the following statement, which can be a single command or an implied GOTO to a line number. For example:
10 IF A > 5 THEN [PRINT](/page/Print) "High"
10 IF A > 5 THEN [PRINT](/page/Print) "High"
This prints "High" only if variable A exceeds 5.[15] Unconditional branching uses GOTO: GOTO expression, which transfers control to the specified line number. An example is GOTO 100, jumping to line 100 regardless of conditions.[13]
Subroutines are handled by GOSUB and RETURN: GOSUB expression branches to the indicated line, saving the return address on a stack, while RETURN resumes execution after the calling GOSUB. Nesting is limited to 16 levels; exceeding this triggers a "16 GOSUBS ERR". A simple subroutine might appear as:
50 GOSUB 200
...
200 PRINT "Subroutine"
210 [RETURN](/page/Return)
50 GOSUB 200
...
200 PRINT "Subroutine"
210 [RETURN](/page/Return)
[15] FOR-NEXT loops provide iteration: FOR variable = start TO end [STEP increment] initializes the variable, executes statements until the end is reached (incrementing by 1 or the specified STEP value), and NEXT variable advances the loop. Up to 16 nested FOR loops are supported. An example loops ten times:
10 FOR I = 1 TO 10 STEP 1
20 PRINT I
30 NEXT I
10 FOR I = 1 TO 10 STEP 1
20 PRINT I
30 NEXT I
[13] Multi-way branching uses ON: ON expression GOSUB/GOTO line1, line2, ..., selecting the nth line (1-based) from the list based on the expression's integer value. For instance, ON X [GOTO](/page/Goto) 100, 200, 300 jumps to line 200 if X equals 2.[15]
Debugging aids in Integer BASIC include built-in tracing and monitoring tools integrated into the interpreter. The TRACE command activates line-by-line execution tracing, displaying each executed line number; NOTRACE deactivates it. For variable monitoring, DSP followed by variable names (e.g., DSP A, B) prints the variables' values whenever they change during execution, aiding in tracking state modifications. These features operate directly in the REPL environment without external tools.[13]
Program interruption uses Ctrl-C to halt execution at any point, displaying the current line number and returning to the prompt; execution can resume from that point using CONT. Error handling reports specific issues with abbreviated messages, such as ?SN ERROR for syntax violations (e.g., malformed statements) and ?RG ERROR for range errors (e.g., RETURN without a matching GOSUB or index out of bounds). Other errors include ?MEM FULL ERR for insufficient memory and ?BAD RETURN ERR for mismatched subroutine calls.[15] To terminate a program explicitly, END stops execution and clears the prompt, while STOP halts at the current line (resumable with CONT) without ending the session.[13]
Integer BASIC provided limited support for graphics on the Apple II, primarily through low-resolution mode, which offered a 40 by 40 pixel grid with 16 possible colors. The GR command switched the display to this mixed graphics mode, clearing the screen and reserving the bottom four lines for text input, while initializing the drawing color to black.[15] In this mode, the PLOT statement plotted a single pixel or dot at specified coordinates, using the syntax PLOT X, Y where X and Y ranged from 0 to 39; for example, PLOT 20, 15 would draw a point at that location using the current color.[15] The COLOR= statement set the active drawing color for subsequent plots, with values from 0 (black) to 15 (white or bright colors depending on the monitor), as in COLOR=6 to select blue; this affected all graphics operations until changed.[11] To return to text mode, the TEXT command restored the full 24-line by 40-column character display, positioning the cursor at the bottom.[15]
High-resolution graphics, offering a 280 by 192 pixel monochrome display with artifact colors, were not natively supported in Integer BASIC through dedicated commands like those in Applesoft BASIC. Instead, programmers accessed hi-res mode by POKEing soft switches, such as POKE 49234, 0 to enable it, but drawing required machine language subroutines invoked via USR calls or direct POKEs to the hi-res page memory starting at $2000; no built-in filled shapes or vector drawing were available, limiting complex visuals to manual pixel manipulation.[21] For instance, a basic hi-res setup might involve POKE -16384,0 to set the mode, followed by USR(1536) for a plotting routine loaded separately.[11]
Sound generation in Integer BASIC lacked dedicated statements, relying on direct hardware manipulation of the Apple II's single speaker, which produced square waves at a fixed volume. Programmers used POKE to toggle the speaker port at address $C030 (accessed as -16336 in BASIC), creating tones through timed loops; for example, the code 10 FOR I=1 TO 1000: POKE -16336,0: NEXT I would generate a short beep by rapidly toggling the speaker on and off, with loop length controlling frequency.[22] More sophisticated music required machine language routines POKE'd into memory and called via CALL, as BASIC loops were too slow for precise polyphony.[22]
Input capabilities included the PDL function for reading analog values from the game paddles (0-3), returning an integer from 0 to 255 representing knob position; for example, PDL(0) sampled the first paddle for game controls like position in a paddle-based game.[15] The GET statement captured a single keypress without echoing or pausing for input, storing the ASCII value in a string variable, as in GET K: IF K="A" THEN ... for non-blocking keyboard checks.[11]
Output and device handling used PR# n to redirect PRINT statements to peripherals in expansion slots (n=1 to 7, with PR#0 returning to the screen), such as PR#1 for a printer in slot 1 or PR#6 for a disk drive; similarly, IN# n shifted INPUT from the specified slot.[15] Cursor positioning in text mode was managed by HTAB col (column 1-40) and VTAB row (row 1-24), for example HTAB 20: VTAB 10 to move to a specific location before printing; XTAB functioned similarly to HTAB for horizontal positioning in some contexts.[15] These slot-based I/O commands enabled integration with printers, modems, or storage devices without additional software, though compatibility depended on the peripheral's firmware.[11]
Implementation
Interpreter Architecture
Integer BASIC employs a tokenized representation for program storage and execution, where source code lines are parsed into compact bytecode tokens during input. Each keyword, operator, and delimiter is replaced by a single-byte token, such as $A3 for PRINT, to minimize memory usage and accelerate processing. Numeric constants are preconverted to binary format, while string literals and variable names remain as nouns in the tokenized stream. These tokens are stored sequentially in the program area of RAM, with each statement prefixed by its line number for ordered execution.[23][24]
The execution model relies on a two-stack architecture to handle expressions and control flow. The noun stack manages operands, including variable addresses, constant values, and string lengths, while the verb stack (also called the operator or syntax stack) processes tokens based on operator precedence, executing higher-priority verbs first through recursive descent parsing. Statements are dispatched via token handlers in the interpreter's code, enabling efficient evaluation without recompilation. This design supports immediate execution of non-line-numbered commands and sequential interpretation of stored programs upon invocation.[23][24]
Memory layout is dynamically managed within the available RAM, starting with the program area at address $0800, followed by the variable table at $0A00 and beyond. Variables are allocated on first reference, growing upward until reaching the boundary defined by HIMEM (typically $1000 initially, adjustable for expansions up to 48K). Free RAM resides between the variable end and HIMEM, with LOMEM marking the low boundary for program storage; the interpreter automatically adjusts these limits to prevent overlaps.[23]
Upon power-up, a cold start loads the interpreter from ROM at E000, initializing stacks and memory pointers before entering command mode. Issuing RUN triggers a warm start at E2B3, clearing variables if needed and commencing execution from the lowest line number in the program area. The interpreter operates independently of an underlying OS, relying on direct hardware access for input/output.[23]
Hand-assembled in 6502 machine code by Steve Wozniak, the interpreter incorporates optimizations such as direct jumps to common operation handlers, reducing overhead for frequent verbs like PRINT and assignment. This approach, combined with the SWEET16 virtual machine for compact 16-bit emulation in extensions, ensures efficient performance on limited hardware.[23][24]
Error recovery involves unwinding the stacks upon detection, such as during syntax checks or runtime faults, and resetting the line pointer to the offending statement for user correction. Interruptions via Ctrl-C allow inspection and modification of variables before resuming with CONT, preserving the execution context where possible.[23]
ROM Integration and Extensions
Integer BASIC was integrated into the read-only memory (ROM) of the Apple II computer, occupying the address range from E000 to F424 within the overall ROM space of C000 to FFFF. This embedding enabled direct execution without loading from external media, with activation occurring through a cold start at E000 via Control-B or a warm start at E003 via Control-C, prompting the familiar ">" interface. In contrast to the Apple I version, which relied on cassette tape loading for its BASIC interpreter, the Apple II implementation was permanently stored in ROM, streamlining startup and enhancing accessibility for users. The ROM design also incorporated an autostart mechanism in later revisions, though original non-autostart versions required manual monitor commands to enter the interpreter.
A key extension within the ROM was the SWEET16 interpreter, a 16-bit virtual machine invented by Steve Wozniak and located from F689 to F7FC. SWEET16 utilized 16 registers (R0 to R15) mapped to zero-page locations $00 to $1F, supporting opcodes such as *CALL for subroutine invocation and *EXEC for direct code execution, with R15 serving as the program counter and R12 as the stack pointer. Designed for compactness, SWEET16 code was approximately half the size of equivalent 6502 assembly but executed 5 to 8 times slower, making it ideal for high-level subroutines like the program renumbering routine in Programmer's Aid #1. Entry to SWEET16 occurred via JSR F689, with 6502 registers preserved through dedicated SAVE (FF4A) and RESTORE ($FF3F) routines to avoid conflicts during operation.
The ROM further included a binary floating-point package from F425 to F65D, providing single-precision arithmetic with a 5-byte format: a combined sign and excess-128 exponent in the first byte, followed by a 24-bit normalized mantissa across three bytes, and an implicit leading 1 bit. Essential routines encompassed FADD for addition ($1F50 or F46E), FSUB for [subtraction](/page/Subtraction) ($1F4A or F468), FMUL for multiplication ($1F77 or F48C), FDIV for division ($1F9D or F4B2), FLOAT for integer-to-floating-point conversion (F451), FIX for floating-point-to-integer conversion (F640), along with functions like FABS for absolute value and FRND for rounding. Although Integer BASIC operated exclusively on 16-bit signed integers (-32768 to 32767), the floating-point routines could be invoked from BASIC programs using the USR function, which jumped to a user-specified machine language subroutine address stored at $3F8-3F9 via the entry at $FECA; activation often involved SWEET16's *EXEC opcode to interface with the package. These extensions incurred performance penalties due to their interpretive overhead and the additional storage required—5 bytes per number versus 2 bytes for integers—limiting their use to scenarios demanding non-integer precision.
Additional ROM components supported advanced interactions, including a mini-assembler from F500 to F63C that permitted one-line 6502 code assembly without labels or equates, accessible via the monitor entry at $F666G using the "!" prompt for input. The USR command facilitated seamless calls to custom machine language routines, passing arguments through USR(W) and executing at the poled address in $04-$05. These features, integral to the Apple II ROM but absent from the cassette-based Apple I Integer BASIC, expanded the system's programmability while maintaining compatibility with the core interpreter architecture.
Benchmarks and Comparisons
Integer BASIC demonstrated notable performance advantages in benchmarks focused on integer arithmetic and looping, owing to its avoidance of floating-point overhead. In the Sieve of Eratosthenes benchmark published by Byte magazine, Integer BASIC on the Apple II completed the test in approximately 166 seconds, generating 2320 prime flags, compared to over 200 seconds for Applesoft BASIC, which produced 2806 flags under similar conditions.[25] This test emphasized array access and control structures, areas where Integer BASIC's design excelled due to lower loop overhead and direct integer handling.[25]
Historical evaluations, including Whetstone-inspired integer benchmarks adapted for BASIC interpreters, highlighted Integer BASIC's superiority for game-oriented tasks involving rapid integer calculations and minimal data type conversions. For instance, simple loop-intensive programs ran faster in Integer BASIC than equivalent floating-point implementations on the same hardware, as the interpreter bypassed the computational cost of floating-point emulation.[26] Comparisons with Microsoft BASIC variants on comparable 6502-based systems, such as the Commodore PET, showed Integer BASIC outperforming in integer-heavy workloads by leveraging tighter integration with Apple II hardware routines, though it lagged in floating-point intensive code where Microsoft-derived interpreters like Applesoft provided native support.[25]
Memory efficiency further underscored Integer BASIC's strengths, occupying 8 KB in ROM compared to 12 KB for Applesoft BASIC, allowing more space for user programs on memory-constrained systems.[3] However, limitations emerged in areas without dedicated optimizations, such as string manipulation and graphics rendering, where unoptimized routines led to slower execution in complex programs relying on these features.[26]
Sample Programs
Sample programs in Integer BASIC demonstrate its syntax and capabilities. These examples are drawn from the official Apple II BASIC Programming Manual and standard references.[27]
Hello World
This basic program prints a greeting to the screen and ends.
10 [PRINT](/page/Print) "HELLO WORLD"
20 END
10 [PRINT](/page/Print) "HELLO WORLD"
20 END
When run, it outputs: HELLO WORLD[27]
Simple Number Loop
This program prints numbers from 1 to 10, showcasing the FOR-NEXT loop structure.
10 FOR I = 1 TO 10
20 [PRINT](/page/Print) I
30 NEXT I
40 END
10 FOR I = 1 TO 10
20 [PRINT](/page/Print) I
30 NEXT I
40 END
Output:
1
2
...
10[27]
Basic Graphics Example
Integer BASIC includes graphics commands for the Apple II. This program enters low-resolution graphics mode and plots a point.
10 GR
20 PLOT 0,0
30 END
10 GR
20 PLOT 0,0
30 END
This draws a single pixel at the origin in lo-res mode.[27]
Legacy
Influence and Preservation
Integer BASIC played a pivotal role in shaping early Apple education software, serving as the built-in programming language for the Apple II and enabling interactive computing in classrooms during the late 1970s and early 1980s.[3] Its simple syntax and immediate feedback loop made it ideal for novice users, including students, fostering widespread adoption of personal computing in educational settings.[28]
The interpreter's design influenced subsequent developments, notably inspiring the development of Applesoft BASIC, a Microsoft port that added floating-point support and other features while incorporating some command compatibility with Integer BASIC.[3] Steve Wozniak's philosophy emphasized efficient code generation, achieved through hand-assembly in 6502 machine language to optimize for the Apple II's constrained 8 KB ROM space and deliver fast execution without unnecessary overhead.[29]
By the 1980s, Integer BASIC was largely phased out in favor of Applesoft with the introduction of the Apple II Plus in 1979, though it remained available as an optional ROM upgrade into the early 1980s and formed the basis for backward-compatible BASIC support in later models like the Apple IIgs.[2]
Preservation efforts have ensured Integer BASIC's accessibility through emulators such as AppleWin, which simulates the original Apple II hardware including the Integer BASIC ROM, and GSport, an emulator for the Apple IIGS that supports loading and running Integer BASIC programs. The source code has been disassembled—originally by Eric Smith for the Apple I version and extended by Paul R. Santa-Maria for the Apple II—and archived on platforms like GitHub, where it remains available for study and modification in the 2020s.[30]
In modern retro computing communities, Integer BASIC continues to be employed for teaching 8-bit programming principles, with enthusiasts using it to explore low-level concepts on emulated or recreated hardware.[23] Ports to FPGA-based recreations of the Apple II allow original programs to run on contemporary field-programmable gate arrays, bridging vintage software with current technology.[31]
While the original interpreter lacks Unicode support, relying instead on 7-bit ASCII, modern tools like enhanced emulators and text editors provide compatibility layers to handle extended character sets during development and execution.[32]
Culturally, Integer BASIC featured prominently in educational literature.