Memory and the processor · A conditional jump
Knowing
when to stop.
Our last loop always went around again. This time, the processor uses the carry flag to choose: repeat the addition, or leave the loop.
Address 3 holds our starting byte. Address 4 is where we will put the result. Values below are decimal.
Address 3 starts at 254; 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.
Runs counts how often each instruction has executed since Start again.
010B · End of this program
Each press runs one instruction; nothing runs between presses.
No instruction has run. PC points to the first instruction.
PC path so far: 0100.
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 254.
See the 8080 instructions
The first instruction is LDA 0003H: load A from memory address 3. Next comes ADI 1: add one to A and update the arithmetic flags. Then comes STA 0004H: store A at address 4. The load and store preserve the processor’s flags.
JNC 0103H follows the store: jump if no carry. With CY = 0 it returns PC to the addition; with CY = 1 it continues at 010B. Both paths fetch all three instruction bytes and preserve A, flags, and RAM. The load runs just once.
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 010B, 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 guideOne new instruction.
We still load, add one, and store. The starting byte is now 254, so we can reach wraparound quickly.
The last instruction is JNC 0103H: jump if no carry. “No carry” means CY = 0, also called clear. CY = 1 is called set.
- CY = 0: jump back to the addition at
0103. - CY = 1: continue after the jump, at
010B.
This is a conditional jump: whether it jumps depends on a condition. The processor reads the flag when it executes the instruction.
The same jump, a different decision.
Take the jump, then add again. 255 + 1 gives A = 0 and sets CY = 1. The store writes 0 to address 4 and leaves CY set.
Watch the last-instruction explanation: it reports the carry value the jump inspected and the PC transition it produced. The jump runs twice, even though only the first execution jumps backward.
A flag remembers a result.
The addition sets carry. The store preserves it. The jump reads it. The jump does not redo the addition or inspect the byte at address 4.
You can also change address 3 before the load. Try 255 for one trip through the loop, or 253 for three. Changing that source after the load leaves A and the remaining work unchanged.
Leaving the loop.
At 010B, this lesson stops offering steps. The processor has left the loop; it has not executed a halt instruction. A larger program could put more instructions at that address.
Each press still runs exactly one instruction. The jump chooses the next address, while you choose when the processor takes its next step.
We can now connect a calculation to a decision: an instruction changes a flag, and a later instruction uses that flag to choose a path.