Question: Consider the following LC - 3 assembly language program: . ORIG x 3 0 0 0 L 1 LEA R 1 , L 1 AND

Consider the following LC-3 assembly language program:
.ORIG x3000
L1 LEA R1, L1
AND R2, R2, x00
ADD R2, R2, x02
LD R3, P1
L2 LDR R0, R1, x0C
OUT
ADD R3, R3, #-1
BRz GLUE
ADD R1, R1, R2
BR L2
GLUE HALT
P1.FILL x0B
.STRINGZ HBoeoakteSmtHaotren!s
.END
Assemble this program and load it into memory in the LC-3 simulator.
1a. What binary number is stored in memory location x3005? Your answer should be
in binary.
1b. What is the address of the instruction that is executed immediately after the
instruction at address x3005 is executed?
1c. What is the address of the instruction that is executed prior to the instruction at
address x3006?
1d. What is the output of this program?
1e. In 20 words or less, what does this program do?
2. The following specification, program, and discussion come from Example 9.1 of the
textbook.
Write a game program to do the following: A person is sitting at a keyboard. Each
time the person types a capital letter, the program outputs the lowercase version of
that letter. If the person types a 7, the program terminates.
The following LC-3 assembly language program will do the job.
.ORIG x3000
LD R2, TERM ; Load -7
LD R3, ASCII ; Load ASCII difference
AGAIN TRAP x23 ; Request keyboard input
ADD R1, R2, R0 ; Test for terminating character
BRz EXIT
ADD R0, R0, R3 ; Change to lowercase
TRAP x21 ; Output to the monitor
BRnzp AGAIN ; ... and do it again!
TERM .FILL xFFC9 ; FFC9 is negative of ASCII 7
ASCII .FILL x0020 ; ASCII upper/lower difference
EXIT TRAP x25 ; Halt
.END
The program executes as follows: The program first loads constants xFFC9 and x0020
into R2 and R3. The constant xFFC9, which is the negative of the ASCII code for 7,
is used to test the character typed at the keyboard to see if the user wants to continue
playing. The constant x0020 is the zero-extended difference between the ASCII code
for a capital letter and the ASCII code for that same letters lowercase representation.
For example, the ASCII code for A is x41 and the ASCII code for a is x61. The ASCII
codes for Z and z are x5A and x7A, respectively.
Then TRAP x23 is executed, it invokes the keyboard input service routine. When the
service routine is finished, control returns to the application program, and R0 now
contains the ASCII code of the character typed. The ADD and BRz instructions test
for the terminating character 7. If the character typed is not 7, the ASCII
uppercase/lowercase difference (x0020) is added to the input ASCII code, storing the
result in R0. Then a TRAP to the monitor output service routine is called. This causes
the lowercase representation of the same letter to be displayed on the monitor. When
control returns to the application program, an unconditional BR to AGAIN is
executed, and another request for keyboard input appears.
The correct operation of this program assumes that the person sitting at the keyboard
only types capital letters or the character 7. But what if the person types something
else, like a lowercase letter, or the character $? A better program would test the
character typed to be sure it really is a capital letter from among the 26 capital letters
in the English alphabet, and if it is not, it would take appropriate corrective action.
Your job: Augment this program to add a test for bad data. In other words, modify
this program so that it will not only produce the lowercase letter for any uppercase
letter typed, but will also be able to tell when an invalid character is typed and then
respond appropriately.
3. Assume that an integer greater than 2 and less than 32,768 is deposited in memory
location A by another module before the program below is executed.
.ORIG x3000
AND R4, R4, #0
LD R0, A
NOT R5, R0
ADD R5, R5, #2
ADD R1, R4, #2
;
REMOD JSR MOD
BRz STORE0
;
ADD R7, R1, R5
BRz STORE1
ADD R1, R1, #1
BR REMOD
;
STORE1 ADD R4, R4, #1
STORE0 ST R4, RESULT
TRAP x25
;
MOD ADD R2, R0, #0
NOT R3, R1
ADD R3, R3, #1
DEC ADD R2, R2, R3
BRp DEC
RET
;
A .BLKW #1
RESULT .BLKW #1
.END
In 20 words or fewer, what does the above program do?
4. The program below, when complete, should print the following to the monitor:
ABCFGH
Insert instructions at (a)-(d) that will complete the program.
.ORIG x3000
LEA R1, TESTOUT
BACK_1 LDR R0, R1, #0
BRz NEXT_1
TRAP x21
------------(a)
BRnzp BACK_1
;
NEXT_1 LEA R1, TESTOUT
BACK_2 LDR R0, R1, #0
BRz NEXT_2
JSR SUB_1
ADD R1, R1, #1
BRnzp BACK_2
;
NEXT_2------------(b)
;
SUB_1------------(c)
K LDI R2, DSR
------------(d)
STI R0, DDR
RET
DSR .FILL XFE04
DDR .FILL XFE06
TESTOUT .STRINGZ ABC
.END
5. Describe and explain the Trap Vector Table.
6. We might see code at the beginning and end of a TRAP service routine that looks
like this:
ST R1, SaveR1
ST R2, SaveR2
.
.
LD R1, SaveR1
LD R2, SaveR2
Explain.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!