string - Mips如何存储用户输入字符串

标签 string mips spim

我曾经以为我知道如何做到这一点。但后来我真的尝试这样做了。这是我编写的程序,但适用于 mac 的 Berkeley S*** 模拟器说最后一行存在语法错误。我做错了什么?

       .text
       .globl __start
    __start:
        la $a0,ask
        li $v0,4
        syscall

        li $v0,8
        syscall

        la $t0,buffer
        move $t0,$v0
        syscall

        la $a0,ret
        li $v0,4
        syscall

        move $a0,$t0
        li $v0,4
        syscall

        .data
      ask:  .asciiz "Enter string: "
      ret:  .asciiz "You wrote: "
      buffer:   .space 100

最佳答案

好的。从年初开始,我发现了一个深藏在其他文件中的程序,它可以满足我的需求。我无法真正评论所提供的建议,因为我不是经验丰富的垃圾邮件或低级程序员。这里是:

         .text
         .globl __start
    __start:
         la $a0,str1 #Load and print string asking for string
         li $v0,4
         syscall

         li $v0,8 #take in input
         la $a0, buffer #load byte space into address
         li $a1, 20 # allot the byte space for string
         move $t0,$a0 #save string to t0
         syscall

         la $a0,str2 #load and print "you wrote" string
         li $v0,4
         syscall

         la $a0, buffer #reload byte space to primary address
         move $a0,$t0 # primary address = t0 address (load pointer)
         li $v0,4 # print string
         syscall

         li $v0,10 #end program
         syscall


               .data
             buffer: .space 20
             str1:  .asciiz "Enter string(max 20 chars): "
             str2:  .asciiz "You wrote:\n"
             ###############################
             #Output:
             #Enter string(max 20 chars): qwerty 123
             #You wrote:
             #qwerty 123
             #Enter string(max 20 chars):   new world oreddeYou wrote:
             #  new world oredde //lol special character
             ###############################

关于string - Mips如何存储用户输入字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7969565/

相关文章:

java - 如何检查正在循环的字符串的最后一个索引

mysql - MySQL 中文本列表的长度(基本字符串操作)

c - SPIM(MIPS 模拟器)无法解析以下语句 lui $2,%hi($LC0)

assembly - 样本垃圾邮件代码

assembly - 计算偏移量

c++ - 检查字符串是否包含 vector<string> 值的有效方法?

c - 为什么在 c 中动态分配时会出现段错误?

assembly - 如何为 Nintendo 64 构建 Hello World?

assembly - 为了流水线,实际的 Intel x86 处理器有多少开销?

assembly - 我们如何在汇编代码 (MIPS) 中取消引用指针?