0

我将如何将 int 更改为 String 或 Char?

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

我将如何存储它以便能够使用系统调用 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
4

0 回答 0