MIPS:从大写到大写

时间:2017-04-14 17:59:49

标签: assembly 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 个答案:

答案 0 :(得分:2)

我希望以下代码适合您。我使用了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