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

The following LC-3 program compares two character strings of the same length. Th

ID: 3842917 • Letter: T

Question

The following LC-3 program compares two character strings of the same length. The source strings are in the .STRINGZ form. The first string starts at memory location x4000, and the second string starts at memory location x4100. If the strings are the same, the program terminates with the value 1 in R5; otherwise the program terminates with the value 0 in R5. Insert one instruction each at (a), (b), and (c) that will complete the program.. ORIG x3000 LD R1, FIRST LD R2, SECOND AND R0, R0, #0 LOOP ______;a LDR R4, R2 #0 BRz NEXT ADD R1, R1, #1 ADD R2, R2, #1 _____;(b) ______;(c) ADD R3, R3, R4 BRz LOOP AND R5, R5, #0 BRnzp DONE NEXT AND R5, R5, #0 ADD R5, R5, #1 DONE TRAP x25 FIRST .FILL x4000 SECOND .FILL 4100 END

Explanation / Answer

a - LDR R3, R1, #0
b - LDR R3, R1, #0
c - LDR R4, R2, #0

LOOP LDR R3, R1, #0 ;load first character of R1 in R3
LDR R4, R2 ,#0 ;load first character of R2 in R4
BRz NEXT ; goto NEXT if R3!=R4
ADD R1, R1, #1 ; Point R1 to next character
ADD R2, R2, #1 ; Point R2 to next character
LDR R3, R1, #0 ; load next character of R1 in R3
LDR R4, R2, #0 ; load next character of R2 in R4
ADD R3, R3, R4 ; R3 = R3+R4
BRz LOOP ; If R3!=0, Goto LOOP. R3 =R3+R4 = 0 means R3 =0 and R4 = 0; meaning if it is last of both the strings
AND R5, R5, #0 ; R5 = 0 , AND with 0 is always 0
BRnzp DONE ; goto DONE