UEMU: Micro Emulator Architecture
Used only for storing program instructions. UEMU is a bit odd in
that memory consists of 16-bit instructions, not 8-bit bytes.
Normally a single instruction (or integer) stored in memory spans
several bytes, but not in UEMU!
There are 16 registers numbered 0 through F (in hex). Register F
is the program counter--it stores the memory address of the next
instruction to execute. All other registers are free for
The instruction encoding is chosen such that everything's a multiple of
4 bits long, which makes it easy to write machine language programs in
hex. There are a ridiculously small number of instructions:
- 0x1ikk: IMMEDIATE. Assign the "immediate" 8-bit value kk to register i. For example,
0x1307 would assign the value 0x07 to register 3. Note that
0x1Fkk assigns to the program counter, and is hence a jump instruction.
- 0xAijk: ADD. Add registers j and k, and assign the result to register i. For example,
if registers 2 and 3 hold values 0x40 and 0x50, 0xA123 puts the sum
0x90 into register 1. Note that 0xA111 doubles the value of
- 0xCijk: CONDITIONAL INCREMENT. If register j is greater
than or equal to register k, increment register i. For example,
if register 2 is 0x40 and register 3 is 0x50, 0xC232 increments
register 2 to 0x40, while 0xC223 does nothing. Note that
incrementing the program counter skips the next program instruction.
- 0xE0jk: EMULATOR OUTPUT. Print the value in register k in
decimal, followed by a space if j==0, a newline if j==1, a tab if j==2,
and a comma if j==3. For example, 0xE012 prints the value of register 2 in decimal followed by a newline.
EMULATOR INPUT. Read a value from standard input into register
k. Accepts decimal, hex, and octal using the C convention.
For example, 0xE105 loads a value into register 5.
- 0xEDkk: EMULATOR DUMP. Dump out the values of all the
registers. If kk==0, dumps out the program memory as well.
If kk=0xFF, does nothing.
- 0xEE0k: EMULATOR EXIT. Stop running the emulator, but print out the value in register k.
The input file consists of machine language instructions, written with
one instruction at the start of each line. Instructions should be
encoded in hexadecimal using the usual 0xABCD notation, but can also be
written in octal (07423) or even decimal. Anything after the
instruction is ignored, and so should be used for comments. Lines
that don't start with integers are ignored, so "# Not 0x23, it ain't"
is a comment, as is "// Crap.", "/* Nooooo! */", as well as "Why...
The first instruction is loaded into memory address 0x80, which is the
initial value of register F (the program counter). Each
instruction read from the file is loaded into memory in the subsequent
address--so the 5th instruction goes into 0x85, the 9th into 0x89, the
15th into 0x8F, the 16th into 0x90, and so on. It's usually
a good idea to start with a 0xED00 instruction (dump program memory and
registers) to make sure your program loaded into the addresses you
think it did.
You can pass the input filename in as a command-line parameter,
drag-and-drop the input file onto uemu, or copy the input file to
"input.txt" and run uemu without parameters.
See the examples/ directory for some simple example programs.
Be aware that the Windows version will expect Windows newline
characters in your input files. If your newlines get screwed up
(for example, the file looks weird in notepad and some of your
instructions don't dump out right) you can fix them by viewing the file
in a web browser and Save As text.
O. Lawlor, email@example.com
Up to: Class Site, CS, UAF