How to avoid executing variables in lc3 assembly

1k views Asked by At

I am making my first steps in lc3 assembly programming and I noticed that every time I try to store a negative value in memory, for example using "ST" instruction, there is some kind of error. In this memory location is stored "TRAP xFF" instead... Anybody know how can I get over it??

1

There are 1 answers

2
Chris M On

You're getting that error because your variables are apart of the run-time code. It's usually best practice to put your variables at the end of your code after the HALT command.

.ORIG x3000

MAIN    
LD R0, VAR1
NOT R0, R0
ADD R0, R0, #1
ST R0, VAR2

HALT

VAR1 .FILL #5
VAR2 .FILL #0
.END

The reason you were getting those errors is because when you were storing numbers into your variables the simulator thought they were commands. The trap command has an opcode of 1111 which also a negative number. When the simulator ran into your variable it couldn't figure out what type of TRAP command it was, thus the error. By preventing the simulator from running your variables you won't get that error.