Leap days (or not) in February for PBDOS
#1
'DECLARE not needed if FUNCTION source is before the CALL
'here the CALL is in PBMAIN
'I call it bottom up because PBMAIN is last and flow goes up
'
'Pretty sure PUSHes and POPs not needed in FUNCTION
'They will be needed to use "inside" code in-line with BASIC
'
'Used PBCC v6 to test. I no longer have PBDOS available.
function Tage_im_Februar(byval iJahr as integer) as integer
  local FebruarTage as integer
  ! push ax
  ! mov FebruarTage, 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%    'EAX has Year\100, so conditionally equivalent MOD 400
  ! jnz Done
  Julian:
  ! mov ax, 3%
  ! and ax, iJahr
  ! jnz Done
  Is29Days:
  ! mov FebruarTage, 29%
  Done:
  ! pop ax
  function = FebruarTage
end function
function pbmain () as long 'put only to demonstrate Tage_im_Februar
  local iJahr as integer
  iJahr = 2000
  print Tage_im_Februar(iJahr); " 2000, divisible by 400, is leap"
  iJahr = 2100
  print Tage_im_Februar(iJahr); " 2100, divisible by 100 not 400, not leap"
  iJahr = 2104
  print Tage_im_Februar(iJahr); " 2104, divisible by 4 not 100, is leap"
  iJahr = 2103
  print Tage_im_Februar(iJahr); " 2103, not divide 4, not leap
  print "julian, did not check rule for prior to Gregorian myself"
  iJahr = 1204
  print Tage_im_Februar(iJahr); " 1204, divisible by 4, is leap
  iJahr = 1201
  print Tage_im_Februar(iJahr)  " 1201, not divisible by 4, not leap
  waitkey$
end function
Reply


Messages In This Thread
Leap days (or not) in February for PBDOS - by Dale Yarker - 03-08-2025, 08:48 AM

Forum Jump:


Users browsing this thread: 1 Guest(s)