HW 2: Instruction Encoding & Simulators
CS 441 Homework, Dr. Lawlor
For this homework problem, I'd like you to design your own instruction encoding that supports:
- At least 32 general-purpose registers (modern compilers need lots of register space)
- The following integer register-to-register operations:
- Arithmetic: add, subtract, multiply, divide
- Bitwise operations: AND, OR, XOR, NOT, left shift, right shift, right arithmetic shift
- Load a 16-bit constant into a register
- The following branch operations:
- Branch unconditionally (goto)
- Branch if less than
- Branch if greater than
- The following input/output operations:
- Read an integer from standard input into a register
- Write an integer from a register to standard output
- Exit the emulator with an integer return code
Feel free to use a CISC or RISC encoding, 2 or 3 operand instructions, ASCII or binary format--your choice!
To test out your instruction encoding, write a simulator to run
programs written with your encoding on a normal machine. A
simulator usually is just a fetch-and-execute loop, where you grab the
next instruction from the program (fetch), look at what it says to do
(decode), and then do it (execute). For reference, here's my
little "UEMU" simulator (but you can't do exactly what I did!).
This homework will be due at midnight on Thursday, September 17 on Blackboard.
My preferred format is a single runnable source code file, with your
instruction set's human readable design in a comment at the top, the
simulator code included right there, and a main function and
well-commented sample program hardcoded in.