For this problem we are given a problem in LC-3 and told to describe what it does and state what is contained in RESULT. Unfortunately, I am struggling hardcore with this language and I am really confused by it. I just don't understand what these different things are for. Here is the code.
.ORIG x3000
LD R2, ZERO
LD R0, M0
LD R1, M1
LOOP BRz DONE
ADD R2, R2, R0
ADD R1, R1, -1
BR LOOP
DONE ST R2, RESULT
HALT
RESULT .FILL x0000
ZERO .FILL x0000
MO .FILL x0004
M1 .FILL x0803
.END
I don't even know where to begin. Like, what is ".ORIG x3000"? I think x3000 is a memory location? If that's the case, then down at the bottom where it says ".FILL ..." aren't those memory locations too? Or are those numbers that you are filling into a register? I am confused.
So I THINK the second line loads whatever is in ZERO into register R2? Then M0 is loaded into R0, followed by M1 being loaded into R1? I am confused on what is being loaded. Are we loading values, or are we just placing memory addresses into registers? After all the LD instructions, we come to a loop. I think the BRz means to go back up an re-iterate through the loop as long as R1 is not 0? So, I guess R1 is our loop control element? R2 is being added to whatever is in R0 and the result is being stored in R2. After the loop ends, then RESULT is stored into R2?
What does DONE signal? I thought if you wanted to exit a loop, you would instruct the computer to HALT which is the line right after it. So why have DONE followed by HALT?
The last few lines I assume are initializations? Like, filling RESULT with x0000. What is x0000? Is it a memory location, or is a it a number?
Can someone help explain this to me and maybe guide me on what happens when this program is run?
I'm sorry if this is a lot at once. I am struggling big time and don't know where to even begin.