Assignments | Class Photo | Course Home | Schedule & Lecture Notes | Submit | Tutoring Hours

## Assignment 05

### Overview

Topic: Computer Architecture, Low-Level Programming with Meyer's Super Simple CPU.
Related Reading: Ch. 5, Notes on the Super Simple CPU (abbreviated SSCPU)
Due: 8pm Tuesday, 4 March 2008
8pm Thursday, 6 March 2008

### Internet Requirements

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.

### Practice Problems (answers available here)

1. Exactly how many bytes are in 128MB?

2. What SSCPU instructions do NOT involve the accumulator?

3. Translate the following machine code to assembly language.  Check using the SSCPU.

0100000000000111
0101000000000101
0100000000000011
0001000000000101
1111000000000000

4. 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

5. Translate the following assembly language program into machine language.  Check with the SSCPU.

```GO  INP
SUB VAL
JZR BYE
JMP GO
BYE STP
VAL DAT 21
```

6. 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
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

### Problems to be Submitted (20 points)

1. (4 points)

Although the SSCPU simulator only displays 16 memory cells, the instruction format could presumably utilize more memory. What is the largest number of memory cells that the SSCPU could effectively use without having to change the instruction format? Explain your answer.

2. (3 points)

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
```

3. (3 points)

Write a sequence of machine code instructions to copy the data at memory location 13 to the output.

4. (5 points)

Write an assembly-language program that inputs two numbers from the user and outputs the value of the expression A - B, where A represents the first value to be inputted and B represents the second value inputted.

5. (5 points)

Write an assembly-language program that inputs two numbers from the user and outputs the maximum of the two.

### Extra Credit (4 points)

1. (2 points)

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

2. (2 points)

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.

CSCI 140, Spring 2008