Computer Sciences Dept.

CS/ECE 252 Introduction to Computer Engineering

Spring 2008 All Sections
Instructor David A. Wood
TAs Spyridon Blanas, Priyananda Shenoy & Shengnan Wang

URL: http://www.cs.wisc.edu/~david/courses/cs252/Spring2008/

Homework 6 // Due at lecture Monday April 14

Primary contact for this homework: Priyananda Shenoy [shenoy at cs.wisc.edu]
You must do this homework alone.
You will lose points if:
  • You have not included your name and your section.
  • You have not stapled multiple pages together.
Problems 1,2,3 are programming exercises.This is how you need to solve it:
  • Open the LC3 editor.
  • Write the binary code for each instruction in your program , one instruction per line. The first line should be "0011000000000000", which is the binary representation of x3000 which is the starting address.
  • Remember that the last instruction in your program should be HALT.
  • Press the button on the menu which says 'B'. This will generate the binary object file ( extension 'obj' ). Save this file somewhere.
  • Open the LC3 Simulator.
  • Open the obj file created using 'File'->'Load Program'.
  • Double click on the small grey square at the beginning of the line corresponding to the HALT instruction. You should see a red circle there.
  • Press the button. This will execute your program and stop at the breakpoint.
  • Take a screenshot. You can use the 'Print Screen' button on your keyboard to do that. You can use an image editor like MS Paint to save it into a file.
Your solution must precisely adhere to the format specified below:
    Your solution consists of two parts: a screenshot of the simulator and some written information.
  • Your screenshot must have all the following:
    • The instructions should start at x3000.
    • All the registers must be visible.
    • For questions 2,3 the memory locations which are referenced must be visible.
    • You should have a breakpoint (red circle) at your HALT instruction and the PC (blue arrow) should be pointing to that instruction when you take your screenshot.
  • Along with this you must also write the following:
    • For each instruction, you need to write a small comment on what it does. You can just annotate the screenshot.
    • You need to specify what registers are used by the program and what is is used for.
A sample programming exercise and solution is given below.

Problem 0


Write an LC-3 program that finds the two's complement of a number stored in memory and stores the result back in memory. The number is stored in memory location x301F. Store the result in x301E. For the screenshot, make the value in memory location x301F be x4321.
Solution:

Problem 1


Write a LC3 program which compares two numbers in R3 and R4 and puts the larger number in R1. For the screenshot, make R3 = x8765 and R4 = x0666. If R3 = R4 then R1 should have the same value as R3 and R4. (15 points)

Problem 2


Write a LC3 program which compares two numbers in memory locations 0x301D and 0x301E and puts the larger number in memory location 0x301F.For the screenshot, make the value in memory location x301D to be x8765 and the value in memory location x301E to be x0666. Your screenshot should show memory location x301F . (20 points)

Problem 3


Write a LC3 program which compares 10 numbers in memory locations starting from 0x3100 and ending at 0x3109 inclusive, and puts the largest number among them in the register R7.(30 points)
Your solution should use a looping construct like the examples in lecture (i.e. if you were asked to examine locations ranging from x3100 to x3120, the number of instructions in your program would not change).
Use the following file as your data file for this problem: hw6p3data.obj. In the simulator, you will need to load this file under 'File' -> 'Load Program' in addition to your program file. You do not need to capture the data from this file in your screenshot.

Problem 4


4. Which LC3 addressing mode makes the most sense to use under the following conditions.(There may be more than one correct answer)
a) You want to load one value from an address which is less than +/- 28 locations away.
b) You want to load one value from an address which is more than +/- 28 locations away.
c) You want to load an array of sequential addresses.
(15 points)

Problem 5


Given instructions ADD,JMP,LEA,NOT identify whether the instructions are operate instructions, data movement instructions or control instructions. For each instruction list the addressing modes that can be used with the instruction. (20 points)

Extra Credit


Explain why program 1 would fail if R3 = 0x8765 and R4 = 0x7654(hint: overflow). Explain how you would solve this (you just have to give an explanation for how you can take care of this, don't have to write a program). (10 points)

 
Computer Sciences | UW Home