Saint Louis University |
Computer Science 115
|
Dept. of Math & Computer Science |
Topic: Computer Architecture, Low-Level Programming with the Super
Simple CPU from Meyer's book.
Related Reading: Ch. 5, Notes on the Super Simple CPU (abbreviated SSCPU)
Due:
8pm Monday, 11 October 2004
For this assignment, we will rely at times on the Simple Super CPU software demonstrated in class. You will need to have an Internet connection to run this software.
Exactly how many bytes are in 128MB?
Exercise 3 of Lab 5 (p. 65 of Meyer)
What SSCPU instructions do NOT involve the accumulator?
Translate the following machine code to assembler. Check using the
SSCPU.
0100000000000111
0101000000000101
0100000000000011
0001000000000101
1111000000000000
Play computer with the program above. Assume the remaining memory
cells are initialized to 0. Keep columns for the instruction number,
its corresponing opcode mnemonic and operand in decimal, the accumulator
value after the instruction executes, and the value of memory cell 5 after
the instruction executes:
# | Instruction | Accumulator | Mem 5 |
Translate the following assembler program into machine language.
Check with the SSCPU.
GO INP
SUB VAL
JZR BYE
JMP GO
BYE STP
VAL DAT 21
Play computer with the program below, assuming 2 is the
input. Keep columns for the instruction number (or label), its
corresponing opcode mnemonic and operand in decimal, the accumulator
value after the instruction executes, and the value of the data N and
P after the instruction executes:
0 LDI 3
1 STO P
2 INP
3 STO N
TOP JZR BYE ; this is line 4
5 LOD P
6 ADD P
7 STO P
8 LOD N
9 SUB ONE
10 STO N
11 JMP TOP
BYE STP
ONE DAT 1
N DAT 0
P DAT 0
# | Instruction | Accumulator | N | P |
What is the largest number of 16-bit memory cells a SSCPU could use without having to change the instruction formats at all? Explain your answer.
Suppose the assembly program below is run and the sequence of instruction numbers
executed is 0, 1, 2, 4. What number was input in the first
instruction? Explain your answer.
GO INP
SUB VAL
JZR BYE
JMP GO
BYE STP
VAL DAT 21
Write a sequence of machine code instructions to copy the data at memory location 13 to the output.
Write an assembler program to input a number and output that number, multiplied by five. For example if 10 binary were input, 1010 binary would be output just before the program stops.
Of course, the SSCPU instruction set does not have an operation for multiply. So you will need to rely on repeated use of the ADD instruction. This might be done with or without a loop.
You may assume the program is reloaded, reinitializing all of memory, every time it is run.
At the end of Ch. 7 there are a series of "Thought Questions" (p. 233). Choose one of questions #3, #4 or #5 to answer. The length of your answer should be appropriate for the question, however I envision answers in the range of 1/2-page to 1-page.
Overall, please type your answers to all of the problems in a single document to be submitted electronically. Please see details about the submission process.
The SSCPU has no instructions for multiplication, division or finding a remainder from division. These operations can be done using the existing instructions, by doing addition or subtraction in a loop. Write an assembly-language program which inputs positive numbers D and N and outputs the remainder of the dividing of D into N. For example if 5 and 15 were input, the output would be 0. If 7 and 19 were input, the output would be 5. (Of course all inputs and outputs are actually in binary.) Hint: Do this by repeated subtraction. If the remainder is 0, you will eventually end up with 0. If the remainder is not 0, you will probably need to subtract until the result is negative. In this case add D at the end to get the actual remainder. For the second example: 19-7=12, 12-7 = 5, 5-7 = -2, so add 7 back to get the remainder 5
Write an assembly-language program which inputs a positive number N and outputs 1 + 2 + 3 + ... + N, the sum of all the integers from 1 to N. For example, if 101 binary (5 decimal) were input, the output should be 1 + 2+ 3 + 4 + 5 = 15 decimal or 1111 binary. Hint: part of the challenge will be fitting your program into the limited memory of SSCPU. Try adding in the order from N down to 1.
128 x 220 = 128 x 1048576 = 134,217,728 bytes
part 6) The first, LDI, loads the accumulator with the data in the operand, 10, while LOD loads data from memory location 10, which in this case is 7.
part 7) Many machinecodes do have a store immediate, but in this CPU there would have to be a special operand format where the 12 bits for the operand contains both the memory address and the immediate data. Since 4 bits are needed for the memory address, that would leave only 8 bits for immediate data. The effect of immediate storing can be obtained from a sequence of two instructions, one loading the immediate value, and the second storing in to the desired memory address.
STP, JMP
0 LDI 7
1 STO 5
2 LDI 3
3 ADD 5
4 STP 0
# | Instruction | Accumulator | Mem 5 |
0 | LDI 7 | 7 | 0 |
1 | STO 5 | 7 | 7 |
2 | LDI 3 | 3 | 7 |
3 | ADD 5 | 10 | 7 |
4 | STP | 10 | 7 |
0110000000000000
0010000000000101
1010000000000100
1000000000000000
1111000000000000
0000000000010101
# | Instruction | Accumulator | N | P |
0
1 2 3 4 5 6 7 8 9 10 11 4 5 6 7 8 9 10 11 4 12 |
LDI 3
STO 15 INP 0 STO 14 JZR 12 LOD 15 ADD 15 STO 15 LOD 14 SUB 13 STO 14 JMP 4 JZR 12 LOD 15 ADD 15 STO 15 LOD 14 SUB 13 STO 14 JMP 4 JZR 12 STP 0 |
3
3 2 2 2 3 6 6 2 1 1 1 1 6 12 12 1 0 0 0 0 0 |
0
0 0 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 0 0 0 0 |
0
3 3 3 3 3 3 6 6 6 6 6 6 6 6 12 12 12 12 12 12 12 |