作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
所以我现在正在做一个项目,我们必须接受一个字符串并将其转换为所有大写字母,然后如果 toUpper 或 toLower 字节不是 0 则转换为小写字母。现在我还在工作在大写部分(猜测小写几乎相同)但是当我遍历字符串以查找大写字母或调用系统调用进行打印时,我被卡住了。任何帮助都会很棒。这是我到目前为止所拥有的:
.data
toUpper: .byte 1
toLower: .byte 0
string:
.asciiz " A long time ago in a Galaxy far, far away...."
# Your code goes below this line
origString:
.asciiz "Original string:\n"
toUpForwardStr:
.asciiz "\nConverted to upper-case:\nForward:\n"
toLowerForwardStr:
.asciiz "\nConverted to lower-case:\nForward:\n"
backwardStr:
.asciiz "Backward:"
.text
main:
# Function prologue
subu $sp, $sp, 24 # allocate stack space -- default of 24 here
sw $fp, 0($sp) # save caller's frame pointer
sw $ra, 4($sp) # save return address
addiu $fp, $sp, 20 # setup main's frame pointer
la $a0, origString #Print "Original String:"
addi $v0, $zero, 4
syscall
la $a0, string #Print string
addi $v0, $zero, 4
syscall
la $s0, toUpper
sb $s1, 0($s0) #toUpper stored in $s1
la $s0, toLower
sb $s2, 0($s0) #toLower stored in $s2
bne $s1, $zero, toUpperCase #Jump toUpperCase if toUpper ≠ 0
toUpperCase:
la $a0, toUpForwardStr #Print "Converted to upper-case:"
addi $v0, $zero, 4 # "Forward:"
syscall
la $s3, string #$s3 holds address to string
addi $s1, $zero, 0 #$s1 = i = 0
j upperCaseLoop #Goto upperCaseLoop
upperCaseLoop:
# Compute address of string[i]
add $t2, $s3, $s1 # $t2 = address of string[i]
lb $t3, 8($t2) # $t3 = elements[i]
beq $t3, $zero, upperDone # test if for loop is done
addi $t6, $zero, 96 #$t6 = 96 (lowercase letters)
bgt $t3, $t6, isLowercase1#If letter is lowercase goto isLowercase1
comeBackFromLowercaseIfs:
move $t3, $a0
addi $v0, $zero, 11
syscall
addi $s1, $s1, 1 # i++
j upperCaseLoop
upperDone:
bne $s2, $zero, toLowerCase #Jump toLowerCase if toLower ≠ 0
toLowerCase:
la $a0, toLowerForwardStr #Print "Converted to lower-case:"
addi $v0, $zero, 4 # "Forward:"
syscall
j done #The END!!
isLowercase1:
addi $t7, $zero, 123 #$t7 = 123
blt $t3, $t7, isLowercase2 #Goto isLowercase2
j comeBackFromLowercaseIfs #Go back to uppercaseLoop
isLowercase2:
addi $t3, $zero, -30 #changes letter to lowercase
j comeBackFromLowercaseIfs #Go back to uppercaseLoop
done:
# Epilogue for main -- restore stack & frame pointers and return
lw $ra, 4($sp) # get return address from stack
lw $fp, 0($sp) # restore the caller's frame pointer
addiu $sp, $sp, 24 # restore the caller's stack pointer
jr $ra # return to caller's code
最佳答案
1 这个
move $t3, $a0
应该是
move $a0, $t3
2 这个
lb $t3, 8($t2)
应该是
lb $t3, 0($t2)
3 这个
addi $t3, $zero, -30 #changes letter to lowercase
应该是
addi $t3, $t3, -32 #changes letter to lowercase
关于string - 如何在 mips 程序集中迭代字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12739463/
我是一名优秀的程序员,十分优秀!