HALT
只是用于停止机器的 TRAP 指令的“伪指令”。
你可以写:
TRAP x25 ;HALT the machine
但这样就需要记住TRAP向量中的位置,本例中x25
。所以最好只使用HALT
反而。
其他常见的TRAP也有伪指令:IN
, OUT
, etc.
我假设您想将结果存储在某个地方。你可以这样做:
;Sets pc to this address at start of program
.ORIG x3000
;R1 will store the result lets clear it(ANd with 0)
AND R1,R1,x0
;R2 will be multiplied by R3, let's clear both of them
AND R2,R2,x0
AND R3,R3,x0
;Test case 4 * 3 = 12;
ADD R2,R2,4
ADD R3,R3,3
;Add to increment zone
LOOP Add R1,R1,R2;
;Decrement the counter, in this case the 3 or R3
ADD R3,R3,x-1
BrP LOOP
ST R1, Result ;STORE R1 at Result
HALT
Result .FILL x0000 ;this will be x000C=12h after execution
.END
- - - - - - - - - - -编辑 - - - - - - - - - - - - -
关于你的最后一个问题(在评论中):
如果 HALT 停止我的程序,Reslt .FILL x0000 指令将如何运行
然后?
这更多的是关于汇编程序如何工作的问题。
答案是因为:组装时间 != 执行时间处理时间
指令在大会时考虑。
事实上,装配时间由两遍组成:
- 解析符号创建符号表
- 使用符号表将指令转换为“真正可执行/机器代码”。
这是实现汇编器的一种非常常见的方法,LC3 汇编器也不例外。