user2837048
user2837048

Reputation: 139

LC-3 left-shift and store left-shifted bits

I am working on the following code to left shift the value in R0 - which I am sure will work. Also, as R0 is left-shifted, the value of the bit which gets removed should be stored in R2. I am not sure if what I am doing is correct for this.

Also, MASK .FILL x8000 does not seem to work. My LC-3 simulator returns an error. It states "invalid instruction. RTI executed with user mode privilege."

.ORIG x3000

LD R0 X
AND R2 R2 0
LD R3 MASK 
LD R1 N
BRZ done
loop
AND R2 R0 R3 ;store leftmost digit of R0 into R2
ADD R0 R0 R0 ;left shift R0
ADD R1 R1 -1 
BRP loop
done .FILL x0000

MASK .FILL x8000
X .FILL xFFFF
N .FILL 5 ;amount of times of leftshifts
.END

Upvotes: 1

Views: 4197

Answers (1)

Layman
Layman

Reputation: 11

If you look at the Opcode for RTI: 1000 0000 0000 0000

It is identical to the value stored by "MASK .FILL X8000": 1000 0000 0000 0000

You haven't put a HALT instruction on anywhere before MASK, so the program will continue to run through MASK, X and N. When it runs through MASK, it thinks you are trying to use the RTI instruction because they have equivalent values.

Upvotes: 1

Related Questions