在Mips中无法将十六进制转换为十进制

在Mips中无法将十六进制转换为十进制,mips,Mips,我在将给定的十六进制转换为十进制时遇到了问题 在此过程中,使用代码调用问题。我只是想 请参阅并理解将十六进制转换为十进制的代码 下面是问题的描述 描述:编写一个函数“hexint”,它接受 ascii字符串在$a0中的地址。 该字符串将表示中的一个数字 十六进制,将只包含“0”到“9” 和“A”到“F”。 返回寄存器$v0中的实际数字。 记住,最重要的一点是 将是字符串中的第一个 输出格式必须为: “数字为1960” 请尝试以下代码: .text main: #

我在将给定的十六进制转换为十进制时遇到了问题 在此过程中,使用代码调用问题。我只是想 请参阅并理解将十六进制转换为十进制的代码

下面是问题的描述

描述:编写一个函数“hexint”,它接受
ascii字符串在$a0中的地址。 该字符串将表示中的一个数字 十六进制,将只包含“0”到“9” 和“A”到“F”。 返回寄存器$v0中的实际数字。 记住,最重要的一点是 将是字符串中的第一个

输出格式必须为: “数字为1960”

请尝试以下代码:

        .text
    main:

    #Display ans String
    
    li $v0, 4
    la $a0, ans
    syscall

    #Store string from data and jump hexint
    la $a0, str
    jal hexint

    #Display modified string
    move $a0 , $v0
    li $v0, 1
    syscall

    la $a0, endl
    li $v0, 4
    syscall

    
    
    #End
    exit:   
    li $v0,10
    syscall
    

    #------------ start cut --------------------------

#the jal code here
    hexint:
        
        li $s3,0
        move $a2,$a0
        strlen:

        li $s0, 0 # initialize the count to zero
        strlen_loop:
            lb $t1, ($a0) # load the next character into t1
            beqz $t1, main_loop # check for the null character
            addi $a0, $a0, 1 # increment the string pointer
            addi $s0, $s0, 1 # increment the count
        j strlen_loop # return to the top of the loop
        
    
    main_loop:
        
        #move $s4,$s0
        move $t1,$s0
        subi $t1,$t1,1
    loop:
        
        li $s2,1
                        
        power_loop: 
            blt $t1,1,test   # if 
            mul $s2,$s2,16
            subi $t1,$t1,1
            
        j power_loop
        
        test:
            lb $t3,($a2)
            blt $t3,'A',is_digit   # if char less than 'A' => char is digit according to ascii table
           is_alpha:li $t5,0
            sub $t5,$t3,'A'
            la $a3,array       
            
            mul $t8,$t5,4
            add $a3,$a3,$t8
            lw $t6,($a3)
            j addition
        is_digit:
            andi $t6,$t3,0xf  # allows to convert string "7" to integer 7
        addition:
            mul $s4,$t6,$s2   
            add $s3,$s3,$s4
            addi $a2,$a2,1
            subi $s0,$s0,1
            beqz $s0,finished
            move $t1,$s0
            subi $t1,$t1,1
    j loop
    
    finished:
        move $v0,$s3
        jr $ra
    
    #------------ end cut ----------------------------
    
    

    .data
    str  :.asciiz "5D123"
    ans  :.asciiz " Number is : "
    endl :.asciiz " \n"
    array: .word 10,11,12,13,14,15 #

你能用C语言或伪代码来实现吗?欢迎使用!这是相当广泛的。你到底被困在哪里了?看见谢谢。我一直在关注从ascii/十六进制(7A8)到十进制(1960)的转换,这应该在底部的开始和结束切割段。我知道如何在纸上转换,但不是以代码格式转换。我在那个剪切区域根本看不到任何代码,所以为什么不尝试一下根据纸上算法实现代码(这是你可以发布的,以使问题更合理),然后如果你卡住了,问一个具体的问题。上面的链接说“首先,真诚地尝试自己解决问题。如果我们看不到您方面的足够工作,您的问题可能会被嘘下台;它将被否决并关闭。”以及“询问您现有实施中的具体问题”。谢谢,祝您好运。
        .text
    main:

    #Display ans String
    
    li $v0, 4
    la $a0, ans
    syscall

    #Store string from data and jump hexint
    la $a0, str
    jal hexint

    #Display modified string
    move $a0 , $v0
    li $v0, 1
    syscall

    la $a0, endl
    li $v0, 4
    syscall

    
    
    #End
    exit:   
    li $v0,10
    syscall
    

    #------------ start cut --------------------------

#the jal code here
    hexint:
        
        li $s3,0
        move $a2,$a0
        strlen:

        li $s0, 0 # initialize the count to zero
        strlen_loop:
            lb $t1, ($a0) # load the next character into t1
            beqz $t1, main_loop # check for the null character
            addi $a0, $a0, 1 # increment the string pointer
            addi $s0, $s0, 1 # increment the count
        j strlen_loop # return to the top of the loop
        
    
    main_loop:
        
        #move $s4,$s0
        move $t1,$s0
        subi $t1,$t1,1
    loop:
        
        li $s2,1
                        
        power_loop: 
            blt $t1,1,test   # if 
            mul $s2,$s2,16
            subi $t1,$t1,1
            
        j power_loop
        
        test:
            lb $t3,($a2)
            blt $t3,'A',is_digit   # if char less than 'A' => char is digit according to ascii table
           is_alpha:li $t5,0
            sub $t5,$t3,'A'
            la $a3,array       
            
            mul $t8,$t5,4
            add $a3,$a3,$t8
            lw $t6,($a3)
            j addition
        is_digit:
            andi $t6,$t3,0xf  # allows to convert string "7" to integer 7
        addition:
            mul $s4,$t6,$s2   
            add $s3,$s3,$s4
            addi $a2,$a2,1
            subi $s0,$s0,1
            beqz $s0,finished
            move $t1,$s0
            subi $t1,$t1,1
    j loop
    
    finished:
        move $v0,$s3
        jr $ra
    
    #------------ end cut ----------------------------
    
    

    .data
    str  :.asciiz "5D123"
    ans  :.asciiz " Number is : "
    endl :.asciiz " \n"
    array: .word 10,11,12,13,14,15 #