LC-3如何在ASCII中产生打印?

发布于 2025-01-25 13:25:17 字数 594 浏览 0 评论 0原文

我的任务是创建一个分区子例程,该子例程将散布的数字将是甚至。这个数字需要除以两个。 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

早茶月光 2025-02-01 13:25:17

检查是否可以在汇编中均匀排除2,

以查看是否可以将数字除以2,您只需要检查第一个位即可。为此,公正并用1来检查结果。

    AND R0, 1

在组装中除以2

除以2,只需移出最低的数字即可。

    SHR R0, 1

编辑:

我知道您现在对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.

    AND R0, 1

Dividing by 2 in Assembly

To divide by 2, simply shift out the lowest digit.

    SHR R0, 1

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文