BASIC on the Altair

A program that keeps a total

Keep a running total as a program works through several numbers. Give the current number and the total separate names, then use the same idea to add up successive ticket purchases.

View lesson source ↗

Continue your session, or load BASIC

If the terminal below already shows your earlier BASIC session, press the browser's RUN button to continue it. You do not need to load the tape again. This tab keeps the machine, program, terminal, and pending input as you move between BASIC lessons, visit All lessons, or refresh. Returning always pauses execution first. Other tabs work independently; a newly opened or duplicated tab may begin with a copy of this tab's saved session.

Begin a lesson's commands at OK. If your previous program is still asking a question at ?, finish that conversation first; the ticket loop finishes when you answer 0. The lesson's setup explains which stored lines to keep or replace. Typing NEW at OK clears the stored program and variables without reloading BASIC.

If this is a fresh machine, follow the loading steps below.

This is the original 4K BASIC 3.2 interpreter running on our Altair. An interpreter is a program that reads your commands and carries them out. Before it can understand PRINT, the Altair must load that interpreter into memory.

  1. Get the selected paper-tape file from the machine guide (opens in a new tab). Return here and choose it in Paper tape below. The file stays on your computer.
  2. Raise only switches A11 and A10. Leave PC at 0000: do not press EXAMINE. You may then close the front panel to bring the terminal closer.
  3. Press the browser's RUN button. Click Terminal keyboard and answer each question when it appears:
When you see Enter
MEMORY SIZE? Just Enter, to let BASIC find the available memory.
TERMINAL WIDTH? Just Enter, to keep the default.
WANT SIN? Y then Enter. We will not need this math function today.

When 727 BYTES FREE and OK appear, BASIC is ready. Leave the processor running for the lesson. Switching tabs pauses it; press the browser's RUN button when you return.

If you need to start loading again, use Start fresh, raise A11 and A10 again, then RUN. This discards the current BASIC program and uses the tape you already selected. Reset CPU + serial does not reload BASIC.

The saved session stays in this browser tab's temporary storage. It is not sent to the site. Copy your numbered lines somewhere to keep them beyond the browser session. If the browser cannot save or restore a session, a message beside the machine explains that; you can still use the current page.

A computer waiting for your instructions

From paper tape to BASIC.

Resume a saved session with RUN. To load BASIC for the first time, choose the 4K BASIC 3.2 tape (guide opens in a new tab), raise the loading switches, then RUN. Loading instructions

This tab can keep your BASIC session between lessons. Checking for a saved session…

The file stays on your computer. Selecting a verified tape prepares a fresh, stopped machine.

No tape selected.

Front panel · address, data, and sense switches

To load BASIC, raise only A11 and A10 and leave PC at 0000. Do not press EXAMINE after raising the loading switches. You can then close this panel to bring the terminal closer.

Operate the front panel

ALTAIR 8800

Memory and sense switches

Address lights PC · next instruction

0 decimal · 0000 hex

Data lights The byte at that location

0 decimal · 00 hex

A lit lamp is 1; a dark lamp is 0. The digits help you read the lights.

Data / address switches Up = 1 · Down = 0

15–8 · Address + sense

7–0 · Address or data

All switches as an address
0 decimal · 0000 hex
Lower eight as a byte
0 decimal · 00 hex

Setting the switches prepares a number. It does not read or write memory. The CPU can read the upper eight switches at port FF, even while running.

Select the address in the switches and read its byte.

Move to the next address and read its byte.

Write the lower eight switches to the selected address.

Move to the next address, then write the lower eight switches.

EXAMINE would select address 0. DEPOSIT would write 0 to the selected address, 0.

Last memory operation

Enable JavaScript to operate the panel.

EXAMINE and NEXT change PC. Only 0000–0FFF contain RAM; other addresses read FF and discard deposits. Lights show instruction boundaries, not individual bus cycles.

Stopped · 0 instructions

RUN lets the processor execute; STOP pauses it. At BASIC’s prompt, type RUN to run your BASIC program. Break sends Control-C to BASIC.


  
  

0 keyboard bytes queued

Use uppercase commands. Enter sends a line; Backspace sends BASIC’s erase character (_). Paste one line at a time. Only the machine’s echoes appear above.

Inspect the running machine

    

Latest twelve instructions on this page · PC before → after (hexadecimal)


  

Reset keeps RAM and the switches but resets the CPU and serial device. Start fresh discards the program, restores the bootstrap, rewinds the selected tape, and clears the terminal; raise the switches again before RUN.

Keep the counter

Load or resume BASIC using the instructions above, and begin at OK. If you continued directly from the previous lesson, keep its program and skip the setup block below. It should print 1 through 5.

If you are starting here or returning from a different lesson, type NEW and enter this program. Type one numbered line at a time, pressing Enter and waiting for its complete echo before the next:

Type, then Enter

NEW

BASIC replies

OK

Type one line at a time, then Enter

10 FOR N=1 TO 5
20 PRINT N
30 NEXT N
50 END

We already have a way to visit each number. Now we want to add those numbers together, keeping what we have added so far. We will call that total T.

Add to what we already have

Add line 5, replace line 20, and add line 40:

Type one line at a time, then Enter

5 LET T=0
20 LET T=T+N
40 PRINT T

Before the loop starts, line 5 sets T to zero: nothing has been added yet. Each time through the loop, LET T=T+N adds the current N to the old T, then stores the result back in T.

This works like LET N=N+1 in the counting lesson. We calculate from an old value and replace it with a new one. Here the amount being added is the current value of another variable, N.

LIST shows where the new instructions sit:

Type, then Enter

LIST

BASIC replies

5 LET T=0
10 FOR N=1 TO 5
20 LET T=T+N
30 NEXT N
40 PRINT T
50 END
OK

Line 20 is inside the loop, so it adds something on every trip. Line 40 is after NEXT, so it prints only when the loop has finished.

Predict the total. What is 1 + 2 + 3 + 4 + 5?

Type, then Enter

RUN

BASIC replies

 15

OK

Add the five numbers ↑

Two variables, two jobs

N selects the number being added. T remembers the sum so far. Follow them through the five trips to line 20:

N to add T before the addition T after the addition
1 0 1
2 1 3
3 3 6
4 6 10
5 10 15

When N is 3, for example, T already holds 1 + 2, which is 3. Line 20 adds the new 3 to that earlier total and stores 6. It does not replace the total with N alone.

After the last addition, NEXT changes N from 5 to 6 and ends the loop. There is no trip to line 20 with N equal to 6, so 6 is never added to T. Check both values at OK:

Type, then Enter

PRINT N

BASIC replies

 6

OK

Type, then Enter

PRINT T

BASIC replies

 15

OK

Changing N did not change T automatically. T changed only when BASIC executed an instruction assigning it a value.

Start each total at zero

What will another RUN print: 15 or 30?

Type, then Enter

RUN

BASIC replies

 15

OK

Each run reaches line 5 before the loop, so it starts a new total at zero. Trips around the loop return to line 20, leaving T available for the next addition. If we put LET T=0 inside the loop, it would throw away the earlier additions on every trip.

Try a shorter count by changing only the limit on line 10:

Type one line at a time, then Enter

10 FOR N=1 TO 3
RUN

BASIC replies

 6

OK

This run adds 1 + 2 + 3. It starts its own total rather than adding to the 15 left by the previous run.

Try a different limit ↑

Add up ticket purchases

Return to the idea from the repeating ticket program. Each ticket costs 2 pounds. Someone can enter several purchases, then enter zero to finish. We will print each purchase's price and keep the total to show at the end.

Type NEW to clear the counting program, then enter these lines one at a time. The familiar ticket program now has a starting total on line 5, an addition on line 35, and a total to print on lines 60 and 65:

Type, then Enter

NEW

BASIC replies

OK

Type one line at a time, then Enter

5 LET T=0
10 PRINT "HOW MANY TICKETS (0 TO FINISH)"
20 INPUT N
22 IF N<0 THEN 80
25 IF N=0 THEN 60
30 PRINT N*2
35 LET T=T+N*2
40 GOTO 10
60 PRINT "TOTAL POUNDS"
65 PRINT T
70 END
80 PRINT "PLEASE USE ZERO OR MORE"
90 GOTO 10

N now comes from INPUT. It holds the number of tickets in the current purchase. T holds pounds, the combined price of all accepted purchases in this run.

On line 35, BASIC works out N*2 first, then adds that price to the old T. Both GOTOs return to line 10, so they pass over the instruction that clears T on line 5. The total survives while the program asks its next question.

The negative and zero tests happen before the addition. A negative answer gets an explanation and another question. Zero goes to the final total. Neither path adds a price.

Predict the total for 3, -1, 1, then 0. Enter each answer only when the question mark appears:

Type, then Enter

RUN

BASIC replies

HOW MANY TICKETS (0 TO FINISH)
?

Type, then Enter

3

BASIC replies

 6
HOW MANY TICKETS (0 TO FINISH)
?

Type, then Enter

-1

BASIC replies

PLEASE USE ZERO OR MORE
HOW MANY TICKETS (0 TO FINISH)
?

Type, then Enter

1

BASIC replies

 2
HOW MANY TICKETS (0 TO FINISH)
?

Type, then Enter

0

BASIC replies

TOTAL POUNDS
 8

OK

Three tickets cost 6 pounds, and one more costs 2 pounds. The rejected negative answer left the total unchanged. Together the accepted purchases cost 8 pounds; the separate prices printed along the way were 6 and 2.

Try several purchases ↑

Check a new run and an empty one

Start another run, buy two tickets, and finish:

Type, then Enter

RUN

BASIC replies

HOW MANY TICKETS (0 TO FINISH)
?

Type, then Enter

2

BASIC replies

 4
HOW MANY TICKETS (0 TO FINISH)
?

Type, then Enter

0

BASIC replies

TOTAL POUNDS
 4

OK

The total is 4, not 12. Line 5 started it at zero, so the 8 pounds from the earlier run did not carry over.

What if we finish before buying anything?

Type, then Enter

RUN

BASIC replies

HOW MANY TICKETS (0 TO FINISH)
?

Type, then Enter

0

BASIC replies

TOTAL POUNDS
 0

OK

No purchase reached line 35. The total is still the zero we started with. While a question mark is showing, answer with a number; at OK, BASIC is ready for another command. Leave the browser's processor RUN control running during these conversations.

As before, this program expects whole numbers of tickets. It rejects negative answers but still has no check for positive fractions.

The FOR loop supplied a fixed sequence of numbers. The ticket program receives an open-ended sequence of purchases. In both, a separate variable keeps the result of earlier additions available for the next one.

You can keep experimenting in the terminal. This tab carries the BASIC machine and program between these lessons, including a visit to All lessons, and restores them paused after a refresh. Press the browser's RUN button to continue. Start fresh discards the program and reloads the retained tape. Copy your numbered lines somewhere for a lasting copy; browser session storage is temporary.

The machine guide (opens in a new tab) explains the hardware, loading process, and recovery controls. These lessons use that same machine and original interpreter.