Simulasi CPU sederhana dengan Python untuk project portfolio Codecademy CS104 Computer Architecture.
- MemoryBus: Simulasi RAM 256 alamat, load initial value dari file
- Cache: Direct-mapped cache 8 block, write-through, hit/miss tracking
- CPU: 8 register (R0-R7, R0 hardwired 0), Program Counter, Fetch-Decode-Execute loop
- ISA yang didukung:
ADD Rd,Rs,Rt: Rd = Rs + RtSUB Rd,Rs,Rt: Rd = Rs - RtMUL Rd,Rs,Rt: Rd = Rs * RtADDI Rd,Rs,Imm: Rd = Rs + ImmediateLW Rd,Addr: Load WordSW Rs,Addr: Store WordBEQ Rs,Rt,Offset: Branch if equalJ Target: JumpHALT: Stop
mkdir cpu-simulator
cd cpu-simulator
git init
# copy file-file ini ke folder
git add .
git commit -m "Initial commit: CPU simulator"python main.py
# atau
python3 main.pyOutput akan menampilkan stage FETCH, DECODE, EXECUTE, MEMORY, WRITEBACK per cycle.
instruction_input.txt: Daftar instruksidata_input.txt: Nilai awal memory
Kamu bisa edit file tersebut untuk test program lain!
Buat penjumlahan loop:
ADDI,R1,R0,0
ADDI,R2,R0,5
ADDI,R3,R0,1
ADD,R1,R1,R3
SUB,R2,R2,R3
BEQ,R2,R0,2
J,3
HALT
Project ini sudah memenuhi semua Project Objectives Codecademy.