.ORIG x3000
COUNTER .FILL x0005
LEA R0, HELLO_WORLD
PUTS
HALT
HELLO_WORLD .stringz "Hello World this is John Cena!"
.END
This is the code I have so far for just writing the name once, I'm confused how to implement the loop into this code so that the name will be displayed 5 times.
The best way to accomplish this is to use the equivalent of a for-loop. Our loop limit variable has to be inverted using 2's complement, this gives us -5. We then add our loop count to -5 to see if they equal 0. If zero, then jump out of the for-loop.
Printing Hello World! 5 Times using a loop:
Good Luck on your assignments and learning LC-3 Assembly Language! :D
I think using a do while loop is a lot easier on the LC3 machine. And a whole lot of less coding too.
The reason I set the counter to 6 is it actually gets decremented before the loop actually starts, so when the loop starts it's actually 5. The reason why I did it is because BR instruction is tied to the last register you fiddled with. If you want to set it to 0, just change the line that has ADD R1, R1, #6 into ADD R1, R1, #5. Change the loop into this.
Hope this helps!