Friday 3 February 2012

Binary to Decimal converter- Masm program


printmsg macro msg
mov ah,09h
lea dx,msg
int 21h
endm

printnum macro reg
mov dl,reg
add dl,30h
mov ah,02h
int 21h
endm

calcnum macro regx
mov ax,regx
mov dh,100
div dh
mov num,ah
aam
mov dh,al
printnum ah
printnum dh
mov al,num
aam
mov dh,al
printnum ah
printnum dh
endm

multiply macro num1
mov ax,0001
mov dh,02
mov dl,00
l10:
cmp dl,num1
jz l9
mul dh
inc dl
jmp l10
l9:
endm

data segment
num dw ?
num1 db 0

array db 10 dup(0)

cr equ 0dh
msg1 db "Enter a binary number$"
msg2 db 0ah,0dh,"Decimal Equivalant$"

msg4 db 0ah,"$"
data ends

code segment
assume cs:code,ds:data
start:
mov ax,data
mov ds,ax
mov cl,00


printmsg msg1
lea si,array
mov bx,si

printmsg msg4

l2:mov ah,01h
int 21h
cmp al,cr
je l1
sub al,30h
mov [si],al
inc si
inc cl
jmp l2

l1:mov bx,0000
mov si,offset array

l5:

cmp cl,00
jne l6
jmp l7
l6:

multiply cl
mov dh,[si]
mul dh
add bx,ax
inc si
dec cl
jmp l5

l7:
printmsg msg4
printmsg msg2

printmsg msg4
mov ax,bx
mov dh,02
 div dh
mov ah,00
calcnum ax

mov ah,4ch
int 21h
code ends
end start






0 comments:

Post a Comment

Twitter Delicious Facebook Digg Stumbleupon Favorites More