|
|
|
Op-code | Mnemonic | Function | Example |
001 | LOAD | Load the value
of the operand into the Accumulator |
LOAD 10 |
010 | STORE | Store the value of the Accumulator at the address specified by the operand | STORE 8 |
011 | ADD | Add the value of the operand to the Accumulator | ADD #5 |
100 | SUB | Subtract the value of the operand from the Accumulator | SUB #1 |
101 | EQUAL | If the value of the operand equals the value of the Accumulator, skip the next instruction | EQUAL #20 |
110 | JUMP | Jump to a specified instruction by setting the Program Counter to the value of the operand | JUMP 6 |
111 | HALT | Stop execution | HALT |
A simple machine language |
In the machine language above, notice that some of the operands include a # symbol. This symbol tells the CPU that the operand represents a number rather than a memory address. Thus, when the assembler translates an instruction with a # symbol, the resulting machine code will have a '1' in the position of the number bit. Also notice the central role that the Accumulator register plays. Nearly all the operations affect the value of this register since the Accumulator acts as a temporary memory location for storing calculations in progress. With our machine language defined, we are ready to take a look at some simple programs.
The first program is called Sum. This program adds the numbers stored in two memory locations. Mathematically, this program represents the formulas x = 2, y = 5, x + y = z where the variables x, y, and z correspond with the memory locations 13, 14, and 15 respectively. The instructions for the program are listed below. Read through the program, and then view the animation of this program by clicking the "View Animation" link.
# | Machine code | Assembly code | Description |
0 | 001 1 000010 | LOAD #2 | Load the value 2 into the Accumulator |
1 | 010 0 001101 | STORE 13 | Store the value of the Accumulator in memory location 13 |
2 | 001 1 000101 | LOAD #5 | Load the value 5 into the Accumulator |
3 | 010 0 001110 | STORE 14 | Store the value of the Accumulator in memory location 14 |
4 | 001 0 001101 | LOAD 13 | Load the value of memory location 13 into the Accumulator |
5 | 011 0 001110 | ADD 14 | Add the value of memory location 14 to the Accumulator |
6 | 010 0 001111 | STORE 15 | Store the value of the Accumulator in memory location 15 |
7 | 111 0 000000 | HALT | Stop execution |
Sum program [view animation] |
The second program is called Count. This program counts up to a number specified by the programmer in the first instruction. Notice that this program incorporates a loop construction by using the JUMP and EQUAL instructions. Every time the value in the Accumulator is incremented, the count is tested to see if it has reached the specified amount. Read through the program, and then view the animation of this program by clicking the "View Animation" link.
# | Machine code | Assembly code | Description |
0 | 001 1 000101 | LOAD #5 | These two operations set the count value to five |
1 | 010 0 001111 | STORE 15 | |
2 | 001 1 000000 | LOAD #0 | Initialize the count to zero |
3 | 101 0 001111 | EQUAL 15 | Test to see if count is complete; if yes, skip next instruction and go to instruction 5; if no, go to next instruction |
4 | 110 1 000110 | JUMP #6 | Set Program Counter to 6 |
5 | 111 0 000000 | HALT | Stop execution |
6 | 011 1 000001 | ADD #1 | Increment the count in the Accumulator |
7 | 110 1 000011 | JUMP #3 | Set Program Count to 3 |
Count program [view animation] |
References
- Brookshear, J. G. (1997), Computer Science: An Overview, Fifth Edition, Addison-Wesley, Reading, MA.
- Intel (2000), "Virtual press kit for 0.18 micron processor launch," https://developer.intel.com/pressroom/kits/events/18micron/photos.htm.