About this lab
StudyFi Lab · Computer science

How a Computer Works

How a Computer Works is a free interactive simulation from StudyFi Lab. It runs right in your browser, with no sign-up and nothing to install.

Binary numbers and a tiny CPU running instructions

Experiments

Binary numbers

A computer stores numbers as bits, 0 and 1. Each bit has a place value — a power of two: 128, 64, … 2, 1 — and the number is the sum of the place values of the bits that are on. Hexadecimal writes every 4 bits as one digit 0–F, octal every 3 bits. In two’s complement the top bit has the negative value −128, so 11111111 means −1.

Try this: Turn on all 8 bits (255), then switch to two’s complement and watch 255 become −1.

Binary addition

The numbers are added column by column from the right, just like on paper, except that 1 + 1 = 10: write 0 and carry 1 into the next column. If a carry falls out of the 8th bit, the result does not fit in 8 bits — an overflow. A computer subtracts a − b as a + (b inverted) + 1, i.e. it adds the two’s complement.

Try this: Set 200 + 100 and step through: a carry falls off the left and the result is only 44. Then try the subtraction 5 − 12.

A tiny CPU

Program and data share the same RAM. The CPU repeats three steps: fetch — copy the byte at the address in the program counter PC into the instruction register IR and increase PC; decode — the control unit works out which instruction it is; execute — carry it out, e.g. A ← A + B. The top 4 bits of a byte are the opcode, the lower 4 bits an address or a number. JZ jumps only when the flag Z = 1 (the last result was zero).

Try this: Run the “Multiply” program, then change cell 14 from 4 to 5 and check that the output ends at 15.

Frequently asked questions

What is How a Computer Works?

How a Computer Works is a free interactive simulation from StudyFi Lab. It runs right in your browser, with no sign-up and nothing to install. Binary numbers and a tiny CPU running instructions

Is How a Computer Works free?

Yes. How a Computer Works is completely free. It works in the browser on computers, tablets and phones, and you do not need an account.

What can I explore in How a Computer Works?

Binary numbers, Binary addition, A tiny CPU.

What does the “Binary numbers” experiment show?

A computer stores numbers as bits, 0 and 1. Each bit has a place value — a power of two: 128, 64, … 2, 1 — and the number is the sum of the place values of the bits that are on. Hexadecimal writes every 4 bits as one digit 0–F, octal every 3 bits. In two’s complement the top bit has the negative value −128, so 11111111 means −1.

What does the “Binary addition” experiment show?

The numbers are added column by column from the right, just like on paper, except that 1 + 1 = 10: write 0 and carry 1 into the next column. If a carry falls out of the 8th bit, the result does not fit in 8 bits — an overflow. A computer subtracts a − b as a + (b inverted) + 1, i.e. it adds the two’s complement.

Studying for a test?

Upload your notes and StudyFi turns them into flashcards, tests and podcasts.

Try StudyFi free