Assembly 使用mips替换字符串的特定字符

Assembly 使用mips替换字符串的特定字符,assembly,mips,Assembly,Mips,我试图用mips替换字符串的特定字符。程序就像用户需要输入限制为40个字符的字符串一样,程序需要询问用户是否要替换字符串中的任何字符。在我的代码中,我只能打印一个字符,以下是我的代码: .data prompt0: .asciiz " Please Enter any String :" prompt:.asciiz "\n Your current string is: " prompt1:.asciiz "\n Do you want to make any changes to the s

我试图用mips替换字符串的特定字符。程序就像用户需要输入限制为40个字符的字符串一样,程序需要询问用户是否要替换字符串中的任何字符。在我的代码中,我只能打印一个字符,以下是我的代码:

.data
prompt0: .asciiz " Please Enter any String :"
prompt:.asciiz "\n Your current string is: "
prompt1:.asciiz "\n Do you want to make any changes to the string? (y/n): " 
prompt2: .asciiz "\n Please Enter the Character that you want to Search for :"
prompt3: .asciiz "\n Please Enter the New Character :  "
prompt4: .asciiz "\n Your Final string is: "
 yes: .asciiz "y"
 No :.asciiz "n"
 Buffer: .space 40
.text
 li $v0, 4
 la $a0, prompt0
 syscall 

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

li $v0,4
la $a0,prompt        # load and print "you wrote" string
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



Loop:
    # Ask if user want to chnge rthe string or not
li $v0, 4     # syscall 4 (print_str)
la $a0, prompt1  # argument: string
syscall

     # GET INPUT FROM USER
li   $v0, 8   # get input
la   $a0, Buffer    # load byte space into address
li   $a1, 2         # allot the byte space for string
 move $t0,$a0        # save string to t0
syscall
#EDIT
lb $t1, yes  
lb $t0, 0($t0)   

#END EDIT

bne $t0, $t1, Exit

#IF YES, PRINT MESSAGE
li $v0,4
la $a0,prompt2
syscall


li $v0, 8   #get input
la $a0, Buffer  #load byte space into address
li $a1, 2      # allot the byte space for string
sw $t0,($a0)    #save string to t0
syscall

li $v0,4
la $a0,prompt3
syscall

li $v0, 8   #get input
la $a0, Buffer  #load byte space into address
li $a1, 2      # allot the byte space for string
move $t0,$a0    #save string to t0
syscall


la $a0,prompt     #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
j Loop


 Exit:

li $v0,10       #end program
syscall 
     jr $ra     
这是我要转换为mips的C程序:

#包括
#包括
int main()
{
char-str[40],ch,Newch;
int i;
printf(“\n请输入任何字符串:”);
获取(str);
printf(“\n请输入要搜索的字符:”;
scanf(“%c”和“ch”);
getchar();
printf(“\n请输入新字符:”);
scanf(“%c”和&Newch);

for(i=0;ifor循环转换为汇编,如下所示:

for ( initializer; condition; increment ) {
    body
}
LoopTop:
    if ( ! condition ) goto ExitTheLoop;
    body
    increment
    goto LoopTop;
ExitTheLoop:
首先,将其转换为C中的while循环:

initializer;
while ( condition ) {
    body
    increment
}
接下来,将while转换为assembly,如下所示:

for ( initializer; condition; increment ) {
    body
}
LoopTop:
    if ( ! condition ) goto ExitTheLoop;
    body
    increment
    goto LoopTop;
ExitTheLoop:


打印部分很简单,只需打印每个单独的组件,每个组件都有自己的系统调用。打印语句将分解为打印一个常量字符串,后跟一个变量字符,后跟一个常量字符串,另一个变量字符,常量字符串,翻译后的字符串,最后是一个空格或常量字符串占用一个空格:总共7个单独的系统调用。

我投票将这个问题作为离题题题结束,因为没有问题,只有一些不完整的代码。@ErikEidt请将您的标记更改为
需要清晰的详细信息
,因为这就是“没有问题,只有一些代码”的意思@SzymonMaszke我的问题是如何替换字符串中的字符并打印更改后的字符串。@ErikEidt我提到过我可以替换字符,但不能替换字符串和打印之间的字符,所以我需要帮助。好的,让我们来分析一下。要么你需要算法方面的帮助,要么你需要算法方面的帮助rithm你已经知道了,在汇编中。如果是前者,那么这显然不是一个汇编问题,你的问题应该是关于这个(一个算法)。如果是后者,那么你需要向我们展示你的C算法,以及你在汇编中无法完成的C代码中的什么构造,你的问题应该是关于这一点。“我需要帮助”或“我不知道怎么做”——做作业——不是有效的问题。(事实证明,它们根本不是问题;)