如何避免在LC3汇编中执行变量 [英] How to avoid executing variables in lc3 assembly

查看:137
本文介绍了如何避免在LC3汇编中执行变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在进行lc3汇编编程的第一步,我注意到每次尝试在内存中存储负值(例如使用"ST"指令)时,都会出现某种错误.而是在此存储位置中存储"TRAP xFF". 有人知道我该怎么克服吗?

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??

推荐答案

由于该变量是运行时代码的一部分,因此会出现此错误.通常最好的做法是将变量放在HALT命令后的代码末尾.

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

出现这些错误的原因是,当您将数字存储到变量中时,模拟器认为它们是命令. trap命令的操作码为1111,也为负数.当模拟器遇到您的变量时,它无法确定它是什么类型的TRAP命令,因此会出错.通过阻止模拟器运行变量,您将不会得到该错误.

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.

这篇关于如何避免在LC3汇编中执行变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆