Computer Sciences Dept.

CS/ECE 252 Introduction to Computer Engineering

Spring 2011 All Sections
Instructor: Andy Phelps
TAs: Newsha Ardalani, Peter Ohmann, Jai Menon

URL: http://www.cs.wisc.edu/~aephelps/courses/cs252/Spring2011/

Homework 5 // Due at the BEGINNING of lecture Mon, Mar 28

Primary contact for this homework: Peter Ohmann [ohmann at cs dot wisc dot edu]

You may do this homework with one other person from your section. You must put both names on the assignment. Please staple multiple pages together.

Problem 1 (2 points)

A memory has 512 distinct memory locations and an addressability of 4 bits. Can we determine the size of the MAR and/or the MDR (i.e. the number of bits in each) based on this? If not, what other information would we need? If so, what is the size of each?

The MAR size is determined by the total memory locations in the memory. 512 = 29, so the MAR is 9 bits.
The MDR size is determined by the addressability. The MDR is 4 bits.

Problem 2 (3 points)

What does the following LC-3 instruction do? (Be specific; that is, give specific register numbers or memory locations.)

AddressBinaryHex
0x450A0011 0110 0000 01110x3607

The instruction is: ST R3 PC+7. So, specifically, the value currently in R3 would be stored at address 0x450B + 7 = 0x4512.

Problem 3 (3 points)

We wish to execute a single instruction which subtracts the decimal number 30 from R1 and stores the result in R2. Can we do this? If yes, give the instruction. If not, explain why not.

No, we cannot perform this operation in a single instruction. The ADD instruction only has an immediate field of 5 bits. Therefore, the most negative number we can represent is -16.

Problem 4 (6 points)

  1. Give a single LC-3 instruction which moves the value in R1 into R5.
    InstructionBinaryHex
    ADD R5 R1 0x00001 1010 0110 00000x1A60
    InstructionBinaryHex
    AND R5 R1 0x01F0101 1010 0111 11110x5A7F
    InstructionBinaryHex
    AND R5 R1 R10101 1010 0100 00010x5A41
  2. Give a single LC-3 instruction for:
    R1 ← 0
    InstructionBinaryHex
    AND R1 R1 0x00101 001X XX10 0000~0x5260
  3. The LC-3 has no subtract instruction, but we can perform subtraction on the LC-3, nevertheless. Give a set of three LC-3 instructions to compute:
    R3 ← R2 - R1
    InstructionBinaryHex
    NOT R1 R11001 0010 0111 11110x927F
    ADD R1 R1 0x10001 0010 0100 00010x1241
    ADD R3 R2 R10001 0110 1000 00010x1681
    InstructionBinaryHex
    NOT RX R11001 001X XX11 1111~0x927F
    ADD RY RX 0x10001 YYYX XX00 0001~0x1241
    ADD R3 R2 RY0001 0110 1000 0YYY~0x1681
  4. The LC-3 has no OR instruction, but we can perform the or operation on the LC-3, nevertheless. Give a set of four LC-3 instructions to compute:
    R3 ← R2 | R1
    InstructionBinaryHex
    NOT R2 R21001 0100 1011 11110x94BF
    NOT R1 R11001 0010 0111 11110x927F
    AND R3 R2 R10101 0110 1000 00010x5681
    NOT R3 R31001 0110 1111 11110x96FF

Problem 5 (5 points)

Write an LC-3 program to perform the following operation:
R3 ← |R1 + R2|
That is, the program should add R1 to R2, take the absolute value of the sum, and then halt.

Note: Your program should start at memory address 0x3000. The instructions for your answer may be in either binary or hex, but please also include your set of instructions in the book's assembly-style format (e.g. R1 ← R2 + R3).

Of course, there are a number of ways to do this, and the following is just one example:

AddressBinaryHexInstruction
0x3000 0001 0110 0100 00100x1642R3 ← R1 + R2
0x3001 0000 0110 0000 00100x0602BRzp 0x3004
0x3002 1001 0110 1111 11110x96FFR3 ← NOT (R3)
0x3003 0001 0110 1110 00010x16E1R3 ← R3 + 1
0x3004 1111 0000 0010 01010xF025HALT

Problem 6 (5 points)

Given the program below:
AddressBinaryHexInstruction
0x30000010 0010 0000 01110x2207R1 ← M[0x3008]
0x30010010 0100 0000 01110x2407R2 ← M[0x3009]
0x30020101 0110 1110 00000x56E0R3 ← R3 & 0x0
0x30030001 0110 1100 00010x16C1R3 ← R3 + R1
0x30040001 0100 1011 11110x14BFR2 ← R2 - 0x1
0x30050000 0011 1111 11010x03FDBRP 0x3003
0x30061111 0000 0010 01010xF025HALT
0x30071100 0000 1100 00000xC0C0RET (N/A)
0x30080000 0000 0000 01010x0005DATA (5)
0x30090000 0000 0000 01000x0004DATA (4)
0x300A1100 0000 1100 00000xC0C0RET (N/A)

  1. Write out each instruction in the book's assembly-style format (e.g. R1 ← R2 + R3). Label each line in your answer by its address in memory (as above).
    (see above)
  2. What are the values in R1, R2, and R3 when the program halts? If the program does not halt, state this.
    RegisterValue
    R15
    R20
    R320
  3. What operation does this program implement?
    Multiply
  4. This program is not particularly useful (despite the fact that it does perform some operation). What new instruction should be inserted just prior to address 0x3006 so that we could actually use the result in the future?
    Any sort of ST operation so that the value is retained in memory somewhere.

Problem 7 (3 points)

The purpose of this problem is to get you set up with the LC-3 PennSim simulator, which will be important for subsequent homework. You can get the LC-3 simulator from the PennSim link in the sidebar.

If you need additional help getting set up with the PennSim simulator, try this page.

After opening the LC-3 PennSim simulator, please report the following:

  1. The names of the LC-3 registers that can be seen in the simulator window, and their corresponding values.
    RegisterValue
    R0x0000
    R1x0000
    R2x0000
    R3x0000
    R4x0000
    R5x0000
    R6x0000
    R7x0000
    PCx0200
    MPRx0000
    PSRx8002
  2. The starting memory address, as shown by the highlighted row.
    0x0200
  3. The "CC" value by the registers is clearly not a register. What is it?
    NZP

 
Computer Sciences | UW Home