MIPS: Storing a int as a string or char

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-11 19:03:52

问题


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

来源:https://stackoverflow.com/questions/54958883/mips-storing-a-int-as-a-string-or-char

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!