LC-3如何在ASCII中产生打印?
我的任务是创建一个分区子例程,该子例程将散布的数字将是甚至。这个数字需要除以两个。 r1是结果寄存器(N / 2的结果),R0是N。我的以下代码经过数字196进行了测试,我们应该期望结果为98,但是,我的结果是“ 196 /2 =ü8 ”。以下是我的印刷代码。
AND R1, R1, #0. ; Clearing Result reg that could hold values from prior exectutions.
LOOP ADD R0, R0, #-1
ADD R0, R0, #-1 ; Subtracting #1 twice from R0 to divide by two.
ADD R1, R1, #1 ;+1 to R1 for every time R0 can be divided by two, expected to + 98
BRp LOOP ; Loop As Long as R0 Does not = Z or N
RET
编辑,它有效!!!以下是编辑的子例程!
AND R1, R1, #0
LOOP ADD R1, R1, #1
ADD R0, R0, #-2
BRp LOOP
RET
My task is to create a division subroutine that infers that the number that will be divided will be even. This number needs to be divided by two. R1 is the result register (result of N/2), and R0 is the N. My following code is tested with the number 196, we should expect the result to be 98, however, my result printed is "196 / 2 = ü8". The following below is my printed code.
AND R1, R1, #0. ; Clearing Result reg that could hold values from prior exectutions.
LOOP ADD R0, R0, #-1
ADD R0, R0, #-1 ; Subtracting #1 twice from R0 to divide by two.
ADD R1, R1, #1 ;+1 to R1 for every time R0 can be divided by two, expected to + 98
BRp LOOP ; Loop As Long as R0 Does not = Z or N
RET
EDIT, IT WORKS!!! BELOW IS THE EDITED SUBROUTINE!!
AND R1, R1, #0
LOOP ADD R1, R1, #1
ADD R0, R0, #-2
BRp LOOP
RET
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
检查是否可以在汇编中均匀排除2,
以查看是否可以将数字除以2,您只需要检查第一个位即可。为此,公正并用1来检查结果。
在组装中除以2
除以2,只需移出最低的数字即可。
编辑:
我知道您现在对LC-3的实现感兴趣。您的实现看起来正确。由于您不显示打印代码,因此可能是一个问题。您可以通过将输出寄存器设置为已知的即时值(例如98),然后再尝试,确保打印功能正常工作。
Checking if Evenly Divisible by 2 in Assembly
To see if the number can be divided by 2 evenly you just need to check the first bit. To do that, just AND with 1 and check the result.
Dividing by 2 in Assembly
To divide by 2, simply shift out the lowest digit.
Edit:
I realize now you're interested in an implementation for LC-3. Your implementation looks correct. Since you don't show the printing code it might be an issue there. You can ensure that your print function is working correctly by setting your output register to some known immediate value (such as 98) then trying again.