Department of Electrical and Computer Engineering
The University of Texas at Austin

EE 306 Fall 2002
Yale Patt, Instructor
TAs: Asad Bawa, Linda Bigelow, Mustafa Erwa, Lester Guillory, Kevin Major,
Moinuddin Qureshi, Paroma Sen, Tanay Shah, Santhosh Srinath,
Matt Starolis, David Thompson, Vikrant Venkateshwar

Problem Set #5
Due November 4, 2002 before class

Problem Set 5

1. Optional - Problem 8 from PS 4
2. Optional - Problem 9 from PS 4
3. Optional - Question 6.7 from the book.

Textbook errata:

Line x3004 should be 0010 010 0 0001 1000.
Line x300C should be 0000 001 000000101

4.a) Using the iteration construct, write an LC-2 machine language routine that displays exactly 10 Zs on the screen.

b) Suppose you want your program in part (a) to output 14 Zs instead of 10. Modify your program to output 14 Zs by changing only one line in your code.

5. Optional - Notice that we can shift a number to the left by one bit position by adding the number to itself. For example, when the binary number 0011 is added to itself, the result is 0110. Shifting a number one bit position to the right is not as easy. Devise an algorithm to shift the contents of location x3100 to the right by one bit and explain it in 20 words. Draw a flow diagram for your solution like the one shown in Figure 6.3 in the book (page 125).

6. Write an assembly language program to compute the XOR of two memory locations A and B, stored in memory at locations x5000 and x5001, respectively. Store the result in location x5002 in memory. Your program should begin at location x5003 in memory.
(Hint: Draw the truth table for a 1 bit XOR function, then realize the truth table with gates)

7. Problem 7.13 (Page 154) from the textbook.

8.a) Problem 7.8 (Page 153) from the textbook.
b) In the previous subsection, will the error be detected by the assembler?

9. Recall the BUSYNESS pattern for eight machines from Problem 15 of Problem Set 1.

Assume that bits [15:8] of memory location labeled PATTERN is the BUSYNESS pattern for eight machines, and bits [7:0] are all zeros as shown below.

```15                 8 7               0
<-BUSYNESS pattern-> <-   all zero  ->
```

For example, if the BUSYNESS pattern is 01110011, the contents of the memory location PATTERN is 01110011 00000000. The following piece of code uses this bit pattern as input and tries to output the number of machines that are free. For example, the pattern 01110011 00000000 must have produced an output 65410 indicating that the machines 6,5,4,1 and 0 are free. But the code is infested with bugs!! What happens when you try to execute this code?
```        .ORIG x3000          ; INITIALIZATION
AND     R1, R1, #0
LD      R2, PATTERN  ; R2 HOLDS THE BUSYNESS PATTERN
BRn     OUTPUT
NEXT    ADD     R2, R2, R2   ; CHECK IF THE MACHINE IS FREE
BRn     OUTPUT
BRp     NEXT
;       BRz     END
OUTPUT  LD      R0, ASCII    ; DISPLAY THE MACHINE NUMBER
TRAP    x21
ADD     R1, R1, #-1  ; CHECK IF OTHER MACHINES ARE FREE
BRnzp   NEXT
END     TRAP    x25
PATTERN .FILL   x7300
ASCII   .FILL   x0030
.END
```

After some deep thought, the programmer made two changes in the program.

(1) He modified a single line and (2) removed an instruction from its current position and placed it before a different instruction to make his code work. What did the programmer do?