2017-04-14 138 views
2

我真的需要這個幫助。我正在嘗試創建一個將所有小寫轉換爲上部的函數。 例如:「大家好!」 - >「大家好MIPS:小寫字母

這是我迄今爲止(我知道這是不是很多,但我只是不知道如何從搬到這裏,一直試圖小時)

to_upper: 
    #PSEUDOCODE: 
    # load byte 
    # send to the ASCII-function 
    # check if the ASCII is a upper or lower 
    # store/save is somewhere - if upper 
    # if lower, subtract 20 in hexadecimal and then store it together with the other upper 
    # print back 

    #### MY CODE: 
la $t0, STR_str 
j check_if_upper 

check_if_upper: 
lb $t1, 0($t0) 
ble $t1, 96, is_upper 
j is_lower 

is_upper: 

is_lower: 

exit_to_upper: 
jr $ra 

回答

1

我希望下面的代碼對你的作品我用了MARS MIPS simulator

.data 
input: .space 20 
newline: .asciiz "\n" 

.text 
main: 
    li $v0, 8 
    li $a1, 20 
    la $a0, input 
    syscall 

    li $v0, 4 
    li $t0, 0 

loop: 
    lb $t1, input($t0) 
    beq $t1, 0, exit 
    blt $t1, 'a', case 
    bgt $t1, 'z', case 
    sub $t1, $t1, 32 
    sb $t1, input($t0) 

case: 
    addi $t0, $t0, 1 
    j loop 

exit: 
    li $v0, 4 
    la $a0, input 
    syscall 

    li $v0, 10 
    syscall 

測試

mips lowercase 
MIPS LOWERCASE 
+0

完美太謝謝你了。!d – Aewend