4917 Microprocessor Emulator

Written by

in

The 4917 microprocessor is an educational, hypothetical 4-bit CPU architecture originally designed by Richard Buckland for the COMP1917 / CS1 introductory computer science course at The University of New South Wales (UNSW). Because it is designed to teach low-level execution basics, writing and running code on it involves manipulating its tiny constraints: 16 memory locations (cells), 4-bit data ranges (0 to 15), and 4 specialized registers.

Depending on whether you use a web-based fantasy console variant or a command-line utility (like Andrew Rothman’s C/C++ 4917 Emulator), the process of building and running programs is highly structural. 1. Architectural Anatomy & Constraints

To write functional code, you must treat every cell as a potential instruction or data placeholder (the Von Neumann architecture):

Registers: General Purpose Register 0 (R0), General Purpose Register 1 (R1), Instruction Pointer (IP), and Instruction Store (IS).

Instructions: Vary between 1 cell (e.g., 3 to increment R0) and 2 cells (e.g., 13 7 to JUMP to memory address 7). 2. How to Write and “Build” the Program

Because the 4917 architecture is basic, “building” code typically means writing machine code in plain text via space-separated decimal or hexadecimal numbers, mirroring the memory array. Core Instruction Set Cheat-Sheet Use these opcodes directly when designing your text file: 0: HALT (Ends execution) 1 / 2: R0 = R0 + R1 / R0 = R0 - R1 3 / 4: Increment R0 / Increment R1 5 / 6: Decrement R0 / Decrement R1 8 X: PRINT memory cell X 9 X / 10 X: LOAD memory X into R0 / R1 11 X / 12 X: STORE R0 / R1 into memory X 13 X: JUMP unconditionally to memory cell X 14 X: JUMP to X if R0 == 0 Example Program: A Simple Countdown (countdown.4917) This program loads a value, counts down to zero, and stops. 9 5 5 14 4 3 0 0 0 0 0 0 0 0 0 5 Use code with caution.

Cell 0 & 1 (9 5): Loads the data value from cell 5 (which contains the number 5) into R0. Cell 2 (5): Decrements R0.

Cell 3 & 4 (14 4): If R0 equals 0, jump to cell 4 (which contains a 3 instruction, though realistically you map it to 0 or a trap loop to halt). 3. Running Programs on the Emulator Option A: Using the Command Line Emulator

If you build or use a binary terminal version like the andrewrothman/4917 repo:

Prepare file: Save your program text file with a .4917 extension.

Execute: Call the emulator binary and pass the source path as an argument: ./bin/4917 examples/countdown.4917 Use code with caution.

Debug: The terminal outputs changes to R0, R1, and IP on every cycle tick. Option B: Using a Graphical Web/App Emulator

If using an interactive UI variant (like Maarten Hus’s interactive React tool or the iOS emulator apps):

Input: Click into the individual 16 RAM cells in the display window and type your numeric machine code directly. Step/Play: Use the UI controls:

Play / Pause: Runs the program continuous at a chosen speed slider.

Step: Executes exactly one instruction so you can watch the IP point from cell to cell and monitor register fluctuations.

Restart / Reset: Flushes values back to the program initial state.

I suspect you might be studying low-level computer architecture or preparing for a systems programming course assignment involving hardware simulations. Would you like me to help you write a custom assembly script for a specific math operation (like multiplication or Fibonacci sequences) designed around these 4917 CPU constraints? AI responses may include mistakes. Learn more Fantasy CPU emulator part 1 | Blog – Maarten Hus

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *