LC-3 Program: Tracing the Execution

39 Views Asked by At

LC-3 program:

     .ORIG x3000
     LEA R1, DATA
LOOP LDR R2, R1, #0
     BRz DONE
NEXT ADD R1, R1, #2
     BRnzp LOOP
DONE HALT
DATA .STRINGZ "1234567"
     .END

I know the instruction labeled LOOP executes 5 times and the instruction labeled NEXT executes 4 times but I don't understand why.

When I trace the execution, I count the loop going through 7 iterations. Could someone explain how I can find the number of times the instructions at LOOP and NEXT execute?

1

There are 1 best solutions below

0
Tim Roberts On

It's because the instruction at NEXT is adding 2 to the pointer, not 1. You fetch every other digit, so you get 1, 3, 5, 7, and then the zero (assuming uninitialized memory is set to 0).