AL - The Assembly Language Simulator-1
<PRE>AL is an assembly language simulator that teaches basic assembly language ideas, the concept of program assembly and the basics of the CPU cycle.
I wrote this simulation for a class I teach at Pellissippi State Community College in Knoxville, TN.
To use AL:
1. Click the "Clear" button to remove existing assembly and machine language code.
2. Press the "Write Code" button to begin entering assembly language instructions.
3. After all of your instructions have been entered, press the "Assemble" button to assemble your code. Each line of your assembly language program will be translated into one line of machine code.
4. Press the "Load" button to load the resulting machine code into RAM.
5. Press the "Run" button to execute the code.
To re-run code that has already been assembled, you must press the "Reset" button to reset the PC (Program Counter), the IR (Instruction Register) and RAM. Then load your machine code into RAM by pressing the "Load" button.
The following code will read in 2 numbers, subtract the second from the first, and output the result:
LOAD 16, R1
SUB 15, R1
STORE 14, R1
Assembly Language Instructions
-- read a value from 0-255 and store it in the indicated RAM address (1-16)<BR />
-- output the value in the indicated address (1-16)
LOAD address, register
-- load the contents of the address into the indicated register
LOAD 16, R2
STORE address, register
-- store the contents of a register into the indicated address
STORE 15, R1
ADD address, register
-- add the contents of the address to the value in the indicated register
ADD 14, R2
SUB address, register
-- subtract the contents of the address from the value in the indicated register
SUB 13, R1
JUMP address, register
-- jump to address on non-zero register value, the PC will be set to the indicated address as long as the register is non-zero
JUMP 1, R1
-- terminate execution
The machine code is created from the assembly code in the following format:
123 4567 8
where the first 3 bits are the operation code,
the next 4 bits are the address used in an operation,
and the last bit is the number of the register used. For operations that do not require a register, this bit is set to 0.
The first 3 bits are an <B>operation code</B> as follows:
000 - STOP
001 - READ
010 - WRITE
011 - ADD
100 - SUB
101 - LOAD
110 - STORE
111 - JUMP
The 4 <B>address</B> bits are used to specify a location in RAM. Locations 1-16 are specified in the operation as values 0-15 (0000-1111).
The final bit of the machine code instruction specifies which <B>register</B> is indicated by the instruction. A 0 indicates register R1 and a 1 indicates register R2. For operations that do not require a register, this bit is set to 0.