In: Computer Science
int getNumOfDaysInMonth(int mon, int year)
{
if (mon == 2)
if ( (year % 400 == 0) || ((year % 4 == 0) && (year % 100
!= 0)))
return 29;
else
return 28;
else if (mon == 4 || mon == 6 || mon == 9 || mon == 11)
return 30;
else if (mon == 1 || mon==3 || mon == 5 || mon == 7 || mon == 8
|| mon == 10 || mon == 12)
return 31;
return 0;
}
Please convert above C program to x86. Please post the correct solution. TIA,
getNumOfDaysInMonth(int, int):
push rbp
mov rbp, rsp
mov DWORD PTR [rbp-4], edi
mov DWORD PTR [rbp-8], esi
cmp DWORD PTR [rbp-4], 2
jne .L2
mov ecx, DWORD PTR [rbp-8]
mov edx, 1374389535
mov eax, ecx
imul edx
sar edx, 7
mov eax, ecx
sar eax, 31
sub edx, eax
mov eax, edx
imul eax, eax, 400
sub ecx, eax
mov eax, ecx
test eax, eax
je .L3
mov eax, DWORD PTR [rbp-8]
and eax, 3
test eax, eax
jne .L4
mov ecx, DWORD PTR [rbp-8]
mov edx, 1374389535
mov eax, ecx
imul edx
sar edx, 5
mov eax, ecx
sar eax, 31
sub edx, eax
mov eax, edx
imul eax, eax, 100
sub ecx, eax
mov eax, ecx
test eax, eax
je .L4
.L3:
mov eax, 29
jmp .L5
.L4:
mov eax, 28
jmp .L5
.L2:
cmp DWORD PTR [rbp-4], 4
je .L6
cmp DWORD PTR [rbp-4], 6
je .L6
cmp DWORD PTR [rbp-4], 9
je .L6
cmp DWORD PTR [rbp-4], 11
jne .L7
.L6:
mov eax, 30
jmp .L5
.L7:
cmp DWORD PTR [rbp-4], 1
je .L8
cmp DWORD PTR [rbp-4], 3
je .L8
cmp DWORD PTR [rbp-4], 5
je .L8
cmp DWORD PTR [rbp-4], 7
je .L8
cmp DWORD PTR [rbp-4], 8
je .L8
cmp DWORD PTR [rbp-4], 10
je .L8
cmp DWORD PTR [rbp-4], 12
jne .L9
.L8:
mov eax, 31
jmp .L5
.L9:
mov eax, 0
.L5:
pop rbp
ret