TIP: Click on subject to list as thread! ANSI
echo: public_domain
to: All
from: rowan_crowe
date: 1996-01-19 05:55:00
subject: leapyear.asm

; LEAPYEAR.ASM

; Public domain code by Rowan Crowe, 3:635/727.1{at}fidonet
;                                    rowan{at}jelly.freeway.DIALix.oz.au

; C callable function which returns whether the specified year
; is a leap year.

; extern int leapyear(int year);


; Generic MASM compatible code, tested with MASM 5.10 and TASM 3.2

; Algorithm supplied by David Drummond:
; -------------------------------
; LeapYear if Year Mod 4 = 0
;    EXCEPT if Year Mod 100 = 0
;        UNLESS Year Mod 1000 = 0
; -------------------------------

; returns AX = -1  yes
; returns AX = 0   no


.model small,c
.code

PUBLIC isleapyear
isleapyear PROC Year:word

        push    bx
        push    cx
        push    dx
        push    si
        mov     ax,[Year]
        mov     cx,ax   ; register store for year
        xor     si,si   ; leapyear = FALSE
        cwd
        mov     bx,4
        div     bx
        or      dx,dx   ; year mod 4 = 0?
        jnz     L9      ; no, exit
        mov     si,-1   ; leapyear = TRUE
L1:
        mov     ax,cx
        cwd
        mov     bx,100
        div     bx
        or      dx,dx   ; year mod 100 = 0?
        jnz     L2
        xor     si,si   ; leapyear = FALSE
L2:
        mov     ax,cx
        cwd
        mov     bx,1000
        div     bx
        or      dx,dx   ; year mod 1000 = 0?
        jnz     L9
        mov     si,-1   ; leapyear = TRUE
L9:
        mov     ax,si
        pop     di
        pop     dx
        pop     cx
        pop     bx
        ret

isleapyear ENDP
END


For those who do not have an assembler:

section 1 of 1 of file leapyear.obj  

begin 644 leapyear.obj
M{at}`X`#&QE87!Y96%R+D%33026`{at}``:({at}#`$"AE)8,``5?5$585`1#3T1%EI{at}'
M`$A```(#`=.6#``%7T1!5$$$1$%40<*8!P!(```$!0$/E{at}{at}`!D1'4D]54(N:
M!``&_P);D!(```$+7TE33$5!4%E%05(````$B`0`0*(!D:!$``$``%6+[%-1
M4E:+1{at}2+R#/VF;L$`/?S"])U(+[__XO!F;MD`/?S"])U`C/VB\&9N^{at}#]_,+
4TG4#OO__B\9?6EE;7<-SB{at}(``'2.
`
end
sum -r/size 32333/307 section (from "begin" to "end")
sum -r/size 3871/200 entire input file

---
* Origin: Jelly-Bean software development, Melbourne AUST. (3:635/727.1)
SEEN-BY: 50/99 632/103 348 998 633/371 634/384 635/402 503 544 727 638/102
SEEN-BY: 639/252 640/230 690/718 711/401 410 413 430 808 809 934 713/888
SEEN-BY: 800/1 7877/2809
@PATH: 635/727 632/348 635/503 50/99 711/808 809 934

SOURCE: echomail via fidonet.ozzmosis.com

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.