A sequential simulator for the Y86-64 instruction set, written in C. It loads a program into memory and runs it one instruction at a time through the six classic processor stages.
Y86-64 is a teaching subset of x86-64 used to show how a CPU actually executes machine code. This simulator implements the sequential (SEQ) processor: every instruction flows through fetch, decode, execute, memory, write-back, and PC update, exactly as a hardware datapath would. Reading it is a concrete way to understand instruction encoding, register files, condition codes, and how a program counter advances.
- The six-stage sequential processor cycle: fetch, decode, execute, memory, write-back, PC update
- Instruction decoding: splitting an opcode byte into
icodeandifun, reading register bytes and immediate words - The full Y86-64 instruction set:
irmovq,rmmovq,mrmovq,rrmovq,OPq,push/pop,jXX,call,ret, conditional moves,nop, andhalt - Condition codes and conditional branch/move evaluation
- A register file and a byte-addressable memory model
- Variable-length instruction encoding and PC math per instruction
- A step mode that prints machine state stage by stage
y86-64.c: the complete SEQ simulator.stepMachineruns one instruction through all six stages;maininitializes memory and registers, loads a program, and runs untilHALT.- Optional
DEBUGbuild that dumps machine state after every cycle.
- C
- Y86-64 instruction set architecture
Compile and run against a Y86 object file:
gcc -o y86 y86-64.c utils.c
./y86 program.yoPass a step flag (handled in parseCommandLine) to print the machine state after each stage instead of only the final result.
Note: this file depends on a utils.h/utils.c support module (memory, register, and opcode helpers) provided by the course framework.