Faster leap year code.
#1
This is roughly 3 times faster than the usual three MOD operations method.
Code:
  ! push eax          'for pseudo MOD, dividend and quotient
  ! mov FebDays, 28&  'not a leap year pre-set
  ! mov eax, 3???
  ! and eax, Year    'conditionally equivalent MOD 4
  ! jz MOD100        '0 is possible leap year
  ! jmp Done
  MOD100:
  ! push ebx          'for divisor
  ! push edx          'for high part of dividend, remainder (MOD)
  ! xor edx, edx
  ! mov eax, Year
  ! mov ebx, 100???
  ! div ebx
  ! cmp edx, 0???    'does MOD 100 = 0 ?
  ! pop edx
  ! pop ebx
  ! jz MOD400        '0 is possibly not a leap year
  ! jmp Is29Days      'non 0 is a leap year
  MOD400:
  ! and eax, 3???    'EAX has Year\100, so pseudo MOD 4 again
  ! jnz Done
  ! Is29Days:
  ! mov FebDays, 29&
  Done:
  ! pop eax '
(here pseudo means conditionally equivalent, the condition is the divisor being a power of 2)

Longer description at: http://www.yarker-dsyc.info/D_Notebook/P...yDays.html
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)