1 2 segment .text 3 global easter_asm 4 5 ;typedef struct { 6 ; unsigned short d; 7 ; unsigned short m; 8 ;} Date; 9 10 ;void easter_asm(unsigned short Y, Date *d) 11 ; computes the Easter date for the year Y and stores it in d 12 ; 13 ;Parameters 14 ; Y - the year 15 ; d - the Date struct in which to store the result 16 17 %define d [ebp + 12] 18 %define Y [ebp + 8] 19 easter_asm: 20 enter 0, 0 21 sub esp, 28 22 %define G [ebp - 4] 23 %define C [ebp - 8] 24 %define X [ebp - 12] 25 %define Z [ebp - 16] 26 %define D [ebp - 20] 27 %define E [ebp - 24] 28 %define N [ebp - 28] 29 30 ; int G = (Y % 19) + 1; 31 xor edx, edx 32 mov eax, Y 33 mov ebx, 19 34 div ebx 35 inc edx 36 mov G, edx 37 38 ; int C = (int)(Y / 100) + 1; 39 xor edx, edx 40 mov eax, Y 41 mov ebx, 100 42 div ebx 43 inc eax 44 mov C, eax 45 46 ; int X = 3 * C / 4 - 12; 47 xor edx, edx 48 mov eax, C 49 mov ebx, 4 50 div ebx 51 mov ebx, 3 52 mul ebx 53 sub eax, 12 54 mov X, eax 55 56 ; int Z = (8 * C + 5) / 25 - 5; 57 xor edx, edx 58 mov eax, C 59 mov ebx, 8 60 mul ebx 61 add eax, 5 62 mov ebx, 25 63 div ebx 64 sub eax, 5 65 mov Z, eax 66 67 ; int D = 5 * Y / 4 - X - 10; 68 xor edx, edx 69 mov eax, Y 70 mov ebx, 5 71 mul ebx, 72 mov ebx, 4 73 div ebx 74 sub eax, X 75 sub eax, 10 76 mov D, eax 77 78 ; int E = (11 * G + 20 + Z - X) % 30; 79 mov eax, G 80 mov ebx, 11 81 mul ebx 82 add eax, 20 83 add eax, Z 84 sub eax, X 85 xor edx, edx 86 mov ebx, 30 87 div ebx 88 mov E, edx 89 90 cmp dword E, 24 91 jne after_e1 92 inc dword E 93 jmp after_e2 94 after_e1: 95 cmp dword E, 25 96 jne after_e2 97 cmp dword G, 11 98 jle after_e2 99 inc dword E 100 after_e2: 101 102 ; int N = 44 - E; 103 mov eax, 44 104 sub eax, E 105 mov N, eax 106 107 cmp dword N, 21 108 jge after_n 109 add dword N, 30 110 after_n: 111 ; N = N + 7 - ((D + N) % 7); 112 mov eax, N 113 add eax, D 114 xor edx, edx 115 mov ebx, 7 116 div ebx 117 add dword N, 7 118 sub N, edx 119 120 mov eax, d 121 122 ; N is the nuber of day from March 1 to easter. Check if easter is in April. 123 cmp dword N, 31 124 jle in_march 125 mov bl, N 126 sub bl, 31 127 mov [eax], bl 128 mov word [eax + 2], 4 129 jmp quit 130 in_march: 131 mov bl, N 132 mov [eax], bl 133 mov word [eax + 2], 3 134 quit: 135 leave 136 ret
You need to create an account or log in to post comments to this site.