首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >MMIX更改输入中的字符

MMIX更改输入中的字符
EN

Stack Overflow用户
提问于 2018-03-20 21:56:50
回答 1查看 137关注 0票数 0

我有一个赋值,我必须在MMIX中接受一个输入并返回完全相同的东西,除了所有的空格都必须是换行符。我已经尝试了大约2天了,我已经弄清楚了如何接受输入以及如何将其输出到控制台。但是第二部分我没读懂,作业明天就要交了。这是我到目前为止所知道的:

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

回答 1

Stack Overflow用户

发布于 2021-04-22 04:33:50

我在对Fgets和Fput的调用之间插入了一个循环

也可以回复评论

  • Data_Segment是一个固定地址-可写数据在MMIX内存中的起始地址-
  • Fgets返回读取的字节数或-1 -字符串is null-terminated
  • LOC #100 (0x100)通常是主程序启动的位置-特殊的中断处理程序可以放在较低的地址中

代码语言:javascript
复制
// 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
代码语言:javascript
复制
// 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 back
代码语言:javascript
复制
2H            LDA     $255,Wordbuffer  % Puts input in global register
              TRAP    0,Fputs,StdOut   % Prints inputted word
              TRAP    0,Halt,0         % Stops program

使用mmix汇编器和模拟器进行测试

代码语言:javascript
复制
$ mmixal space_to_newline.mms
$ echo "abc defgh ijklm nopq" | mmix space_to_newline
abc
defgh
ijklm
nopq
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/49386210

复制
相关文章

相似问题

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