gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 04:49:16 25 4
gpt4 key购买 nike

我曾经以为我知道如何做到这一点。但后来我真的尝试这样做了。这是我编写的程序,但适用于 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com