Memory and the processor · One calculation

Doing something
with a byte.

We can bring a byte into A and copy it back to memory. Now let’s do something in between: add one.

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.

Step through the program

Enable JavaScript to run this experiment.

Last instruction

No instruction has run. A starts at 0.

Last addition · full sum and stored byte

No addition has run. Read a byte into A, then add one.

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 or the last addition’s explanation.

Explore the Intel 8080 guide

One small calculation.

Address 3 starts with 41. Read it into A, then press Add one to A. A becomes 42. Address 3 still holds 41, and address 4 still holds 0: the calculation has changed the working copy inside the processor.

Press Write A to address 4 to save the result in memory. Now address 4 holds 42. A keeps its value too.

Room for the result.

A is still only one byte. It can hold an unsigned value from 0 to 255, even when a calculation produces a larger answer.

This is the same wraparound we met in What happens after 255?. Here, a real processor instruction performs the addition.

A bit to remember.

The processor has small pieces of state called flags. The carry flag, named CY on the 8080, is one bit. This addition sets it to 1 when the sum does not fit in eight bits, and to 0 when it does.

CY is separate from A. It remembers the carry from the addition; it does not make A a nine-bit register. Writing A to memory writes just its eight bits. The load and store instructions leave CY alone.

Starting again restores the lesson’s chosen values, including CY = 0. Editing memory by itself never changes A or CY.

Load, calculate, store.

These three instructions form a small program: bring a value in, work on it, and put the result somewhere. Each button runs one instruction; the others wait their turn.

The program and its instruction bytes are already in memory. You can reveal them above. Next we will look at how the processor finds those instructions in order.