given hex input should be convert to decimal

78 views Asked by At

pretty new to assembly !!

My assembly code takes hex input which is 0-9 and a-f other inputs will result an error, every character of the input is stored in an array and every element in an array will be taken to print their integer value, but for some reason the elements address is printing. Please see the code below and give me solution for my problem. if you need the full code please let me know.

(The idea of below code is to take each element of hex number and print the elements in decimal number)

        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

Please resolve my problem. Many thanks.

1

There are 1 answers

0
kirkpatt On

Without knowing anything about the print_int procedure, I'd assume that one is the problem. Should just involve adding a couple of square brackets when pushing the register that has your value, assuming you are using printf.