Memory and the processor · A stored program

What comes
next?

The program still reads a byte, adds one, and writes the result. This time, there is just one button. How does the processor know which instruction to run?

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.

    0108 · End of this program

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

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

    Instructions are bytes too.

    The commands are already stored in memory. They are bytes, just like the values at addresses 3 and 4. The descriptions beside them are for us; the processor reads the bytes themselves.

    Look at “Add one to A.” Its two bytes are C6 01. On the 8080, C6 says to add a number to A; the next byte supplies that number. Here it is 01, meaning one.

    The program view uses hexadecimal for both addresses and contents. Each small address labels one memory location; the larger number underneath is its byte. For example, location 0103 contains C6.

    Both views above show parts of the same RAM: data near the beginning, and the program starting at 0100 (256 in decimal). This lesson lets you edit the data while keeping the instructions fixed.

    An address to remember.

    The processor has another register called the program counter, or PC. Between these steps, it holds the address where the next instruction begins.

    Our lesson starts PC at 0100. Press Step one instruction. The processor fetches the load instruction from that address and executes it. A receives 41, and PC moves to 0103.

    PC counts addresses, not instructions. The load occupies three bytes, at 0100, 0101, and 0102. The next instruction therefore starts at 0103.

    Fetch, then act.

    Fetching means reading the instruction’s bytes from memory. The shaded bytes show what the last step fetched. The arrow shows where the next instruction starts. After a step, these refer to different instructions.

    The load fetches 3A 03 00, then reads the data at address 3 into A. That data read is separate from fetching the instruction. You can see all four reads in the optional record above.

    Why three bytes for the load?

    3A selects the load instruction. The next two bytes give its address, with the low byte first: 03 00 means 0003. An 8080 memory address needs two bytes, while the value loaded into A is one byte.

    Each press executes one whole instruction. The display reports the completed step; it does not pause at each byte read or represent individual clock cycles.

    At the end.

    The store occupies three bytes, so the final step leaves PC at 0108. Our lesson stops offering steps there. The processor has not executed a halt instruction; we have reached the end of this little experiment.

    You have followed a stored program: instruction bytes tell the processor what to do, and PC tells it where to look next. Here, each instruction leads to the following one. Later, we will see instructions that deliberately change that path.