Using NASM, using jz, cmp, flags, loops also use the register 32 bit Task: Desig
ID: 3588316 • Letter: U
Question
Using NASM, using jz, cmp, flags, loops also use the register 32 bit Task:
Design and write an assembly code that will determine if a given year is a Leap Year. Things to consider
How to change a string of numbers into its numerical counterpart o Helpful Hit:
Take a 4-digit string
Get the thousands digit
Multiply by 10
Add the hundred’s digit
Multiply by 10 etc.….
What defines a leap year A year is a leap year if it is divisible by 4 and not divisible by 100, unless it is also divisible by 400
. Would any loops (jmp to self), or if else statements (je or jne) that would be useful Loop: ~~~~ Code ~~~~ jmp Loop Compares: cmp ~x~, ~y~ je ~~something~~ jne ~~something else sample output : Type Year: 2000 This year is a leap year type Year: 2005 This year is not a leapy year
Explanation / Answer
Assembly code for whether the given year is Leap Year or not?
assume ds:data1,cs:code1
data1 segment
msg db 0ah,0dh,'Enter the year$'
number db 6,0,6 dup('$')
ys db 0ah,0dh,'yes,It is a Leap Year$'
n db 0ah,0dh,'no,It is not a Leap Year$'
data1 ends
code1 segment
start:mov ax,seg data1
mov ds,axlea dx,msg
mov ah,09h
int 21hlea dx,number
mov ah,0ah
int 21h
lea bx,number+4
mov ah,[bx]
mov al,[bx+1]
aad
mov bl,04h
div bl
and ah,0ffh
jz yes
lea dx,n
mov ah,09h
int 21h
jmp down
yes:lea dx,ys
mov ah,09h
int 21h
down: mov ah,4ch