I need to write a program (on emu8086), which would convert hexadecimal number into decimal number. I have to do it until tomorrow, but I don't know where to start. Please, someone, help me to write that program. :'(:

Recommended Answers

All 2 Replies

format PE GUI 4.0

include 'win32a.inc'

        mov     esi,shex
        mov     ecx,0
        cmp     byte [esi],0
        je      mGotoEndEx
        inc     esi
        inc     ecx
        jmp     mGotoEnd
        dec     esi

        mov     edx,0
        mov     ebx,1
        mov     eax,0
        mov     al,[esi]
        mov     ah,'0'
        cmp     al,'A'
        jl      mDigit
        mov     ah,'A'-10
        sub     al,ah
        mov     ah,0

        push    edx
        mul     ebx
        pop     edx
        add     edx,eax

        mov     eax,16
        push    edx
        mul     ebx
        pop     edx
        mov     ebx,eax

        dec     esi
        loop    mConvertToNumber

        mov     edi,sdec
        push    edi
        mov     eax,edx
        mov     ecx,0
        mov     edx,0
        mov     ebx,10
        div     ebx
        mov     byte [edi],dl
        add     byte [edi],'0'
        inc     ecx
        cmp     eax,0
        je      mConvertToDecEx
        inc     edi
        jmp     mConvertToDec

        pop     edi
        mov     esi,edi
        mov     edx,0
        mov     eax,ecx
        mov     ebx,2
        div     ebx
        add     esi,ecx
        dec     esi
        mov     ecx,eax
        mov     al,[esi]
        xchg    [edi],al
        mov     [esi],al
        inc     edi
        dec     esi
        loop    mBackOrder

        invoke  ExitProcess,0

shex    db '499602D2',0;positive hexadecimal CAPITALS
sdec    db 256 dup(?);decimal (should be 1234567890)

data import

        library kernel32,'KERNEL32.DLL'

        import  kernel32,\

end data

Each hex digit represents a nibble.

Subtract 48 from the ASCII value, is it less than or equal to 9?
If so shift it into the proper nibble. If not subtract
65 'A' or 97 'a' from the original value and add ten and
shift into the proper nibble.

[ Digits are ascii values (in hex) 30 to 39h.
41 'A' - 41 = 0 add 10 because A = 10 in hex,
also 42 'B' - 41 = 1 + 10 = 11 or B in hex. ]

So that:
/ \
1010 1000

To convert to decimal divide by powers of ten,
the quotient should yield the digit (0-9) of the corresponding
place value.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.