如何在MIPS / MARS中反转之前添加/打印用户输入

问题描述

这是我在火星上的代码。它要求一个名称并将其取反。示例输出

输入您的姓名(格式为“第一名”):arya stark 反向是:斯塔克,阿里亚 -程序运行完毕(从底部移出)-

我想说: 输入您的姓名(格式为“第一名”):arya stark 艾莉亚·斯塔克反向是:斯塔克,艾莉亚 -程序运行完毕(从底部移出)-

我该怎么做?

############################ data segment ################################
.data
promptuser: .asciiz "Enter your name (format 'FirsT LAST'): "
putComma:   .asciiz "," #prompt for string
userinput:  .space 400 #string that user enters
reverse:    .asciiz " reversed is : " #prompt for string
############################ code segment ################################ 
.text 
.globl main

main: 
    li $v0,4
    la $a0,promptuser  #prints a srting prompt to the user 
    syscall
    
    li $v0,8
    la $a0,userinput   #asks the user to enter name
    li $a1,100
    syscall
    
    move $s0,$a0        #move data to s0
    move $s1,$a1
    li $v0,reverse     #prompt to reverse
    syscall

    move $s1,$s0
loop: 
    #loop while end of string
    lb $a0,0($s0)      #load first character to a0
    addi $s0,$s0,1    #add index by one
    beq $a0,$zero,exit    #else print character
    beq $a0,32,exitLoop   #if current character is space go to loop
    j loop

exitLoop:

loopprint: 
    lb $a0,0($s0)          #load first character to a0
    addi $s0,1        #add index by one
    beq $a0,printOtherStr   #else print character
    beq $a0,10,printOtherStr  #else print character
    beq $a0,exit       #if current character is space go to loop
    li $v0,11
    syscall
    j loopprint

printOtherStr:
    li $v0,putComma    #padding comma to name
    syscall

printOther:
    lb $a0,0($s1)      #load first character to a0
    addi $s1,$s1,exit   #if current character is space go to loop
    li $v0,11
    syscall
    j printOther 
    
    exit:

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)