如何解决想在更改后在内存中打印原始值
.globl main
.text
# The label 'main' represents the starting point
main:
li $v0,4 # print_string syscall code = 4
la $a0,theString # load the address of msg
syscall
li $v0,newLine # load the address of msg
syscall
jal capitalize # call capitalize procedure
# syscall to print value
li $v0,4
move $a0,$t2
syscall
li $v0,newLine # load the address of msg
syscall
li $v0,theString # load the address of msg
syscall
li $v0,10 # Sets $v0 to "10" to select exit syscall
syscall # Exit
capitalize:
li $t0,0
la $t2,theString
loopString:
lb $t1,theString($t0) # load the char
beq $t1,finishLoop # If done with iteration of string finish loop
bgt $t1,'z',notLetter # checks if char is not between 'a' and 'z'
blt $t1,'a',notLetter
sub $t1,$t1,32 # subtracts 32 from lowercase letter to get uppercase
sb $t1,theString($t0) # saves back the char
notLetter:
# increments char loop by one
addi $t0,$t0,1
j loopString
finishLoop:
jr $ra
.data
theString: .asciiz "test"
newLine: .asciiz "\n"
目前正在打印
test
TEST
TEST
但是,我很难让它看起来像
test
test
TEST
原始字符串打印两次的地方。我想知道是否有任何技巧可以解决这个问题?我曾经考虑过堆栈分配,但在尝试之后我一直遇到不同的问题。
解决方法
.globl main
.text
# The label 'main' represents the starting point
main:
li $v0,4 # print_string syscall code = 4
la $a0,theString # load the address of msg
syscall
li $v0,newLine # load the address of msg
syscall
jal capitalize # call capitalize procedure
# syscall to print value
li $v0,4
la $a0,oldString
syscall
li $v0,newLine # load the address of msg
syscall
li $v0,theString # load the address of msg
syscall
li $v0,10 # Sets $v0 to "10" to select exit syscall
syscall # Exit
capitalize:
li $t0,0
la $t2,theString
loopString:
lb $t1,theString($t0) # load the char
beq $t1,finishLoop # If done with iteration of string finish loop
bgt $t1,'z',notLetter # checks if char is not between 'a' and 'z'
blt $t1,'a',notLetter
sub $t1,$t1,32 # subtracts 32 from lowercase letter to get uppercase
sb $t1,theString($t0) # saves back the char
notLetter:
# increments char loop by one
addi $t0,$t0,1
j loopString
finishLoop:
jr $ra
.data
oldString: .asciiz "test"
theString: .asciiz "test"
newLine: .asciiz "\n"
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。