Computer Sciences Dept.

CS/ECE 252 Introduction to Computer Engineering

Spring 2007 Sections 1 and 2
Instructor Mark D. Hill and TAs Marc de Kruijf & Sanghamitra Roy
URL: http://www.cs.wisc.edu/~markhill/cs252/Spring2007/

Homework 6 // Due at Lecture Wed Mar 28

You may do this homework in a group of two students from the same 252 section and turn in one solution at lecture with BOTH students names at the top.

First contact for questions is TA Marc de Kruijf at: dekruijf@cs.wisc.edu


Special Instructions

For problems 3-5, please submit a screenshot of your solution. Your screenshot should look like the example below; the instructions should start at address x3000 and all register information and the instructions of your program should be visible from the screenshot. For problems 3-4, the data that you are asked to reference should be visible as well. 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 (i.e. your program should be one instruction away from finished).

In addition to your screenshot, also submit a print-out of your commented .asm program/instruction file for these problems. In LC-3 comments are added by placing a ";" character after an assembly instruction, followed by your comments. If you do not comment your code to make it relatively understandable you will lose points! (Also please write your programs in assembly rather than binary or hexadecimal -- it is to both our benefit!)

Taking a screenshot in Windows XP is easy:

  1. Make sure your simulator window is in focus.
  2. Hit the ALT key and the PrintScreen key together at the same time.
  3. Start the program "Paint" (comes with Windows under Start -> All Programs -> Accessories). You can alternatively use "Word" if you prefer.
  4. Paste (i.e. hit the CTRL key and the V key together at the same time).
  5. Print (i.e. hit the CTRL key and the P key together at the same time).

Problem 1

Problem 5.14 on page 147 of ItCS.

Problem 2

Problem 5.22 on page 148 of ItCS. We encourage you to use the LC-3 simulator to assist you with this problem, but its use is not required.

Problem 3

Write an LC-3 program that adds two numbers in memory together and stores the result back in memory. The operands are stored in x301E and x301F. Store the result in x301D. You do not need to worry about overflow. For the screenshot, make your operands be x1234 and xABCD.

Problem 4

Write an LC-3 program that that determines if the number stored in memory location x301F is odd. If it is odd, store a value of 1 in R1. Otherwise, R1 is 0. For the screenshot, make the value in memory location x301F be xABCD.

Also submit a short explanation of how you would modify one or more instructions in your program to identify even numbers rather than odd numbers. Fewer instructions is better. There is no screenshot required for this part of the problem.

Problem 5

Write an LC-3 program that searches for the binary number sequence '1001 1110 0110 1010' in memory locations ranging from x3100 to x3110 (inclusive). Set R0 to the number of times that the sequence is found. 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: hw6p5_data.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.

 
Computer Sciences | UW Home