给定的十六进制输入应转换为十进制

时间:2015-06-13 00:18:52

标签: assembly x86 nasm

对装配很新!!

我的汇编代码采用十六进制输入,即0-9,其他输入将导致错误,输入的每个字符都存储在一个数组中,并且数组中的每个元素都将被用来打印它们的整数值,但是元素地址的一些原因是打印。 请参阅下面的代码并给我解决我的问题。如果您需要完整的代码,请告诉我。

(以下代码的思想是采用十六进制数的每个元素并以十进制数字打印元素)

        mov     ebx, array              

next_loop:                              ;this loop is to convert the character

        mov     al, [ebx]
        cmp     al, NEWLINE        ; here NEWLINE is 10 which is already defined
        je      end_loop          

        cmp     al, 97            
        jge     subblock
        jl      numsub

numsub:
        sub     al, 48
        mov     [ebx], al
        jmp     next

subblock:
        sub     al, 97
        add     al, 10
        mov     [ebx], al
        jmp     next

next:
        inc     ebx
        loop    next_loop

; below code is to print the value which is stored in array


end_loop:
        mov     ebx, array
        mov     eax, message2
        call    print_string

print_loop:
        mov     al, [ebx]
        inc     ebx
        call    print_int      ; addresses of ebx is printing but not the value
        cmp     al, NEWLINE
        jne     print_loop         
        jmp     finalend

请解决我的问题。 非常感谢。

1 个答案:

答案 0 :(得分:0)

在不了解print_int程序的情况下,我假设一个是问题所在。假设您正在使用printf,那么在推送具有您的值的寄存器时,只需要添加几个方括号。