Friday, 19 September 2014

Decimal Number to Binary

.model small
printmsg macro msg
        push ax
        push dx
        lea dx,msg
        mov ah,09h
        int 21h
        pop dx
        pop ax
endm
.data
        msg1 db 0ah,0dh,"Enter Decimal:$"
        msg2 db 0ah,0dh,"Binary is:$"
        cnt dw 0
        num dw 0
        a dw 0
.code
        mov ax,@data
        mov ds,ax
        printmsg msg1
        call readnum
  mov bx,num
        mov cx,10h
    l7: mov ax,bx
        and ax,0001
        shr bx,01
        add al,30h
        push ax
        inc cnt
        loop l7
        mov cx,cnt
        printmsg msg2
     l8:pop ax
        mov dl,al
        mov ah,02h
        int 21h
        loop l8
    ext:mov ah,4ch
        int 21h


 readnum proc near
                push ax
                push bx
                push cx
                push dx
                mov num,00h
                next1:
                        mov ah,01h
                        int 21h
                        cmp al,0dh
                        je next2
                        sub al,30h
                        mov cx,ax
                        and cx,00ffh
                        mov ax,num
                        mov bx,10
                        mul bx
                        mov num,ax
                        add num,cx
                        jmp next1
                next2:
                        pop dx
                        pop cx
                        pop bx
                        pop ax
                        ret
                        readnum endp
     
end




                 

Convert Hexa Decimal to Binary


masm code to convert binary number to Decimal....