Memory and the processor · A loop

Going
around again.

A jump can take us back to an earlier instruction. What happens when the processor adds one, stores the result, and then does it again?

Memory · eight locations shownAddresses 0–7

Address 3 holds our starting byte. Address 4 is where we will put the result. Values below are decimal.

Select a memory byte to edit

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.

Inside the processorIntel 8080

Register A

0decimal

Binary
0000 0000
Hexadecimal
00
Carry flag CY0

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 instruction · PC0100

← 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.

    Each press runs one instruction; nothing runs between presses.

    No instruction has run. PC points to the first instruction.

    PC path so far: 0100.

    Step through the program

    Enable JavaScript to run this experiment.

    Last instruction

    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.

    Byte at address 3Unsigned · 0 to 255

    Enable JavaScript to change this byte. This example shows 41.

    Change the byte

    Hex digit 2

    Hex digit 9

    Add the values of the bits that are on

    32 + 8 + 1 = 41

    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.

    JMP 0103H follows the store. It returns PC to the addition, preserving A, flags, and RAM. The load is outside the repeating part and 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). There is no completion address or halt instruction. Each press runs one instruction; the machine waits for your next press.

    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 guide

    The first time around.

    Take three steps. The load puts 41 into A, the addition makes it 42, and the store writes 42 to address 4. We have done all of this before.

    Now PC points to 0108, where the instruction is JMP 0103H. Take one more step. The next-instruction marker returns to the addition at 0103.

    Repeat without resetting.

    The processor repeats three instructions: add, store, jump. Together they form a loop. The same bytes run again, working with the state left by the previous trip around.

    Watch the run counts. The load stays at 1, while the other instructions run again and again. PC revisits 0103 → 0105 → 0108 → 0103, but the stored results grow: 42, 43, 44…

    The recent PC path shows up to twelve steps. Earlier addresses disappear from that short history, but each instruction’s run count continues to include the whole experiment.

    Start again does something different from the jump: it restores the whole lesson, including A = 0, the starting data, PC = 0100, and cleared run counts.

    Still one byte.

    Repeating the addition does not make A any wider. Eventually the value reaches 255 and the next addition wraps to 0, setting carry.

    The jump always goes back, even when the value wraps or carry changes. It does not test a flag.

    When does it stop?

    This program has no instruction that ends the loop. Every jump leads back to the addition.

    In this experiment, you control the pace: each press runs one whole instruction, and nothing runs between presses. You can pause simply by stopping. Step remains available, and Start again restores the original setup.

    We have learned how to repeat. Next we need a way for the program to decide whether to repeat—or continue somewhere else.