Problem: Write an 8086 ALP to Convert Decimal number to Hexadecimal number.
Title: Code for Assembly Language Program to Convert Decimal number to Hexadecimal number in Assembly Language
Description: This 8086 ALP takes decimal number as input from the user, checks if the number inputted is valid decimal number, if the number is valid decimal, the ALP converts Decimal number to Hexadecimal number and prints equivalent Hexadecimal number. If the number given by user is not a valid decimal numbers the it prints the message “Invalid decimal number”

8086 ALP to Convert Decimal to Hexadecimal number

This 8086 ALP also uses macro definition, in this ALP is defined as macro, so that the code inside this macro can be used repeatedly.
prntstr macro msg       ;defining macro prntstr
        mov ah, 09h
        lea dx, msg
        int 21h
        endm

data segment
        buf1 db "Enter a decimal number : $"
        buf2 db 0ah, "Invalid Decimal Number...$"
        buf3 db 0ah, "Equivalent hexadecimal number is : $"
        buf4 db 6
             db 0
             db 6 dup(0)
        multiplier db 0ah
data ends

code segment
        assume cs:code, ds:data
start :
        mov ax, data
        mov ds, ax
        mov es, ax

        prntstr buf1

        mov ah, 0ah
        lea dx, buf4
        int 21h

        mov si, offset buf4 + 2
        mov cl, byte ptr [si-1]
        mov ch, 00h
subtract :
        mov al, byte ptr [si]
        cmp al, 30h
        jnb cont1
        prntstr buf2
        jmp stop
cont1 :
        cmp al, 3ah
        jb cont2
        prnstr buf2
        jmp stop
cont2 :
        sub al, 30h
        mov byte ptr [si], al

        inc si
        loop subtract

        mov si, offset buf4 + 2
        mov cl, byte ptr [si-1]
        mov ch, 00h
        mov ax, 0000h
calc :
        mul multiplier
        mov bl, byte ptr [si]
        mov bh, 00h
        add ax, bx
        inc si
        loop calc

        mov si, offset buf4 + 2
        mov bx, ax
        mov dx, 0000h
        mov ax, 1000h
convert :
        mov cx, 0000h
conv :
        cmp bx, ax
        jb cont3
        sub bx, ax
        inc cx
        jmp conv
cont3 :
        cmp cx, 0ah
        jb cont4
        add cl, 37h
        jmp cont5
cont4 :
        add cl, 30h
cont5 :
        mov byte ptr [si], cl
        inc si
        mov cx, 0010h
        div cx
        cmp ax, 0000h
        jnz convert

        mov byte ptr [si], '$' 
        prntstr buf3
        prntstr buf4+2
stop :
        mov ax, 4c00h
        int 21h
code ends
        end start