Memory and the processor · Editing a program
Change one byte,
change the program.
Our program adds one because one of its bytes says 01. What if we change that byte to 02?
Address 3 holds our starting byte. Address 4 is where we will put the result. Values below are decimal.
Address 3 starts at 41; address 4 starts at 0.
Select a location to edit it in the explorer below. The read and write always use addresses 3 and 4.
Register A
0decimal
- Binary
- 0000 0000
- Hexadecimal
- 00
CY starts at 0. The addition sets CY to 1 if the sum exceeds 255, or 0 if it fits.
The program in memory
Addresses and bytes below are hexadecimal.
← Next (PC) marks the next instruction. Shaded bytes were fetched by the last step.
Choose 0–255 before the first step. This changes just the byte at 0104. Start again restores 01 and unlocks this field.
Address 0104 contains 01 in hexadecimal (1 in decimal).
0108 · End of this program
No instruction has run. PC points to the first instruction.
Enable JavaScript to run this experiment.
No instruction has run. A starts at 0.
Change the byte at address 3
Edits here change memory immediately. They do not change A or run an instruction.
Enable JavaScript to change this byte. This example shows 41.
See the 8080 instructions
The first instruction is LDA 0003H: load A from memory address 3. Next comes ADI: add the number in the following byte to A and update the arithmetic flags. The last instruction is STA 0004H: store A at address 4. The load and store preserve the processor’s flags.
ADI adds the number encoded in the instruction, regardless of which memory byte is selected. It does not add the incoming carry. Unlike INR A, which preserves carry, ADI updates CY. It also updates sign (S), zero (Z), auxiliary carry (AC), and parity (P); their before/after values appear in the record.
This view shows the first eight locations of a 65,536-byte RAM. The instructions live elsewhere, starting at hexadecimal address 0100. The program counter, PC, tells the processor where to find its next instruction.
Current PC: 0100 (hexadecimal). The lesson stops offering steps at 0108, just after the final instruction. This is a lesson boundary; the processor has not executed a halt instruction.
No instruction has run.
The record includes the reads that fetch the instruction bytes, as well as the data read or write. Editing a memory byte in the explorer is a separate learner action; it does not alter the last instruction’s record.
Explore the Intel 8080 guideChoose the number.
Before stepping, change Add this number to A from 1 to 2. Look at address 0104 in the program view: it now holds 02. The addition’s bytes are C6 02.
You have edited memory. A is still 0, the starting data is still 41, and PC still points to 0100. Nothing has run yet.
The field locks when you take the first step, so this run uses the program you chose. Start again restores all the original values, including the addition’s 01, and lets you choose another number. This editing rule belongs to the lesson; the RAM itself is writable.
What to do, and what to use.
The two bytes play different roles. C6 selects the operation: add a number to A. We call this the opcode. The following byte supplies the number to add: the operand.
The operand is part of the instruction itself. This is called immediate addressing, which is where the I in the 8080 name ADI comes from: add immediate.
The field accepts decimal numbers from 0 to 255. The program view shows hexadecimal bytes, while labels such as ADI 2 use decimal. Try entering 10: the bytes become C6 0A. These are two ways of writing the same operand.
This experiment lets you change only that operand. The opcode and the load/store addresses stay fixed, so the program always reads address 3, adds your number, and writes to address 4.
Same path, new result.
Changing the operand changes the calculation, but the addition still occupies two bytes. PC follows the same path: 0100 → 0103 → 0105 → 0108.
Two kinds of edit.
Changing address 3 gives the same program different starting data. Changing 0104 changes a number inside the program. Both edits write a byte into the same RAM; its role depends on how the processor uses it.
You have changed a program by changing its bytes. So far, each instruction still leads to the next one in memory. A different kind of instruction—a jump—will let us change that path too.