Wednesday, 7 March 2012

Masm program to check a given year is leap year or not


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

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

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

endm

data segment
n db,0000
n1 db ,0000
msg1 db 0ah,0dh,"Enter a year$"
msg2 db 0ah,0dh,"Leap year$"
msg3 db 0ah,0dh,"Not leap year$"
msg4 db 0ah,0dh,"$"
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 cx,1000
mul cx
mov n,ax

mov ah,01h
int 21h
sub al,30h
mov ah,00
mov cx,100
mul cx
add ax,n
mov n,ax

mov ah,01h
int 21h
sub al,30h
mov ah,00
mov cl,10
mul cl
add ax,n
mov n,ax

mov ah,01h
int 21h
sub al,30h
mov ah,00
add ax,n
mov n,ax

mov cx,0004
mov dx,0000
mov ax,n
div cx

cmp dx,0000
je t1
jmp t3
t1:
mov cx,0100
mov dx,0000
mov ax,n
div cx

cmp dx,0000
jne t2
jmp t3
t2:
printmsg msg2
jmp st1
t3:
mov ax,n
mov bx,400
div bx
cmp dx,0000
je t2

printmsg msg3



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

0 comments:

Post a Comment

Twitter Delicious Facebook Digg Stumbleupon Favorites More