Reputation: 1
I'm using an LC3 microarchitecture simulator to write assembly code. I've only been writing assembly for about three weeks, so I am still very new.
My goal is to print all the numbers leading up to a set value, so for example, if the user selects '6' the console prints 012345
My code works, but the unit test says my code is inefficient or has an infinite loop.
I set the value by manually setting R1 in my simulator to any value, the rest is automated with the code. Starting at 0x3000
LD, R0, X3001 ;Load R0 with 0
0 ;I did this b/c I don't know how to load a register with ascii values
AND R2, R2, #0 ; Set R2=0
NOT R3, R1 ;invert R1, store in R3
ADD R3, R3, #1 ;Add 1 to R3, now R3=-R1
ADD R4, R0, R3 ; better way to perform loop? added these to maintain loop
BRz X300b ; if previous math ever produces 0, skip to halt
OUT ; print single char
ADD R0, R0, #1 ; R0++
ADD R1, R1 #-1 ; R1--
BRnzp X3006 ;Always branch back to the above BR instruction
HALT
Hex:
3000
2000
0030
54a0
967f
16e1
1803
0404
f021
1021
127f
0ffb
f025
So my question is, is there any way to make this more efficient?
Upvotes: 0
Views: 245