Question

In: Computer Science

int getNumOfDaysInMonth(int mon, int year) {    if (mon == 2) if ( (year % 400...

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,

Solutions

Expert Solution

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


Related Solutions

#include <stdio.h> int isLeapYear(int year) {    if (year % 400 == 0 || (year %...
#include <stdio.h> int isLeapYear(int year) {    if (year % 400 == 0 || (year % 100 != 0 && year % 4 == 0)) {        return 1;    }    else {        return 0;    } } int toJulianLeap(int month, int day) {    month--;    switch (month)    {    case 1: day += 31;        break;    case 2: day += 60;        break;    case 3: day += 91;   ...
Date - month: int - day: int - year: int +Date() +Date(month: int, day: int, year:...
Date - month: int - day: int - year: int +Date() +Date(month: int, day: int, year: int) +setDate(month: int, day: int, year: int): void -setDay(day: int): void -setMonth(month: int): void -setYear(year: int): void +getMonth():int +getDay():int +getYear():int +isLeapYear(): boolean +determineSeason(): string +printDate():void Create the class Constructor with no arguments sets the date to be January 1, 1900 Constructor with arguments CALLS THE SET FUNCTIONS to set the Month, then set the Year, and then set the Day - IN THAT ORDER...
In Java: int[] A = new int[2]; A[0] = 0; A[1] = 2; f(A[0],A[A[0]]); void f(int...
In Java: int[] A = new int[2]; A[0] = 0; A[1] = 2; f(A[0],A[A[0]]); void f(int x, int y) { x = 1; y = 3; } For each of the following parameter-passing methods, saw what the final values in the array A would be, after the call to f. (There may be more than one correct answer.) a. By value. b. By reference. c. By value-result.
what is the output? int main ( ) { int a = 3, b= 2, c=...
what is the output? int main ( ) { int a = 3, b= 2, c= 1, d, e, f, g; d = a&b;    e = a | c; f = a >> 1, g = a << 1; cout << “d= “ << d << “ e = “ << e << “ f = “ << f << “g = “ << g << endl; }
#include <stdio.h> int main () { int value= 10; int value2= 5; value = value %2;...
#include <stdio.h> int main () { int value= 10; int value2= 5; value = value %2; printf("he FInal =value=%d\n", value); value +=3; printf("he FInal =value=%d\n", value); value ++; printf("he FInal =value=%d\n", value); value= ++value2; printf("he FInal =value=%d\n", value); value= value2--; printf("he FInal =value=%d\n", value); } what is output explain each print statement? exlain why?
Steganography Describe substitution, Mon alphabets, and other classes, and attacks
Steganography Describe substitution, Mon alphabets, and other classes, and attacks
Kleptography Describe substitution, Mon alphabets, and other classes, and attacks
Kleptography Describe substitution, Mon alphabets, and other classes, and attacks
Suppose A is (10, 2, 5, 9, 1, 8, 2, 4). Consider the function: int BBOX(int...
Suppose A is (10, 2, 5, 9, 1, 8, 2, 4). Consider the function: int BBOX(int n, int k)             if (n <= 0) return 0;             else if (A[n] < k) return (1+ 2*BBOX(n-1,k+1));             else return BBOX(n-1,k-2);             Find BBOX(8, 5)
int a = 3; int b = -2; if((a>0)&&(b>0)){ if (a>b) { System.out.println("A"); } else {...
int a = 3; int b = -2; if((a>0)&&(b>0)){ if (a>b) { System.out.println("A"); } else { System.out.println("B"); } } else if ((b<0)||(a<0)) { System.out.println("C"); } else { System.out.println("D"); }
Translate the following C code to MIPS assembly. int a = 1; int b = 2;...
Translate the following C code to MIPS assembly. int a = 1; int b = 2; if (a<b)           a=a+1; b = b + a; printf("The value of b is: %d", b); Translate the following C code to MIPS assembly. int a = 2; int b = 2; if (a<b)           a=a+1; else           a=a-1; b = b + a; printf("The value of b is: %d", b);
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT