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

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.
#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"); }
2. Let the function fun be defined as int fun(int*k) {       *k += 4;       return...
2. Let the function fun be defined as int fun(int*k) {       *k += 4;       return 3 * (*k) - 1; } Suppose fun is used in a program as follows: void main() {       int i = 10, j = 10, sum1, sum2;       sum1 = (i / 2) + fun(&i);       sum2 = fun(&j) + (j / 2); } What are the values of sum1 and sum2 a. operands in the expressions are evaluated left to right? b. operands...
Show the output of the following code segment. int count=0;                         for (int i=2; i <=...
Show the output of the following code segment. int count=0;                         for (int i=2; i <= 4; i++ ) {                                     StdOut.println(i);                                     for (int j=1; j <3; j++) {                                                 count++;                                                 StdOut.println(i +" " + j +" "+ count);                                     }                         } count i j I print 0 2 1 3 1 1 1 2 3 2 2 3 3 3 3 4 3 Show the output of the function call statements shown.             double x =...
int compare_and_swap(int *value, int expected, int new_value) { int temp = *value; if ( *value ==...
int compare_and_swap(int *value, int expected, int new_value) { int temp = *value; if ( *value == expected ) *value = new_value; return temp; } Suppose that a machine has an atomic compare_and_swap() instruction that sets the value to new_value only if the expression ( *value == expected ) is true. Regardless, compare_and_swap() always returns the original value of the variable value. Using the compare__and_swap() instruction, give a mutual-exclusion solution to the n-process critical section problem. Use only the shared variable...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT