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

Saint Louis University

Computer Science 140
Introduction to Computer Science

Michael Goldwasser

Fall 2007

Dept. of Math & Computer Science

Assignment 05

Architecture, Low-Level Programming

Contents:


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, 2 October 2007
Extended to 8pm Tuesday, 9 October 2007


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 appear at end of this file)

  1. Exactly how many bytes are in 128MB?

  2. What SSCPU instructions do NOT involve the accumulator?

  3. Translate the following machine code to assembler.  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 assembler 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
    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


Problems to be Submitted (20 points)

  1. (4 points)

    Although the SSCPU simulator only displays 16 memory cells, the instrutcion 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 assembler program that inputs two numbers from the user and outputs the maximum of the two.

  5. (5 points)

    Write an assembler program that inputs a number and output that number multiplied by five.

    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.

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.


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.


Practice Problem Solutions

  1. 128 x 220 = 128 x 1048576 = 134,217,728 bytes

  2. STP, JMP

  3. 0  LDI  7
    1  STO  5
    2  LDI  3
    3  ADD  5
    4  STP  0

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

  5. 0110000000000000
    0010000000000101
    1010000000000100
    1000000000000000
    1111000000000000
    0000000000010101

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


CSCI 140, Fall 2007
Michael Goldwasser
goldwamh at our university domain

Last modified: Friday, 26 October 2007
Assignments | Course Home | Schedule & Lecture Notes | Submit | Tutoring Hours