Thursday, 2 February 2012

Fibonacci series-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


data segment
num dw 0
a dw 0000
b dw ?

regx dw ?
msg1 db "Enter a non zero limit(Ex: 05)$"
msg2 db 0ah,0dh,"Fibnocci series $"
msg3 db 0ah,"$"
msg5 db 0ah,0dh,"Try again$"
data ends

code segment
assume cs:code,ds:data

start:
mov ax,data
mov ds,ax
printmsg msg1
mov ah,01h
int 21h
sub al,30h
mov ah,00
mov dh,10
mul dh
mov num,ax
mov ah,01h
int 21h
sub al,30h
mov ah,00
add ax,num


mov cx,ax
cmp cx,0000
je p1
jmp p2
p1:
printmsg msg5
mov ah,4ch
int 21h
jmp l5
p2:cmp cx,0001
je l9
jmp l7
l9:
printmsg msg3
printmsg msg2
calcnum a
mov ah,4ch
int 21h
jmp l5



l7:
mov bx,0001
cmp cx,0002
je l6
jmp l4
l6:printmsg msg3
printmsg msg2
calcnum a
printmsg msg3
calcnum bx
mov ah,4ch
int 21h
jmp l5

l4:
mov bx,0001
printmsg msg3
printmsg msg2
calcnum a
printmsg msg3
calcnum bx
sub cx,0002
l1:
printmsg msg3
mov dx,a
add dx,bx
mov b,dx
calcnum dx
mov dx,b
mov a,bx
mov bx,dx
dec cx
cmp cx,0000
jne l1


l5:
code ends
end start




0 comments:

Post a Comment

Twitter Delicious Facebook Digg Stumbleupon Favorites More