Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In the code below the Subroutine ONECHAR takes 1 character from the user (keyboa

ID: 3850844 • Letter: I

Question

In the code below the Subroutine ONECHAR takes 1 character from the user (keyboard) and saves it into the memory. The assembly code uses ONECHAR in a loop 6 times to input 6 characters and saves it to the memory. Finally it prints the string to the screen. a. Line 6 saves R0 before calling the subroutine ONECHAR. Briefly explain why this is necessary. b. What other register needs to be stored and restored inside the subroutine [Fill in lines 17, 19]. c. Once the subroutine is done, we have to restore registers. In line 8, fill in the register restored. What is pushed on the supervisor stack when an interrupt is serviced?

Explanation / Answer

1;CODE TO INPUT AND PRINT 6 CHARACTERS
2 .ORIG x3000
3 AND R0, R0, #0 ;
4 LOOP LEA R1, INPSTRING ;
5 ADD R1, R1, R0 ;
6 ST R0, SAVEREG1 ;
7 JSR ONECHAR ;
8 LD _(R0)_, SAVEREG1 ;
9 ADD R0, R0, #1 ;
10 LD R1, LENGTH ;
11 ADD R1, R1, R0 ;
12 BRn LOOP ;
13 LEA R0, INPSTRING ;
14 PUTS ;
15 TRAP X22 And print
16 HALT ;
17 ONECHAR ST _(R7)_, SAVEREG2 ;
18 GETC ;
19 LD _(R7)_, SAVEREG2 ;
20 STR R0, R1, #0 ;
21 RET


LENGTH . FILL xFFFA
KBSR . FILL xFE00
KBDR . FILL xFE02
SAVEREG1 .FILL x0
SAVEREG2 .FILL x0
INPSTRING .BLKW 6
END

a) Line 6 saves R0 before calling the subroutine ONECHAR. Briefly explain why this is
necessary.
ans) R0 is modified/used by GETC call in ONECHAR subroutine.

b) What other register needs to be stored and restored inside the subroutine [Fill in lines 17,
19].
ans) R7 needs to be stored


c) Once the subroutine is done, we will have to restore the registers. In line 8 Fill in the register restored

ans) R0