MIPS: Storing a int as a string or char

2019-08-27 22:18发布

How would I go about changing an int to a String or Char?

I have to take a 8 bit 2sc binary string and convert it to a signed decimal. I have figure out how to convert the string to a decimal but I am not allowed to use the following syscalls to print: 1, 5, 12, 34, 35, and 30.

How would I store it to be able to print it using syscall 4 or 11?

My code below:

.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

标签: mips mars
0条回答
登录 后发表回答