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
Problem 2
Refer to Figure 9.6 of the textbook, the halt service routine.
Problem 3
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:
Problem 6
Consider the following LC-2 assembly language program:
.ORIG x3000Assuming 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?
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
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 x3000Like 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?
;; 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