Leap days (or not) in February for PBDOS
#2
Thanks a lot, Dale.

I converted everything to the syntax and rules of PB 3.5 and it workg fine!

Code:
'- 08.03.2025 - Dales work with syntax of PB 3.5

$Dim All
$Compile exe

Declare _
Function iTage_im_Februar(byval iJahr as integer) as integer

Function iTage_im_Februar(byval iJahr as integer) as integer
  Dim iFebruarTage As Local Integer

  ! push ax
  ! mov iFebruarTage, 28%              ; not a leap year, pre-set to 28
  ! mov ax, 1582%
  ! cmp ax, iJahr
  ! jge Julian
  ! mov ax, 3%
  ! and ax, iJahr                      ; conditionally equivalent MOD 4
  ! jz MOD100                          ; 0 is possible leap year
  ! jmp Done
MOD100:
  ! push bx                            ; for divisor
  ! push dx                            ; for high part of dividend,
                                       ' remainder (MOD)
  ! xor dx, dx
  ! mov ax, iJahr
  ! mov bx, 100%
  ! div bx
  ! cmp dx, 0%                         ; does MOD 100 = 0 ?
  ! pop dx
  ! pop bx
  ! jz MOD400                          ; 0 is possibly not a leap year
  ! jmp Is29Days                       ; non 0 is a leap year
MOD400:
  ! and ax, 3%                         ; AX has Year\100, so conditionally
                                       ' equivalent MOD 400
  ! jnz Done
Julian:
  ! mov ax, 3%
  ! and ax, iJahr
  ! jnz Done
Is29Days:
  ! mov iFebruarTage, 29%
Done:
  ! pop ax
  function = iFebruarTage
End Function

Function pbMain () as long 'put only to demonstrate Tage_im_Februar
  Dim iJahr As Local Integer
 
  iJahr = 2000
  print iTage_im_Februar(iJahr); " 2000, divisible by 400, is leap"
  iJahr = 2100
  print iTage_im_Februar(iJahr); " 2100, divisible by 100 not 400, not leap"
  iJahr = 2104
  print iTage_im_Februar(iJahr); " 2104, divisible by 4 not 100, is leap"
  iJahr = 2103
  print iTage_im_Februar(iJahr); " 2103, not divide 4, not leap
  print "julian, did not check rule for prior to Gregorian myself"
  iJahr = 1204
  print iTage_im_Februar(iJahr); " 1204, divisible by 4, is leap
  iJahr = 1201
  print iTage_im_Februar(iJahr)  " 1201, not divisible by 4, not leap
end function

pbMain


The output is the following:
Code:
29  2000, divisible by 400, is leap
28  2100, divisible by 100 not 400, not leap
29  2104, divisible by 4 not 100, is leap
28  2103, not divide 4, not leap
julian, did not check rule for prior to Gregorian myself
29  1204, divisible by 4, is leap
28  1201, not divisible by 4, not leap

This helps me a lot, Dale!
Reply


Messages In This Thread
RE: Leap days (or not) in February for PBDOS - by Andy Dee - 03-08-2025, 08:31 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)