Skip to main content
The cyberduck’s pond

šŸ–„ 8080 CPU emulation

·

Computers through microscope šŸ”¬ #

I always wanted to understand more deeply the lowest level of computers, so I tried to make an emulator for the iconic 8 bits 8080 CPU which is one of the first CPUs made by Intel.

I had to understand how a computer hardware works in general and look at the processor documentation to reproduce the behavior of all instructions.

I was a beginner in C programming so it was also a good way to practice a rare C feature known as function pointers.

Function pointers are variables from which you can call a function, in this case they are very useful associated with an array to emulate instructions.

The operating loop of a CPU can be simplified by this flow:

graph LR; A[Program counter]--> |point to| B[Memory]; B--> |fetch| C[Instruction]; C--> |modify| D[CPU State]; D--> |increment| A;

Each round the CPU fetch the value of memory pointed by the program counter and each value is an instruction from 0x00 to 0xFF.

So you can create a function pointer array of size 0xFF in which each index is the value of the associated instruction.

I wanted to emulate a full 8080 CPU-based machine but because lack of time (I had to do my school projects) it only emulates the CPU.

My emulator actually pass the CPUdiag program who test if the processor operate correctly and contains a disassembler for debugging.

look at the code! šŸ¤“ #

@coincoingit repo.