Department of Electrical and Computer Engineering
University of Texas at Austin
EE 379K, Fall 2000
Y. N. Patt, Instructor
TAs: Kathy Buchheit, Laura Funderburg, Chandresh Jain, Onur Mutlu, Danny Nold, Kameswar Subramanian, Francis Tseng, Brian Ward
Problem Set 5
Due: November 13, 2000

Instructions: Remember to put all group members' names on the solution sheet. Also, remember to put the unique number of the discussion session you want the homework returned back to you. Good luck!!

Problem 1

  1. What problem is likely to occur if the keyboard hardware does not check the KBSR before writing to the KBDR?
  2. What problem could occur if the CRT output hardware does not check the CRTSR before writing to the screen?


Problem 2
Refer to Figure 9.6 of the textbook, the halt service routine.

  1. What starts the clock after the machine is HALTed? Hint:  How can the halt service routine return after bit 15 of the machine control register is cleared?

  2.  
  3. Which instruction actually halts the machine?


Problem 3

  1. How many TRAP service routines can be implemented in the LC-2? Why?

  2.  
  3. Why must a RET instruction be used to return from a TRAP routine? Why won't a BRnzp (Unconditional BR) instruction work instead?

  4.  
  5. How many accesses to memory are made during the processing of a TRAP instruction? Assume the TRAP is already in the IR.


Problem 4
Which of the following combinations describe the system in Section 8.2.2 of the textbook? Please select one.


Problem 5
Consider the following LC-2 assembly langauge program:

          .ORIG x3000
    L1    LEA      R1, L1
          AND      R2, R2, x0
          ADD      R2, R2, x2
          LD       R3, P1
    L2    LDR      R0, R1, xC
          OUT
          ADD      R3, R3, -1
          BRZ      GLUE
          ADD      R1, R1, R2
          BRNZP    L2
    GLUE  HALT
    P1    .FILL    xB
          .STRINGZ "HBoeoakteSmtHaotren!s"
          .END
  1. After this program is assembled and loaded, what binary pattern is stored in memory location x3005?

  2.  
  3. Which instruction (provide a memory address) is executed after the instruction at location x3005 is executed?

  4.  
  5. Which instruction (provide a memory address) is executed prior to the instruction at location x3006 is executed?

  6.  
  7. What is the output of this program?


Problem 6
Consider the following LC-2 assembly language program:

       .ORIG x3000
       LEA   R0, DATA
       AND   R1, R1, #0
       ADD   R1, R1, #9
LOOP1  ADD   R2, R0, #0
       ADD   R3, R1, #0
LOOP2  JSR   SUB
       ADD   R2, R2, #1
       ADD   R3, R3, #-1
       BRP   LOOP2
       ADD   R1, R1, #-1
       BRP   LOOP1
       HALT
DATA   .BLKW #10
SUB    LDR   R5, R2, #0
       NOT   R4, R5
       ADD   R4, R4, #1
       LDR   R6, R2, #1
       ADD   R4, R4, R6
       BRZP   CONT
       STR   R5, R2, #1
       STR   R6, R2, #0
CONT   RET
       .END
Assuming that the memory locations starting at label DATA contains ten 2's complement numbers. These numbers are filled in before the program executes. What is the relationship between the final values at DATA and the initial values at DATA?
 

Problem 7
Peter decided to design a variant of the LC-2 that did not need a keyboard status register. Instead, he created a readable/writable keyboard data and status register (KBDSR), which contains the same data as the KBDR. With the KBDSR, a program requiring keyboard input would wait until a nonzero value appeared in the KBDSR. The nonzero value would be the ASCII value of the last key press. Then the program would write a zero into the KBDSR indicating that it had read the key press. Modify the basic input service from Section 8.2.2 of the textbook to implement Peter's scheme.
 

Problem 8
In class, we learned one way of performing binary to ASCII conversion (program available from the course homepage). We notice that the code to output the hundreds digit and the code to output the tens digit is similar. Instead of repeating the code to print the hundreds digit, and the tens digit, we can use a subroutine. The subroutine called OUTDIGIT does exactly this (see below).

          .ORIG x3000
          ;; initialize block
          AND   R0, R0, #0   ; clear count
          LEA   R2, OUTBLK   ; R2 is the pointer to OUTBLK

          ;; output the sign and obtain the absolute value of the number
          LD    R3, PLUS     ; R3 contains the ASCII value for '+'
          STR   R3, R2, #0   ; store '+' into the first location of OUTBLK
          LD    R1, VALUE    ; R1 contains the number to be displayed
          BRzp  CONTINUE     ; branch if number is zero or positive
          NOT   R1, R1       ;
          ADD   R1, R1, #1   ;
          LD    R3, MINUS    ; R3 contains the ASCII value for '-'
          STR   R3, R2, #0   ; store '-' into the first location of OUTBLK
CONTINUE  ADD   R2, R2, #1   ; increment pointer to OUTBLK
;; ======================================================================
;; process the hundreds digit
          LD    R5, HUN
          LD    R6, MINUSHUN
          JSR   OUTDIGIT
;; ======================================================================
;; process the tens digit
          LD    R5, TEN
          LD    R6, MINUSTEN
          JSR   OUTDIGIT
;; ======================================================================
;; process the units digit
          LD    R5, UNIT
          LD    R6, MINUSUNIT
          JSR   OUTDIGIT
;; ======================================================================
;; output
          LEA   R2, OUTBLK
          LDR   R0, R2, #0 ; load the sign
          TRAP  x21        ; OUT
          LDR   R0, R2, #1 ; load the hundreds digit
          TRAP  x21        ; OUT
          LDR   R0, R2, #2 ; load the tens digit
          TRAP  x21        ; OUT
          LDR   R0, R2, #3 ; load the units digit
          TRAP  x21        ; OUT
          TRAP  x25        ; stop the LC-2
;; ======================================================================
;; data
OUTBLK    .BLKW 4
VALUE     .FILL #347
PLUS      .FILL x2B
MINUS     .FILL x2D
HUN       .FILL #100
MINUSHUN  .FILL #-100
TEN       .FILL #10
MINUSTEN  .FILL #-10
UNIT      .FILL #1
MINUSUNIT .FILL #-1
ASCII     .FILL x30
;; ======================================================================
;; process digit subroutine
; R2 = pointer to OUTBLK
; R5 = BASE
; R6 = -BASE
          ;; process a digit
OUTDIGIT  AND   R0, R0, #0 ; clear the digit count
          ADD   R1, R1, R6 ; subtract BASE from R1
AGAIN     BRn   CORR       ; branch if negative to CORR
          ADD   R0, R0, #1 ; increment the digit count
          ADD   R1, R1, R6 ; subtract BASE from R1
          BRnzp AGAIN      ;

          ;; make correction to number
CORR      ADD   R1, R1, R5 ; number has been reduced by one digit

          ;; store the hundreds digit to output
          LD    R4, ASCII  ; load the ASCII template
          ADD   R0, R0, R4 ; add the ASCII template
          STR   R0, R2, #0 ; store the tens digit into OUTBLK
          RET              ;
          .END

Like the program shown in class, this program prints the sign of the number followed by the number itself. However, the program above doesn't output the characters properly. There is a bug. Can you find it? How can you fix the program?