The data at memory address x3500 is a bit vector with each bit representing whet
ID: 3842918 • Letter: T
Question
The data at memory address x3500 is a bit vector with each bit representing whether a certain power plant in the area is generating electricity (bit = 1) or not (bit = 0). The program counts the number of power plants that generate electricity and stores the result at x3501. However, the program contains a mistake that prevents it from correctly counting the number of electricity generating (operational) power plants. Identify it and explain how to fix it. .ORIG x3000 AND R0, R0, #0 LD R1, NUMBITS LDI R2, VECTOR. ADD R3, R0, #1 CHECK AND R4, R2, R3 BRz NOTOPER ADD R0, R0, #1 NOTOPER ADD R3, R3, R3 ADD R1, R1, # -1 BRp CHECK STR R0, R1, #1 TRAP x25 NUMBITS .FILL #16 VECTOR. FILL x3500 .ENDExplanation / Answer
ORIG x3000
AND R0, R0, #0
LD R1, NUMBITS
LDI R2, VECTOR
ADD R3, R0, #1
CHECK AND R4, R2, R3
BRz NOTOPER
ADD R0, R0, #1
NOTOPER ADD R3, R3, R3
ADD R1, R1, #-1
BRp CHECK
LD R2, VECTOR <- missing instruction
STR R0, R2, #1
TRAP x25
NUMBITS .FILL #16
VECTOR .FILL x3500
.END
R2 contains the bit vector, and not the address at which the bit vector is contained.
The instruction LDI R2, VECTOR loaded the value at x3500 into R2 since the value at the memory address labeled as VECTOR was used as the
address from which to load. The store instruction STR R0, R2, #1 uses the value of R2 to evaluate an address.
However, R2 must be modified to contain an address for an STR instruction to work. Thus, LD R2, VECTOR is an additional required instruction.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.