我正在学习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我做错了什么?
发布于 2010-12-22 05:56:06
在看到代码here后,我最终弄明白了这一点。我必须首先创建一个字节,然后将寄存器的值存储到该字节中。然后通过打印该字节,我得到了ADD y,n,1的结果。
发布于 2020-09-25 02:48:41
罗伯特自己的回复中的链接被打破了。此外,解释也不令人满意。
主要的问题是在MMIX程序集中没有printf。所以你不能直接打印一个数字。需要将其转换为字符串,Fputs才能工作。
一旦你知道了这一点,解决方案就很容易了。挑战在于用MMIX对其进行编码。下面的程序处理一个无符号数字。
// 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// 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,0https://stackoverflow.com/questions/4503763
复制相似问题