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?

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

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.

Problem 4 (6 points)

  1. Give a single LC-3 instruction which moves the value in R1 into R5.
  2. Give a single LC-3 instruction for:
    R1 ← 0
  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
  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

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

Problem 6 (5 points)

Given the program below:
AddressBinaryHex
0x30000010 0010 0000 01110x2207
0x30010010 0100 0000 01110x2407
0x30020101 0110 1110 00000x56E0
0x30030001 0110 1100 00010x16C1
0x30040001 0100 1011 11110x14BF
0x30050000 0011 1111 11010x03FD
0x30061111 0000 0010 01010xF025
0x30071100 0000 1100 00000xC0C0
0x30080000 0000 0000 01010x0005
0x30090000 0000 0000 01000x0004
0x300A1100 0000 1100 00000xC0C0

  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).
  2. What are the values in R1, R2, and R3 when the program halts? If the program does not halt, state this.
  3. What operation does this program implement?
  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?

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.
  2. The starting memory address, as shown by the highlighted row.
  3. The "CC" value by the registers is clearly not a register. What is it?

 
Computer Sciences | UW Home