Mips,十六进制转换为二进制

时间:2018-11-15 20:40:26

标签: assembly low-level mips32

我一直在尝试在mips程序集中进行一些转换,以尝试将十六进制转换为二进制,但是我不确定如何实现。这是与转换相关的代码片段

    .data


operand: .asciiz "\nEnter correct value to be converted: "
result: .asciiz "\nYour result is: "
hexstore: .space 8

.globl main

.text
main:

li $v0, 4   #display welcome message
la $a0, welcome
syscall

li $v0, 5   #get int for type of operation
syscall

move $t0, $v0  #store result in t0, now compare t0 to t1 in order to get a branching result

addi $t1, $zero, 0 #set t1 to 0
addi $t1, $t1, 1 #set t1 to 1
beq $t0, $t1, hexatobinary #jump to hextobinary if t0 is 1
hexatobinary:

la $a0, operand     #prompt for input
    li $v0, 4
    syscall

    li $v0, 5       #integer input
    syscall
    add $t0, $v0, $zero #Move to t0

    addi $t1, $zero, 0

    sw $t0, hexstore($t1)

因此,我的思维过程几乎是存储用户输入的十六进制值,然后尝试在for循环中一次读取一位,并通过16个分支将正确的二进制值放入寄存器中,然后在循环完成之后我将打印寄存器,转换将完成。这是正确的实现吗?我实际上需要什么代码?我可以通过相同的过程将二进制转换为十六进制吗?谢谢!

0 个答案:

没有答案
相关问题