The Wombat1 Computer
The Wombat1 is the first product of the ACC (Australian Computer Corporation). The Wombat1 has one "accumulator" register to store the results of operations. Also, all input and output is via the accumulator. There is a memory (RAM) and there are several other registers that are invisible to the machine-language programmer.
The Wombat1 machine language instructions are 16 bits long and have the following form: op-code memory-address, where op-code is a 4-bit operation code and memory-address is a 12-bit memory address. In the following descriptions, acc refers to the the accumulator register, m refers to the memory address in the instruction and c(m) indicates the contents of memory location m. The symbol "-->" indicates data movement (copying the source into the destination).
| Opcode | ||||
|
Mnemonic |
(bin) |
(hex) |
(dec) |
Description |
| STOP | 0000 |
0 |
0 | stop execution of the program |
| LOAD | 0001 |
1 |
1 |
c(m) --> acc |
| STORE | 0010 |
2 |
2 | acc --> c(m) |
| READ | 0011 |
3 |
3 | input --> acc |
| WRITE | 0100 |
4 |
4 | acc --> output |
| ADD | 0101 |
5 |
5 | acc + c(m) --> acc |
| SUBTRACT | 0110 |
6 |
6 | acc - c(m) --> acc |
| MULTIPLY | 0111 |
7 |
7 | acc * c(m) --> acc |
| DIVIDE | 1000 |
8 |
8 | acc / c(m) --> acc |
| JUMP | 1001 |
9 |
9 | go to the instruction at memory location m |
| JMPZ | 1010 |
A |
10 | if acc = 0, go to m |
| JMPN | 1011 |
B |
11 | if acc < 0, go to m |
For example, the machine language statement "1001000000001110" says to jump unconditionally to the instruction in memory location 14.
There are 12 machine instructions for the Wombat1, each associated with a 4-bit op-code, as shown in the table above. These instructions are: HALT (stop), READ (get input from the user ), WRITE (send output to the user), LOAD (transfer data from the main memory to the acc), STORE (transfer data from the acc to the main memory), ADD (add a value from the main memory to the value in the acc, putting the result in the acc), SUBTRACT, MULTIPLY, DIVIDE (all similar to ADD), JMPZ (if the value in the acc is 0, jump to a new location to obtain the next instruction to be executed), JMPN (if the value in the acc is less than 0, jump to a new location to obtain the next instruction to be executed), JUMP (jump to a new location unconditionally).
Pre-lab Exercise W1-0
The following is a sample Wombat1 machine-language program that reads in non-negative integers and adds them up. It stops reading when it reads in a negative number. It then writes out the sum. The first 5 bits (followed by a colon) in each line below correspond to the address (location) in memory where the 16-bit instruction is stored. The next 4 bits (after the colon) give the opcode and the remaining 12 bits correspond to the memory address used by the instruction. The semicolon ";" and everything after it is just a comment to help you understand what the instruction means. Note that the 12 address bits are unused in some instructions, such as the first instruction (the read instruction), since this instruction just gets input from the user and puts it in the accumulator.
|
location |
opcode |
address | comments |
|
00000: |
0011 |
000000000000 | ; read n -> acc |
|
00010: |
1011 |
000000001010 | ; if n<0 jump to address 1010 |
|
00100: |
0101 |
000000010000 | ; add n to the sum (at address 10000) |
|
00110: |
0010 |
000000010000 | ; store the new sum |
|
01000: |
1001 |
000000000000 | ; go back & read in the next number |
|
01010: |
0001 |
000000010000 | ; load the final sum into the acc |
|
01100: |
0100 |
000000000000 | ; output the final sum |
|
01110: |
0000 |
000000000000 | ; stop |
|
10000: |
0000 |
000000000000 | ; location where the sum is stored |
Modify the program so that it computes the product of the integers in the input instead of the sum. Also, this time, instead of stopping when a negative number is read in, the program should stop only when the integer 0 is read in. That is, 0 will act as a "sentinel" to terminate the input. The sentinel value should not be included in the product.
Pre-lab Exercise W1-1
Write a Wombat1 machine-language program that reads in one or more non-negative integers and outputs the average of the numbers (as an integer). It stops reading integers after it reads a negative integer. The negative integer is just a sentinel value and so is not to be included in the average. Your program should work with any number of non-negative integers.
Pre-lab Exercise W1-2
Below you will find a machine language program with no comments explaining the code. Figure out what the program does. Do this by first figuring out what each line does and then also give a high-level summary of what the program does, e.g., "This program reads in two integers and outputs the larger of the two". Hand in your line comments and your summary.
| address |
16-bit value | |
| 00000: | 0011000000000000 | |
| 00010: | 1011000000000110 | |
| 00100: | 1001000000000000 | |
| 00110: | 0111000000001100 | |
| 01000: | 0100000000000000 | |
| 01010: | 0000000000000000 | |
| 01100: | 1111111111111111 |
Exercises W1-0, W1-1, and W1-2 are due at the start of class on Wednesday. I'll grade them and bring them with me to class on Friday. You'll want them as you do the lab assigment on Friday.