MIPS:将int存储为字符串或char

时间:2019-03-02 13:12:43

标签: mips mars

如何将int更改为String或Char?

我必须采用8位2sc二进制字符串并将其转换为带符号的十进制。 我已经弄清楚如何将字符串转换为十进制,但不允许使用以下系统调用来打印:1、5、12、34、35和30。

我将如何存储它以便能够使用syscall 4或11打印?

我的下面的代码:

.text
        addi $t7 $zero 0        # int $t7 = 0

        lw $s1, ($a1)   # Loads the address of the first argument
                        # Argument example: 0b11111110

        lb $t0, 2($s1)  # Loads 3rd char of Argument1 to $t1
        bne $t0, 0x31, step2
        addi $t7 $t7 -128

        step2:
        lb $t0, 3($s1)  # Loads 4th char of Argument1 to $t1
        bne $t0, 0x31, step3
        addi $t7 $t7 64

        step3:
        lb $t0, 4($s1)  # Loads 5d char of Argument1 to $t1
        bne $t0, 0x31, step4
        addi $t7 $t7 32

        step4:
        lb $t0, 5($s1)  # Loads 6th char of Argument1 to $t1
        bne $t0, 0x31, step5
        addi $t7 $t7 16

        step5:
        lb $t0, 6($s1)  # Loads 7th char of Argument1 to $t1
        bne $t0, 0x31, step6
        addi $t7 $t7 8

        step6:
        lb $t0, 7($s1)  # Loads 8th char of Argument1 to $t1
        bne $t0, 0x31, step7
        addi $t7 $t7 4

        step7:
        lb $t0, 8($s1)  # Loads 9th char of Argument1 to $t1
        bne $t0, 0x31, step8
        addi $t7 $t7 2

        step8:
        lb $t0, 9($s1)  # Loads 10th char of Argument1 to $t1
        bne $t0, 0x31, step9
        addi $t7 $t7 1

        step9:
        li $v0 1
        add $a0 $zero $t7
        syscall

0 个答案:

没有答案