Question: Leap Year in Assembly : Design and write an assembly code that will determine if a given year is a Leap Year. x86 nasm on
Leap Year in Assembly : Design and write an assembly code that will determine if a given year is a Leap Year.
x86 nasm on gl server (64 bit linux)
A year is a leap year if it is divisible by 4 and not divisible by 100, unless it is also divisible by 400.
My code isn't working (segmentation fault) and I'm not sure how to fix it. Thank you
My code so far:
section .data msg db "Please enter a 4 digit year: " len equ $ - msg leapYearmsg db "is a leap year.", 10 leapYearLength equ $-leapYearmsg NoLeapYear db " is not a leap year.", 10 noLeapYearLength equ $-NoLeapYear section .bss year resb 5 intYear resb 5 section .text global _start: print: ; defining function print mov ebx, 1 ; file descriptor (stdout) mov eax, 4 ; system call number (sys_write) int 0x80 ; call kernel ret ; return back _start: mov eax, 4 ; print out msg mov ebx, 1 mov ecx, msg mov edx, len int 0x80 mov eax, 3 ; read in number and enter key mov ebx, 0 mov ecx, year mov edx, 6 int 0x80 mov eax, 4 ; print out year mov ebx, 1 int 0x80 mov eax, [year] ;convert first digit sub eax, '0' mov ebx, '10' mul ebx mov [intYear], eax mov eax, [year+1] ; convert second digit sub eax, '0' mov ebx, '10' mul ebx mov [intYear], eax mov eax, [year+2] ; convert third digit sub eax, '0' mov ebx, '10' mul ebx mov [intYear], eax mov eax, [year+3] ; convert third digit sub eax, '0' mov ebx, '10' mul ebx mov [intYear], eax mov edx, 0 mov eax, [intYear] mov ebx, 4h div ebx cmp ah, 0x0 jne NoLeapYear ;// je L1 L1: mov edx, 0 mov eax, ecx mov ebx, 64h div ebx mov eax, edx cmp eax, 0 je L2 jne LeapYear L2: mov edx, 0 mov eax, ecx mov ebx, 190h div ebx mov eax, edx cmp eax, 0 je leapYearmsg jne NoLeapYear LeapYear: mov eax, 4 mov ebx, 1 mov ecx, leapYearmsg mov edx, leapYearLength int 0x80 jmp Exit Exit: mov eax, 1 mov ebx, 0 int 0x80
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
