Question

Please write it in 80X86 assembly langauge Leap Year The month of February normally has 28...

Please write it in 80X86 assembly langauge

Leap Year

The month of February normally has 28 days. But if it is a leap year, February has

29 days. Write a program that asks the user to enter a year. The program should

then display the number of days in February that year. Use the following criteria to

identify leap years:

Determine whether the year is divisible by 100.

If it is, then it is a leap year if and if only it is also divisible by 400. For

example, 2000 is a leap year but 2100 is not.

If the year is not divisible by 100, then it is a leap year if and if only it is

divisible by 4. For example, 2008 is a leap year but 2009 is not.

my code

.586
.MODEL FLAT
INCLUDE io.h ;header file
.STACK 4096

header file start

; IO.H -- header file for I/O macros (listing suppressed)
.NOLIST ; turn off listing

; 32-bit version with windows I/O
; must be used with project framework defining showOutput and getInput
; R. Detmer October 2007
.586
EXTRN _getInput:NEAR32, _showOutput:NEAR32, atodproc:NEAR32, dtoaproc:NEAR32, wtoaproc:NEAR32, atowproc:NEAR32


dtoa MACRO dest,source ; convert double to ASCII string
push ebx ; save EBX
lea ebx, dest ; destination address
push ebx ; destination parameter
mov ebx, [esp+4] ; in case source was EBX
mov ebx, source ; source value
push ebx ; source parameter
call dtoaproc ; call dtoaproc(source,dest)
add esp, 8 ; remove parameters
pop ebx ; restore EBX
ENDM

atod MACRO source ; convert ASCII string to integer in EAX
lea eax,source ; source address to AX
push eax ; source parameter on stack
call atodproc ; call atodproc(source)
add esp, 4 ; remove parameter
ENDM

wtoa MACRO dest,source ; convert word to ASCII string
push ebx ; save EBX
lea ebx,dest ; destination address
push ebx ; destination parameter
mov ebx, [esp+4] ; in case source was BX
mov bx, source ; source value
push ebx ; source parameter
call wtoaproc ; call dtoaproc(source,dest)
add esp, 8 ; remove parameters
pop ebx ; restore EBX
ENDM

atow MACRO source ; convert ASCII string to integer in AX
lea eax,source ; source address to AX
push eax ; source parameter on stack
call atowproc ; call atodproc(source)
add esp, 4 ; remove parameter
ENDM

output MACRO outLbl, outStr ; display label and string

pushad ; save general registers
cld ; clear DF
lea eax,outStr ; string address
push eax ; string parameter on stack
lea eax,outLbl ; label address
push eax ; string parameter on stack
call _showOutput ; showOutput(outLbl, outStr)
add esp, 8 ; remove parameters
popad ; restore general registers
ENDM

input MACRO inPrompt, inStr, maxLength ; prompt for and input string
   pushad ; save general registers
mov ebx, maxLength ; length of input string
push ebx ; length parameter on stack
lea ebx,inStr ; destination address
push ebx ; dest parameter on stack
lea ebx,inPrompt ; prompt address
push ebx ; prompt parameter on stack
call _getInput ; getInput(inPrompt, inStr, maxLength)
           add esp, 12 ; remove parameters
popad ; restore general registers
ENDM

.NOLISTMACRO ; suppress macro expansion listings
.LIST ; begin listing
header file end

0 0
Add a comment Improve this question Transcribed image text
Answer #1

section .data

   msg db 'Enter a year ' , 10

   msglen equ $-msg

   leapYear db ' is a leap year.', 10
   leapYearLenght equ $-leapYear
   noLeapYear db ' is not a leap year.', 10
   noLeapYearLenght equ $-noLeapYear
   section .bss

   year resd 1

   section .text

   global main

main:

   mov eax,4
   mov ebx, 0
   mov ecx, msg
   mov edx, msglen
   int 0x80

   mov eax, 3
   mov ebx, 0
   mov ecx, year
   mov edx, 4
   int 0x80

   mov eax, 4
   mov ebx, 1
   int 0x80

   mov edx, 0
   mov eax, ecx
   mov ebx, 4h
   div ebx    ; step 3
   mov eax, edx
   cmp eax, 0
   jne NoLeapYear
   je L1

L1:
   mov edx, 0

   mov eax, ecx

   mov ebx, 64h

   div ebx    ; step 2

   mov eax, edx

   cmp eax, 0

   je L2

   jne LeapYear

L2:

   mov edx, 0

   mov eax, ecx

   mov ebx, 190h

   div ebx    ;step 1

   mov eax, edx

   cmp eax, 0

   je LeapYear

   jne NoLeapYear

LeapYear:      ; step4

   mov eax, 4

   mov ebx, 1

   mov ecx, leapYear

   mov edx, leapYearLenght

   int 0x80

   jmp Exit

NoLeapYear:      ; step 5

   mov eax, 4

   mov ebx, 1

   mov ecx, noLeapYear

   mov edx, noLeapYearLenght

   int 0x80

   jmp Exit
Exit:

   mov eax, 1

   mov ebx, 0

   int 0x80

Add a comment
Know the answer?
Add Answer to:
Please write it in 80X86 assembly langauge Leap Year The month of February normally has 28...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT