我有一个赋值,我必须在MMIX中接受一个输入并返回完全相同的东西,除了所有的空格都必须是换行符。我已经尝试了大约2天了,我已经弄清楚了如何接受输入以及如何将其输出到控制台。但是第二部分我没读懂,作业明天就要交了。这是我到目前为止所知道的:
LOC Data_Segment % Sets data storage location
GREG @ % Reserves a new global register
Wordbuffer BYTE 0 % New Byte for incoming words
LOC Wordbuffer+5 % After the buffer
Arg OCTA Wordbuffer
OCTA 21 % Sets max word length
LOC #100 % Code section
Main LDA $255,Arg % Loads the buffer into the global register
TRAP 0,Fgets,StdIn % Gets input
LDA $255,Wordbuffer % Puts input in global register
TRAP 0,Fputs,StdOut % Prints inputted word
TRAP 0,Halt,0 % Stops program发布于 2021-04-22 04:33:50
我在对Fgets和Fput的调用之间插入了一个循环
也可以回复评论
// space_to_newline.mms
LOC Data_Segment % Sets data storage location
GREG @ % Reserves a new global register
Wordbuffer BYTE 0 % New Byte for incoming words
LOC Wordbuffer+5 % After the buffer
Arg OCTA Wordbuffer
OCTA 21 % Sets max word length
LOC #100 % Code section
Main LDA $255,Arg % Loads the buffer into the global register
TRAP 0,Fgets,StdIn % Gets input// loop over the string in Wordbuffer
// check if each character is a space
// replace with newline (0xa) if so
nl GREG #0a newline constant
LDA $0,Wordbuffer load base address
SET $1,0 initialize index to zero
0H LDBU $2,$0,$1 load byte in $2
BZ $2,2F done if null byte
CMP $255,$2,' ' check if space
PBNZ $255,1F skip character if not space
STBU nl,$0,$1 fallthru to replace with newline
1H INCL $1,1 increment index
JMP 0B loop back2H LDA $255,Wordbuffer % Puts input in global register
TRAP 0,Fputs,StdOut % Prints inputted word
TRAP 0,Halt,0 % Stops program使用mmix汇编器和模拟器进行测试
$ mmixal space_to_newline.mms
$ echo "abc defgh ijklm nopq" | mmix space_to_newline
abc
defgh
ijklm
nopqhttps://stackoverflow.com/questions/49386210
复制相似问题