$24
(15 pts ) Write an LC-3 assembly language program that counts the number of 1s in the value stored in R0 and stores the result in R1. For example, if R0 contains 0001001101110000, then R1 should store the value 6.
(10 pts) The following program adds the values stored in memory locations A, B and C, and stores the result into memory. There are two errors in the code. For each, describe the error and indicate whether it will be detected at assembly time or run time.
1.
.ORIG x3000
2.
ONE
LD R0, A
3.
ADD R1, R1, R0
4.
TWO
LD R0, B
5.
ADD R1, R1, R0
6.
THREE
LD R0, C
7.
ADD R1,R1,R0
8.
ST R1, SUM
9.
HALT
10.
A
.FILL x0001
11.
B
.FILL x0002
12.
C
.FILL x0003
13.
D
.FILL x0004
14. .END
(5 pts) Name some of the advantages of doing I/O through a TRAP routine instead of writing the routine yourself each time you would like your program to perform I/O.
(5 pts)
How many trap service routines can be implemented in the LC-3? Why?
How many accesses to memory are made during the processing of a TRAP instruction?
5. (20 pts) Consider the following LC-3 assembly language program:
1)
.ORIG x3000
2)
L1
LEA R1, L1
3)
AND R2, R2, 0
4)
ADD R2, R2, 2
5)
LD R3, P1
6)
L2
LDR R0, R1, xC
7)
OUT
8)
ADD R3, R3, -1
9)
BRz GLUE
ADD R1, R1, R2
BR L2
GLUEHALT
13) P1 .FILL xB
.STRINGZ “HBoeoakteSmtHaotren!s”
.END
After this program has run, what binary pattern is stored in memory location x3005?
Which instruction (provide a memory address) is executed after instruction x3005 is executed?
Which instruction (provide a memory address) is executed prior to instruction x3006
What is the output of this program?
(30 pts) Perform the following multiplications in 4-bit 2SC and provide both the binary and decimal answers.
5 x 6
-6 x 4
2 x 6
-3 x -2
-8 x 7