<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: easter code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Sat, 06 Sep 2008 19:02:16 GMT</pubDate>
    <description>DZone Snippets: easter code</description>
    <item>
      <title>Easter date - NASM</title>
      <link>http://snippets.dzone.com/posts/show/3982</link>
      <description>Compute Easter date in NASM.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;segment .text&lt;br /&gt;  global easter_asm&lt;br /&gt;&lt;br /&gt;;typedef struct {&lt;br /&gt;;  unsigned short d;&lt;br /&gt;;  unsigned short m;&lt;br /&gt;;} Date;&lt;br /&gt;&lt;br /&gt;;void easter_asm(unsigned short Y, Date *d)&lt;br /&gt;;   computes the Easter date for the year Y and stores it in d&lt;br /&gt;;&lt;br /&gt;;Parameters&lt;br /&gt;;   Y - the year&lt;br /&gt;;   d - the Date struct in which to store the result&lt;br /&gt;&lt;br /&gt;%define d [ebp + 12]&lt;br /&gt;%define Y [ebp + 8]&lt;br /&gt;easter_asm:&lt;br /&gt;  enter 0, 0&lt;br /&gt;  sub esp, 28&lt;br /&gt;  %define G [ebp - 4]&lt;br /&gt;  %define C [ebp - 8]&lt;br /&gt;  %define X [ebp - 12]&lt;br /&gt;  %define Z [ebp - 16]&lt;br /&gt;  %define D [ebp - 20]&lt;br /&gt;  %define E [ebp - 24]&lt;br /&gt;  %define N [ebp - 28]&lt;br /&gt;&lt;br /&gt;  ; int G = (Y % 19) + 1;&lt;br /&gt;  xor edx, edx&lt;br /&gt;  mov eax, Y&lt;br /&gt;  mov ebx, 19&lt;br /&gt;  div ebx&lt;br /&gt;  inc edx&lt;br /&gt;  mov G, edx&lt;br /&gt;&lt;br /&gt;  ; int C = (int)(Y / 100) + 1;&lt;br /&gt;  xor edx, edx&lt;br /&gt;  mov eax, Y&lt;br /&gt;  mov ebx, 100&lt;br /&gt;  div ebx&lt;br /&gt;  inc eax&lt;br /&gt;  mov C, eax&lt;br /&gt;&lt;br /&gt;  ; int X = 3 * C / 4 - 12;&lt;br /&gt;  xor edx, edx&lt;br /&gt;  mov eax, C&lt;br /&gt;  mov ebx, 4&lt;br /&gt;  div ebx&lt;br /&gt;  mov ebx, 3&lt;br /&gt;  mul ebx&lt;br /&gt;  sub eax, 12&lt;br /&gt;  mov X, eax&lt;br /&gt;&lt;br /&gt;  ; int Z = (8 * C + 5) / 25 - 5;&lt;br /&gt;  xor edx, edx&lt;br /&gt;  mov eax, C&lt;br /&gt;  mov ebx, 8&lt;br /&gt;  mul ebx&lt;br /&gt;  add eax, 5&lt;br /&gt;  mov ebx, 25&lt;br /&gt;  div ebx&lt;br /&gt;  sub eax, 5&lt;br /&gt;  mov Z, eax&lt;br /&gt;&lt;br /&gt;  ; int D = 5 * Y / 4 - X - 10;&lt;br /&gt;  xor edx, edx&lt;br /&gt;  mov eax, Y&lt;br /&gt;  mov ebx, 5&lt;br /&gt;  mul ebx,&lt;br /&gt;  mov ebx, 4&lt;br /&gt;  div ebx&lt;br /&gt;  sub eax, X&lt;br /&gt;  sub eax, 10&lt;br /&gt;  mov D, eax&lt;br /&gt;&lt;br /&gt;  ; int E = (11 * G + 20 + Z - X) % 30;&lt;br /&gt;  mov eax, G&lt;br /&gt;  mov ebx, 11&lt;br /&gt;  mul ebx&lt;br /&gt;  add eax, 20&lt;br /&gt;  add eax, Z&lt;br /&gt;  sub eax, X&lt;br /&gt;  xor edx, edx&lt;br /&gt;  mov ebx, 30&lt;br /&gt;  div ebx&lt;br /&gt;  mov E, edx&lt;br /&gt;&lt;br /&gt;  cmp dword E, 24&lt;br /&gt;  jne after_e1&lt;br /&gt;  inc dword E&lt;br /&gt;  jmp after_e2&lt;br /&gt;after_e1:&lt;br /&gt;  cmp dword E, 25&lt;br /&gt;  jne after_e2&lt;br /&gt;  cmp dword G, 11&lt;br /&gt;  jle after_e2&lt;br /&gt;  inc dword E&lt;br /&gt;after_e2:&lt;br /&gt;&lt;br /&gt;  ; int N = 44 - E;&lt;br /&gt;  mov eax, 44&lt;br /&gt;  sub eax, E&lt;br /&gt;  mov N, eax&lt;br /&gt;&lt;br /&gt;  cmp dword N, 21&lt;br /&gt;  jge after_n&lt;br /&gt;  add dword N, 30&lt;br /&gt;after_n:&lt;br /&gt;  ; N = N + 7 - ((D + N) % 7);&lt;br /&gt;  mov eax, N&lt;br /&gt;  add eax, D&lt;br /&gt;  xor edx, edx&lt;br /&gt;  mov ebx, 7&lt;br /&gt;  div ebx&lt;br /&gt;  add dword N, 7&lt;br /&gt;  sub N, edx&lt;br /&gt;&lt;br /&gt;  mov eax, d&lt;br /&gt;&lt;br /&gt;  ; N is the nuber of day from March 1 to easter. Check if easter is in April.&lt;br /&gt;  cmp dword N, 31&lt;br /&gt;  jle in_march&lt;br /&gt;  mov bl, N&lt;br /&gt;  sub bl, 31&lt;br /&gt;  mov [eax], bl&lt;br /&gt;  mov word [eax + 2], 4&lt;br /&gt;  jmp quit&lt;br /&gt;in_march:&lt;br /&gt;  mov bl, N&lt;br /&gt;  mov [eax], bl&lt;br /&gt;  mov word [eax + 2], 3&lt;br /&gt;quit:&lt;br /&gt;  leave&lt;br /&gt;  ret&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Thu, 10 May 2007 08:17:06 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/3982</guid>
      <author>scvalex (Alexandru Scvortov)</author>
    </item>
    <item>
      <title>Easter date - C</title>
      <link>http://snippets.dzone.com/posts/show/3973</link>
      <description>Easter_c computes the easter date for year Y. It uses the standard (as used by most western churches) algorithm developed by the Napolitan astronomer Aloysius Lilius and the Jesuit mathematician Christopher Clavius. It works for any year after 1582.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;typedef struct {&lt;br /&gt;  unsigned char d;&lt;br /&gt;  unsigned char m;&lt;br /&gt;} Date;&lt;br /&gt;&lt;br /&gt;void easter_c(unsigned short Y, Date *d) {&lt;br /&gt;  int G = (Y % 19) + 1;&lt;br /&gt;  int C = (int)(Y / 100) + 1;&lt;br /&gt;  int X = 3 * C / 4 - 12;&lt;br /&gt;  int Z = (8 * C + 5) / 25 - 5;&lt;br /&gt;  int D = 5 * Y / 4 - X - 10;&lt;br /&gt;  int E = (11 * G + 20 + Z - X) % 30;&lt;br /&gt;  if (((E == 25) &amp;&amp; (G &gt; 11)) || (E == 24))&lt;br /&gt;    ++E;&lt;br /&gt;  int N = 44 - E;&lt;br /&gt;  if (N &lt; 21)&lt;br /&gt;    N += 30;&lt;br /&gt;  N = N + 7 - ((D + N) % 7);&lt;br /&gt;&lt;br /&gt;  if (N &gt; 31) {&lt;br /&gt;    d-&gt;d = N - 31;&lt;br /&gt;    d-&gt;m = 4;&lt;br /&gt;  } else {&lt;br /&gt;    d-&gt;d = N;&lt;br /&gt;    d-&gt;m = 3;&lt;br /&gt;  }&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Wed, 09 May 2007 09:36:22 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/3973</guid>
      <author>scvalex (Alexandru Scvortov)</author>
    </item>
  </channel>
</rss>
