Meet the Altair · Recognizing an ending

Where does
a message end?

Last time, B told the program how many bytes to print. This time, a byte in memory marks the end. The program reads, checks, and only then sends.

Begin here: The message is still HELLO and a line feed. One extra byte, 00, follows it. Step through the first four instructions: set HL, read H, compare it with zero, then decide whether to finish. Nothing has reached the display yet.

Loaded message program · reference card All addresses and bytes here are hexadecimal
These sixteen program bytes are already loaded at 0000. The message and its zero terminator begin at 0100. RAM shows what is stored now.
AddressReferenceRAMCheck

0000–0002: 21 00 01 puts 0100 into HL.
0003: 7E reads the byte at HL into A.
0004–0005: FE 00 compares A with zero.
0006–0008: CA 0F 00 jumps to 000F if Z = 1.
0009–000A: D3 01 sends A to the display.
000B: 23 advances HL.
000C–000E: C3 03 00 jumps back to 0003.
000F: 76 halts the CPU.

The lesson checks all sixteen program bytes before executing. Data at 0100–0106 starts as 48 45 4C 4C 4F 0A 00: HELLO, line feed, and a zero terminator. Data can be changed while stopped; RAM elsewhere starts at zero.

Operate the memory panel

The 8080 behind the panel

A decimal
0
PC hex
0000
HL address · hex
0000

Message in RAM

Addresses and bytes in hexadecimal; characters interpreted as ASCII.
AddressByteCharacter
0100 48H
0101 45E
0102 4CL
0103 4CL
0104 4FO
0105 0ALF
0106 00NUL

Enable JavaScript to follow HL.

The marker follows HL. Looking at these bytes changes no CPU or memory state.

Received text Output port 1


    Waiting for output
  

No byte sent yet.

0 writes received.

Only OUT adds text. LF starts a new line; other non-printing bytes appear as labels in angle brackets.

Zero flag Z: 0 · the most recent comparison’s answer

CPU halted: no

The program is loaded. Enable JavaScript to run or step it.

Last CPU instruction

No instruction has run.

Look inside the last instruction
Step an instruction to see its fetched bytes, memory accesses, and any port transfers.
Recent instructions

0 instructions executed.

    RUN and STOP are teaching controls at instruction boundaries. Pace is for reading, not a simulation of the Altair’s clock. This page stops running when hidden. Looking at these readouts changes no state; EXAMINE changes PC.

    EXAMINE changes PC without running a program instruction. Stepping advances PC, and the panel lights follow it. This added control executes a whole instruction; the original SINGLE STEP switch advanced one machine cycle.

    ALTAIR 8800

    Memory controls · learning view

    Address lights The selected location

    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 only

    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.

    Lower all switches and press EXAMINE to select 0000.

    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.

    This lesson connects an 8080, 65,536 bytes of RAM, and a teaching output device at port 1. The program at 0000 reads text at 0100 until it finds zero. Start again restores the program and data, clears registers, flags, halted state, output, counts, and history, and stops at PC 0000. It is not the hardware RESET switch.

    Give the message an ending.

    The seven bytes at 0100–0106 are 48 45 4C 4C 4F 0A 00. The first six are familiar. The last byte is zero, labelled NUL in ASCII. This program uses it as a terminator: a value that marks where the message ends.

    RAM simply holds bytes. It does not know which ones are letters, where a message begins, or where it ends. The program gives zero this job by checking for it. There is no length in B this time; B stays unused.

    Check before sending.

    LXI H,0100H sets the pointer, and MOV A,M reads through it. With the original message, A now holds 72, the ASCII byte for H. Neither instruction prints anything.

    CPI 0 compares A with zero. Because 72 differs from zero, Z becomes 0. A keeps 72. The following JZ 000FH does not jump, so execution reaches OUT 01H and H appears.

    INX H advances the pointer. JMP 0003H returns to the read. Every trip asks the same question about a new byte: is this zero?

    Zero, “0”, and a new line.

    These three bytes have different values and different jobs. The memory window shows hexadecimal bytes; A shows decimal.

    Byte · hexDecimalMeaning here
    000NUL: the program finishes without sending it.
    3048The printed character “0”: send it and continue.
    0A10LF: send it to start a new line, then continue.

    After LF, HL advances to 0106. MOV reads zero into A, but Z is still 0 from comparing LF. CPI then sets Z to 1, and JZ jumps straight to HLT. The final zero is read and checked, but never sent. HL stays on its row.

    The output device has no special rule for ending this message. The CPU avoids OUT on the terminating path. In the previous lesson, a zero among the six counted bytes would have been sent and displayed as ⟨NUL⟩.

    How does the complete run finish?

    One setup instruction, six trips of six instructions, then MOV, CPI, JZ, and HLT: 41 instructions. Final A is 0, HL is 0106, Z is 1, and PC is 0010. The display received six writes: HELLO and a line feed.

    Move the ending without changing the program.

    Use the panel while stopped to change the message. EXAMINE changes PC, so return to 0000 before running from the beginning.

    Try stopping after HE
    1. Start this lesson again.
    2. Set the switches to 0102 and press EXAMINE. This is the first L.
    3. Lower all switches and press DEPOSIT to replace it with 00.
    4. With the switches still at zero, press EXAMINE to return PC to 0000.
    5. RUN. Predict what happens to the remaining bytes.

    The display prints HE and then stops. The later L, O, and LF remain in RAM; the CPU never reads them on this run. The pointer finishes at 0102.

    Try the character “0” instead

    Start again, EXAMINE 0102, then set the switches to 0030 and DEPOSIT. Lower the switches and EXAMINE 0000 before running. The display prints HE0LO and a line feed: 30 hex is not a terminator.

    Try an empty message

    Start again and deposit 00 at 0100. EXAMINE 0000 and run. Five instructions set the pointer, read zero, compare, jump, and halt. No OUT executes, so the display stays empty.

    Changing RAM after MOV does not change the byte already in A. Likewise, changing RAM after CPI does not change the comparison stored in Z. The next instruction uses the processor’s current state.

    A convention needs a matching byte.

    The loop has no built-in message length. If you replace the zero at 0106 with a nonzero byte, it sends that byte and keeps reading beyond the window. In this lesson, the next location, 0107, starts at zero, so it would finish there instead. The window reports when HL is outside the displayed range.

    A program using this convention needs a reachable zero to finish. It does not stop because it has reached the edge of our picture. STOP can still pause execution between instructions; starting the lesson again restores all the original bytes.