Click here to Skip to main content
15,742,303 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
When running this code, every year I put in, the output comes back as "This is a leap Year" when in fact some of the strings are not leap years.

Can someone help find the logic mistake?

What I have tried:

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
Posted
Updated 6-Dec-21 21:02pm
v2
Comments
jeron1 6-Dec-16 15:57pm    
Can you single step it using a debugger?
C-P-User-3 6-Dec-16 21:58pm    
Here is your Number One error: You are not commenting your code.

Edit this source, with a useful comment on EACH AND EVERY instruction and...

* You will immediately find your own error
* If not, I am confident that others will find it quickly


Really, drop me a message after adding adquate comments and I'll be happy to take a second look at it.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900