打印寄存器中包含的数字
我正在学习 MMIX,所以我尝试制作一个简单的程序来向自身添加一个并打印结果。不幸的是它不打印任何东西。这是我的程序:
n IS $4
y IS $3
t IS $255
LOC #100
Main SET n,1 %let n = 1
ADD y,n,1 %add 1 to n and store the result in y
LDA t,y
TRAP 0,Fputs,StdOut
TRAP 0,Halt,0
我做错了什么?
I'm learning MMIX so I tried making a simple program to add one to itself and print the result. Unfortunately it doesn't print anything. Here is my program:
n IS $4
y IS $3
t IS $255
LOC #100
Main SET n,1 %let n = 1
ADD y,n,1 %add 1 to n and store the result in y
LDA t,y
TRAP 0,Fputs,StdOut
TRAP 0,Halt,0
What am I doing wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在看到代码此处后,我最终弄清楚了。我必须首先创建一个字节,然后将寄存器的值存储到该字节中。然后通过打印该字节,我得到 ADD y,n,1 的结果。
I ended up figuring it out after seeing the code here. I had to first create a byte, then store the value of the register into the byte. Then by printing out that byte, I get the result of ADD y,n,1.
罗伯特自己的回复中的链接已损坏。对此的解释也并不令人满意。
主要问题是 MMIX 程序集中没有
printf
。所以你不能直接打印一个数字。需要将其转换为字符串才能使 Fputs 正常工作。一旦你知道了这一点,解决方案就很容易了。挑战在于在 MMIX 中对其进行编码。下面的程序处理一个无符号数。
The link in Robert's own response is broken. Also the explanation is unsatisfactory.
The main issue is there is no
printf
in MMIX assembly. So you can't just print a number directly. It needs to be converted to a string forFputs
to work.Once you know this the solution is easy. The challenge is to code it in MMIX. The program below handles one unsigned number.