首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >打印寄存器中包含的数字

打印寄存器中包含的数字
EN

Stack Overflow用户
提问于 2010-12-22 04:48:28
回答 2查看 320关注 0票数 2

我正在学习MMIX,所以我试着编写一个简单的程序来给自己加一个,然后打印结果。不幸的是,它不打印任何东西。下面是我的程序:

代码语言:javascript
复制
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

我做错了什么?

EN

回答 2

Stack Overflow用户

发布于 2010-12-22 05:56:06

在看到代码here后,我最终弄明白了这一点。我必须首先创建一个字节,然后将寄存器的值存储到该字节中。然后通过打印该字节,我得到了ADD y,n,1的结果。

票数 2
EN

Stack Overflow用户

发布于 2020-09-25 02:48:41

罗伯特自己的回复中的链接被打破了。此外,解释也不令人满意。

主要的问题是在MMIX程序集中没有printf。所以你不能直接打印一个数字。需要将其转换为字符串,Fputs才能工作。

一旦你知道了这一点,解决方案就很容易了。挑战在于用MMIX对其进行编码。下面的程序处理一个无符号数字。

代码语言:javascript
复制
// printnum.mms
// run with MMIX simulator or visual debugger: https://mmix.cs.hm.edu

n        IS $4
y        IS $3
t        IS $255

// a register for extracting a digit
digit    IS $5
// a 16-byte buffer for the converted string
buf      OCTA 0

         LOC #100
Main     SET n,1 %let n = 1
         ADD y,n,1 %add 1 to n and store the result in y
代码语言:javascript
复制
// convert y to ascii digits and store in buf

         GETA t,buf+16
// divide and set digit to the remainder register rR
1H       DIV y,y,10
         GET digit,rR
// convert digit to ascii character
         INCL digit,'0'
// fill buffer from the end
         SUB t,t,1
         STBU digit,t,0
// loop back to 1H for more digits
         PBNZ y,1B

// print the converted string
// this works because string offset is already in register $255
         TRAP 0,Fputs,StdOut

         TRAP 0,Halt,0
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/4503763

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档