Meet the Altair · Writing through a pointer
Remembering
what you type.
A character need not be printed as soon as it arrives. The program can save several characters in RAM, then read them back when the message is ready.
Begin here: Send the prepared H while stopped. Step eight times to receive it and check that it is not LF. A holds 72, but RAM and the display are unchanged. The ninth instruction, MOV M,A, makes the first stored character appear in the buffer.
Loaded buffer program · reference card All addresses and bytes here are hexadecimal
| Address | Reference | RAM | Check |
|---|
0000: LXI H,0100H sets the write pointer; 0003: MVI B,08H sets the capacity.
0005: IN 00H, 0007: CPI 0, and 0009: JZ 0005H poll readiness. 000C: IN 01H receives a byte. 000E: CPI 10 and 0010: JZ 0019H finish on LF.
0013: MOV M,A stores a character; 0014: INX H advances HL; 0015: DCR B counts down; 0016: JNZ 0005H returns only if space remains.
0019: MVI A,00H and 001B: MOV M,A append NUL. 001C: LXI H,0100H rewinds the pointer.
001F: MOV A,M, 0020: CPI 0, and 0022: JZ 002BH check for the terminator. 0025: OUT 01H, 0027: INX H, and 0028: JMP 001FH print nonzero bytes. 002B: HLT finishes.
Instruction addresses and reference bytes are hexadecimal. CPI 10 compares with decimal 10 (0A hex). The lesson checks all forty-four program bytes. Normal collection stores at most eight characters at 0100–0107 and a terminator no later than 0108.
This lesson connects an 8080, 65,536 bytes of RAM, and separate teaching input and output devices. The program collects up to eight characters, appends NUL, prints the buffer, and halts. Start again restores the program, clears RAM, registers, flags, halted state, both devices, output, counts, and history, prepares H, and stops at PC 0000. It is not the hardware RESET switch.
A place to keep the characters.
A buffer is a region of memory used to hold data. Our program uses 0100–0107 for up to eight characters, with one extra location at 0108 available for the zero terminator. All nine locations start at zero.
LXI H,0100H puts the first buffer address into HL. MVI B,08H puts the capacity into B. During collection, HL points to the next place to write, and B counts the character slots still available.
The input device still holds only one pending byte. The larger buffer is ordinary RAM, filled by the program. Typing or pressing Send does not write to it.
Use the pointer in the other direction.
You have seen MOV A,M read through HL. MOV M,A copies in the other direction: from A into the memory location addressed by HL. M still means “the byte at HL.”
The first store writes 48 hex, or 72 decimal, at 0100. A keeps 72, HL stays at 0100, and the display stays empty. INX H then advances HL to 0101; DCR B reduces B from 8 to 7. These are separate changes.
If B is not zero, JNZ returns to the readiness check. The program can keep polling while you prepare the next character. Readiness checks change A, but the stored H remains in RAM.
Tell the program the message is ready.
After IN 01H receives a byte, the CPU compares it with 10 decimal, the value of LF. For this program, LF means finish collecting. It skips the character store, so LF takes no slot and does not enter the buffer.
The CPU puts zero into A, stores it through HL, and resets HL to 0100. This appends NUL after the characters and brings the pointer back to the start. Even though unused RAM already starts at zero, the program explicitly writes its terminator.
The familiar print loop now reads through HL, compares with zero, and sends each nonzero byte. Only these OUT instructions put text on the display. It halts at NUL; neither LF nor NUL is printed.
Sending LF first makes an empty message. The program stores NUL at 0100, then halts without executing OUT.
Keep room for the ending.
After the eighth character, DCR leaves B at zero. JNZ does not return for more input. The program immediately appends NUL at 0108 and prints the eight stored characters, without waiting for LF.
The extra location matters: eight characters and a terminator require nine bytes. During normal execution from the start, the program never writes past 0108. B is decreased after the store, so it may briefly show its old value beside a newly written character.
You can prepare or offer another character while the CPU finishes. A later offer may wait in the input device, but this run will not receive or store it. Starting the lesson again clears that pending byte and the buffer.
The output comes from memory.
Once a character has been stored, later typing does not change it. The readback loop obtains its bytes from RAM, not from the input field or a hidden copy of your text.
Change stored H to J before playback
- Start this lesson again, RUN, and send H and I one at a time, waiting for room in the input device.
- Wait until I has been received and the device is empty. Press STOP before sending line feed, so the program cannot begin playback while you prepare the experiment.
- Send line feed while stopped. Use Step one instruction until PC is
001F, just before the first readback MOV. - EXAMINE
0100, set the switches to004A, and DEPOSIT. RAM now holds J where it held H. - EXAMINE
001Fto restore PC, then RUN. The display prints JI.
Editing RAM after that MOV would leave the first character already captured in A unchanged.
The switches remain available for experiments, but manually jumping into the middle of collection can bypass the setup and capacity check. Start again to return to the program’s normal path.
The character field offers printable ASCII, including spaces. LF is sent separately. The raw byte device can accept other values; a stored NUL would end readback early because this format uses zero as its terminator.