; Name: leapyear.asm;; Build: nasm -felf64 leapyear.asm -o leapyear.o ;; in : RDI holds the year in hexadecimal format. Year is a positive number.; out : RAX = -1, no leap, RAX = 0 leapglobal pagesize
section .text
LeapYear:pushrbx; save used registerspushrcxpushrdxmovrax, rdixorrcx, rcx; help register = 0decrcx; assume not leap, rcx = -1testrax, 3; last two bits 0?jnz .@1 ; if not year is not disible by 4 -> no leapyearincrcx; assume year is a leapyear, rcx = 0xorrdx, rdx; prepare rdx for divisionmovrbx, 100; year / 100divrbxandrdx, rdx; remainder = 0?jnz .@1 ; no, no leapyeartestrax, 3; multiples of 100 aren't leap years except if last two bits; are zero 0 (divisible by 4) then also divisible by 400jz .@1 ; yes, leap yeardecrcx; no, not leap year, rcx = -1
.@1:
movrax, rcx; mov result in RAXpoprdxpoprcxpoprbxret