lc 3 – A Better Understanding of LC-3 – Branch Loop to Stop When Encountering a Negative


Im going to start with that im trying to do.

Change this program to loop until it encounters a sentinel value, which is a negative number. The data begins at x3100. Use only one branch command. There will always be at least one positive integer in the list. No count controlled loop.

When the program ends, R2 must contain the number of values summed and R3 must contain the sum of those values.

.ORIG x3000

AND R3, R3, #0

AND R2, R2, #0

ADD R2, R2, #12

BRz #5

LDR R4, R1, #0

ADD  R3, R3, R4

ADD R1, R1, #1

ADD R2, R2, #-1

BRnzp #-6

.END

My textbook along with the professor are not being of much help so i came here to try a get a better understanding.

I know I can remove/get rid of the other two Branch Loop commands as I need only one, but I do not know how to structure that loop and getting R2 and R3 to work, it just seems they want to stay at 0.

EDIT: That was because i did not run it, i only opened it in the simulator.

I’m also not sure how i can just skip from x3000 to x3100 to fill data being provided from this loop.