FastProc for PBWin 10 or PBCC 6.
(no need to understand assembly, just cut and paste "as-is" to use)
((no PBWin or PBCC specific code, will work in either regardless of which it is compiled by))
fastproc FebDays (byval Year as long) as long
  ! mov ecx, Year 'Year now available for reuse as result
  ! mov Year, 28& 'not a leap year pre-set
  ! mov eax, 3&   'power of two divisor,either/both bits 0 and 1 mean <> 0 MOD
  ! and eax, ecx  'conditionally equivalent MOD 4
  ! jnz Done      'not a leap year
  'MOD100:        'label not needed, Year MOD 4 = 0 "falls" to MOD 100 check
  ! xor edx, edx  'clear upper dividend
  ! mov eax, ecx  'year into lower dividend
  ! mov ebx, 100& '100 into divisor
  ! div ebx       'divide, quotient is in EAX, remainder (MOD) in EDX (2 for 1)
  ! cmp edx, 0&   'compare remainder with 0
  ! jnz Is29Days  'year <> 0 is a leap year, 0 is possibly a leap year
  'MOD400:        'label not needed, year MOD 100 = 0 "falls" to MOD 400 check
  ! and eax, 3&   'EAX has from Year\100, so is conditionally equivalent MOD 400
  ! jnz Done      'year AND 3 <> 0 is a leap year, else "fall" to Is29Days
  Is29Days:
  ! mov Year, 29&
  Done:
end fastproc = Year
To use as IsLeapYear, put 0 instead of 28, and -1 instead of 29; and the change the label name for readability; otherwise identicle to the above.
fastproc IsLeapYear (byval Year as long) as long
  ! mov ecx, Year
  ! mov Year, 0&
  ! mov eax, 3&
  ! and eax, ecx
  ! jnz Done
  'MOD100:
  ! xor edx, edx
  ! mov eax, ecx
  ! mov ebx, 100&
  ! div ebx
  ! cmp edx, 0&
  ! jnz IsLeap
  'MOD400:
  ! and eax, 3&
  ! jnz Done
  IsLeap:
  ! mov Year, -1&
  Done:
end fastproc = Year
No descriptors, except THREADSAFE, available in FASTPROC, see next.
As FUNCTION for earlier PB compilers, in DLL for any PB version, or SLL for PBWin 10 or PBCC 6.
Add ALIAS and EXPORT to compile in DLL, COMMON if as SLL.
function FebDays (byval Year as long) as long
  if (Year and 3) then         '(<> 0) not a leap year
    function = 28
  else                         '(=0) may be a leap year
    if (Year mod 100) then     '(<> 0) is a leap year unless
      function = 29
    else                       '(= 0) may be a leap year
      if (Year mod 400) then   '(<> 0) it is not a leap year
        function = 28
      else                     '(=0) it is a leap year
        function = 29
      end if
    end if
  end if
end function
Same as shown for assembly, to make an IsLeapYear function change 28 to 0 and 29 to -1.

Full copyleft (ɔ), 2024 by Dale Yarker in source or compiled form. Complete license in new tab or window.


Created on 07 September 2024.

Done with this window?