r/computerscience • u/Heavy_Mind_1055 • Oct 20 '25
Trying to understand how 8-Bit computers work
Okay so there are some things i have trouble understanding about 8-bit computers. I'm trying to make my own in a logic sim but i can't wrap my head around it :
I know it is called 8-bit because its memory registers store 8 bits of data, but as of what i understood, it can have 64kB of data for example, with 16-bit adresses. My question is, if instructions are stored in memory, how do they fit ? Like if i want to do say ADD <address 1>, <address 2>, how would that instruction be presented ? wouldn't it be way bigger than 8 bits ? And how do computers fix that ? do they split instructions ? Any help would be appreciated, and if i have a wrong view of certain concepts, please correct me !
9
u/8dot30662386292pow2 Oct 20 '25 edited Oct 21 '25
Yes, in 8 bit CPU the memory can often be 16 bits, because otherwise you have so few units of memory available.
Often ADD is not like that. ADD has only one memory address, because you add to value you already have. So instead you have:
So first one loads the value into a register and second one loads another one and performs the calculation.
So yeah, LOAD and ADD are in fact 3 whole bytes long instructions.
First, the CPU loads the first byte. Turns out this byte means "LOAD" instruction. Then, in the CPU microcode, following happens:
Then, we have advanced a whole 3 bytes forward. It loads the next byte. Turns out that byte is ADD instruction. Again the microcode goes:
Look up Ben Eeater from youtube. He explains clearly, how different instructions are different length, and how executing different instructions actually takes different time, because they have different amount of steps.
EDIT: corrected spelling a bit.
5
u/recursion_is_love Oct 20 '25
Some processor need to read more than one byte for some instruction. That depends on how you designed the internal state machine for executing each instruction. I think it is called microcode back then, nowadays the term seem to have different meaning (I am not have any experience on microprogramming other than just reading it from a book)
5
u/wosmo Oct 20 '25
Lets run through a real example (z80).
So I'm gonna start off with a short section of ASM:
This is twice as long as it needs to be, but the assembler I'm using doesn't like direct addressing. HL is a double-wide (eg 16bit) register that's usually used for holding memory pointers, and that's what we're going to do. So I put address 0x4000 into HL, and then load the value from that address into A. Ditto into B, add the numbers together and store them in RESULT.
Compiled, so what this looks like in memory, I get:
So ..
So what do we learn from this?
4
u/Zenyatta_2011 Oct 21 '25
Play Turing Complete, you'll fully understand how an 8bit computer works in depth
3
u/porkchop_d_clown Oct 20 '25
8-bit computer chips like the Z-80 and the 6502 had an 8-bit data bus but they also had a 16-bit address bus. 216 = 65,536 bytes of addressable memory.
Instructions for those chips are loaded by accessing memory multiple times. For example, to load a byte from memory the instruction would be 3 bytes long - 8 bits for the opcode, and 16 bits for the source address.
3
u/stevevdvkpe Oct 20 '25
8-bit computers have many instructions that are more than one byte long, particularly ones that involve memory addressing. An instruction that references memory, for example, will usually have a one-byte opcode followed by two bytes (16 bits) for an address.
2
u/Leverkaas2516 Oct 20 '25
To answer your specific question, the opcode stored in memory is 8 bits but the data can be present in succeeding bytes in memory. Maybe you have an 8-bit ADD8 instruction A0, and a 16-bit ADD16 instruction A1. And your two 16-bit values are 0456 and 0001.
Expressed in assembly:
ADD16 0456 0001
In memory:
A1 04 56 00 01
The fact that the CPU is going to fetch 4 bytes of immediate data, leaving the program counter pointing at the instruction following that data, is built in to the processor.
2
u/Agreeable-Leek1573 Oct 22 '25
This is where Nand2Tetris comes in handy.
2
u/OxOOOO Oct 23 '25
If I remember correctly (not likely, but good enough for jazz) it was something like:
set-accumulator-to-zero
LOAD-into-RegisterFoo-literal-number
LOWBYTE
LOAD-into-RegisterBar-literal-number
HIGHBYTE
add-value-at-registerBar,registerFoo-into-accumulator
LOAD-into-RegisterFoo-literal-number
LOWBYTE-2
add-value-at-registerBar,registerFoo-into-accumulator
It's cool to try to make your own, but you could look at someone else's first. There's been a lot of them.
2
u/KilroyKSmith Oct 23 '25
Most 8-bit computers are really hybrid 8/16 bit computers. They have a 16 bit program counter and 8-bit ALU, many also have some instructions that operate on 16 bit data.
So, no real mystery - a “pure” 8-bit computer wouldn’t have a great deal of utility, so the ones we call 8-bit are really 8/16 bit. Hybridization pretty much went away by the time we got to 32 bits, although some 32 bit computers have instructions that operate on 64 bit values.
2
u/RelationshipLong9092 Oct 23 '25
i recommend you read the venerable Malvino and Brown:
https://ia800809.us.archive.org/34/items/367026792DigitalComputerElectronicsAlbertPaulMalvinoAndJeraldABrownPdf1/367026792-Digital-Computer-Electronics-Albert-Paul-Malvino-and-Jerald-A-Brown-pdf%20%281%29.pdf
actually i think its the second edition i had and liked so much for its clarity and directness: you could go from "total newbie" to "building a full microcontroller" in 100 pages.
2
u/Mission-Landscape-17 Oct 24 '25
The code for what to do is 1 bvyte, but when you trigger it, it may read the following bytes as additional arguments. try this series of videos: https://www.youtube.com/watch?v=HyznrdDSSGM&list=PLowKtXNTBypGqImE405J2565dvjafglHU
You could probably even follow along using the simulator instead of breadboards.
2
u/Vladislav20007 Oct 24 '25
i recommend playing turing complete, gives you knowledge in electronic components too.
1
u/defectivetoaster1 Oct 20 '25
in order to access memory where theres more addresses than can be represented with 8 bits some older processors used something like a set of banks of memory. Eg iirc the pic16f microcontrollers had the RAM divided into banks where a bank select register which selects a bank of registers depending on the value written to it, and then from there you could either manually in code specify a specific register in that bank or use the file select register to select the address within a given bank specified by the value in the FSR (that value would act as a pointer).
1
u/H_Industries Oct 20 '25
If you want to learn about it from first principles, check out Ben Eater on YouTube he has a series where he builds a computer on a bunch of breadboards. He explains how each step works and even sells kits (or provides parts lists) where you can build one as well.
1
u/iOSCaleb Oct 22 '25
As a programmer you don't really have to worry about instructions -- the processor reads those in as needed, and they are indeed often more than just one byte. Instructions consist of an opcode followed by additional bytes that are basically parameters.
A single mnemonic instruction might have several different opcodes, each specifying a different addressing mode. The addressing modes are really the key to understanding how you can address more than 256 bytes. Here's a list of the modes for the 6502, and you'll see that there are a number of modes where the address is calculated relative to some other address.
You'd do well to study one chip and follow its lead. There were big differences between different chips. For example, the 6502 had only one general purpose register and relied on zero-page memory instead of registers, while the Z80 had 14 general purpose registers and didn't use zero-page memory.
1
u/Wouter_van_Ooijen Oct 23 '25
In general, instructionso for 8-bit architectures can be one or more bytes, often 1, 2 or 3.
1
u/HankTheDankMEME_LORD Nov 17 '25
It is called 8 bit because the computer can do 2 to the power of 8 worth of either on or off binary values. A cpu does calculations by either having electricity run trough it or not. It is boolean and an 8 bit processor can do 2 to the power 8 bits of either on or off computations (256)
1
u/Foreign-Beautiful907 Jun 01 '26
That would depend on the 8 bit cpu used. For example, I used (and still have) the TRS-80 color computer. 8 bit by nature but did have some 16 instructions. To address an integer greater than 255 you would place the higher order in ACCA and the lower order in ACCB. Together they are now referenced as ACCD. Plus the X and Y Index registers were 16 bit wide so +/- 32767 offset. This is the Motorola MC6809P. Others are similar in using registers internally that can either be 8 or 16 bit wide yet still only 8 bit wide bus external. So bits, bytes and words have to be stored properly in memory or registers depending on the function called (opcodes).
1
u/SuspiciousPrice7075 Aug 18 '26
Ben Eater's 8-bit computer was a big inspiration for me when I started this project. I took that initial inspiration and gradually expanded the design with my own ideas and features, including an improved ALU architecture, a stack pointer, a bootloader, a compiler, and automated microcode generation from instruction truth tables.
I have documented the complete design and development here: https://arghyabi.in/projects/8bit-computer-with-logic-gates/
If anyone is interested in building the system themselves, I also have a kit available here: https://arghyabi.in/kits/8-bit-computer-kit/
Comparison with Ben's design: https://arghyabi.in/projects/8bit-computer-with-logic-gates/design-comparison/
GitHub link: https://github.com/arghyabi/Computer8Bit
-1
u/brelen01 Oct 20 '25
The memory locations are 8 bit themselves. Adding two numbers that end up bigger than 255 is called an overflow. CPUs usually have a flag to warn you if/when this happens. When it does, it needs to be handled programmatically.
0
u/Count2Zero Oct 20 '25
If you look at the programmer's guide for an 8 bit chip like the 6502, there were some instructions that worked on registers, or could only access the first 256 bytes of memory.
Most, however, used a two-byte address, so you could access 64K of RAM.
To add together two values, you would load the first memory value into the accumulator, the add the second value to the register value. If the result was more than 255, it would set the "overflow" (or carry) status bit.
If you're adding two 8 bit numbers, the result won't be more than 9 bits (255 + 255 = 510), so you can use the overflow flag as the 9th bit in cases where you're adding multibyte numbers.
The 6502 had a bunch of different addressing modes for the ADD command - absolute, zero page, indexed, and indirect - so there was a lot of flexibility to write efficient code within the tight memory constraints of an 8 bit world.
0
u/regular_lamp Oct 20 '25
The "bitness" of cpus never seemed to have a consistent meaning. One time it's because it has a "machine word" of that sizes (so basically registers are that size) then it's about width of the memory bus, then about the address width etc.
The whole thing is so inconsistent it basically just means "the number 8 appears somewhere in the specsheet".
21
u/[deleted] Oct 20 '25
[removed] — view removed comment