Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please turn my 5 functions of my C program into Assembly: #(function 1) void printMonthYear(int mon,int year); .global getFirstDayOfMonth .data #TODO: Put strings here .text

Please turn my 5 functions of my C program into Assembly:

#(function 1) void printMonthYear(int mon,int year);

.global getFirstDayOfMonth

.data #TODO: Put strings here .text

getFirstDayOfMonth: push %rbx # TODO: complete pop %rbx ret

#(function 2) void printDaysOfWeek();

.global getNumOfDaysInMonth

.data #TODO: Put strings here

.text

getNumOfDaysInMonth: push %rbx # TODO: complete pop %rbx ret

#(function 3) void printDays(int mon,int year);

.global printDays

.data #TODO: Put strings here

.text

printDays: push %rbx # TODO: complete

pop %rbx ret

#(function 4) int getFirstDayOfMonth(int mon, int year);

.global printDaysOfWeek

.data #TODO: Put strings here

.text

printDaysOfWeek: push %rbx # TODO: complete pop %rbx ret

#(function 5) int getNumOfDaysInMonth(int mon, int year);

.global printMonthYear

.data msg: .asciz "%s %d " jan: .asciz "January" feb: .asciz "February" .text

printMonthYear: # save registers push %rbx push %r12 # %r12 = mon push %r13 # %r13 = year push %r14 # %r14 = currentMonth mov %rdi, %r12 # save mon to %r12 mov %rsi, %r13 # save year to %r13

cmp $1, %r12 # mon == 1 jne else1 mov $jan, %r14 # currentMonth = "January" jmp if_else_if_done else1: cmp $2, %r12 # mon == 2 jne else2 mov $feb, %r14 # currentMonth = "February" jmp if_else_if_done else2:

if_else_if_done:

mov $msg, %rdi # param1 is $msg mov %r14, %rsi # param2 is mon mov %r13, %rdx # param3 is year xor %rax, %rax # clear %rax call printf # restore registers pop %r14 pop %r13 pop %r12 pop %rbx ret ---------------------------------------------------------//----------------------------------------

Here is my C code below:

#include #include

void printMonthYear(int mon,int year);

void printDaysOfWeek();

void printDays(int mon,int year);

int getFirstDayOfMonth(int mon, int year);

int getNumOfDaysInMonth(int mon, int year);

int main(void) { int mon=-1; int year= -1;

printf("Month : "); fflush(stdout); scanf("%d",&mon); if(mon < 1|| mon > 12){ printf("Invalid month >. return 1; }

printf("Year : "); fflush(stdout); scanf("%d",&year); if(year < 2000){ printf("Invalid year >. return 1; }

printf(" "); printMonthYear(mon,year); printDaysOfWeek(); printDays(mon,year); return EXIT_SUCCESS;

}

void printMonthYear(int mon, int year){ switch(mon){ case 1: printf("\tJanuary %d",year); break; case 2: printf("\tFebruary %d",year); break; case 3: printf("\tMarch %d",year); break; case 4: printf("\tApril %d",year); break; case 5: printf("\tMay %d",year); break; case 6: printf("\tJune %d",year); break; case 7: printf("\tJuly %d",year); break; case 8: printf("\tAugust %d",year); break; case 9: printf("\tSeptember %d",year); break; case 10: printf("\tOctober %d",year); break; case 11: printf("\tNovember %d",year); break case 12: printf("\tDecember %d",year); break; default: printf("Invalid month >. break;

}

}

void printDaysOfWeek(){ printf(" Su Mo Tu We Th Fr Sa ");

} void printDays(int mon, int year){ int dayOfWeek = getFirstDayOfMonth(mon,year); for(int i=0;i printf(" "); int daysInMonth = getNumOfDaysInMonth(mon,year); for(int i=1;i<=daysInMonth;i++){

if(i > 9) printf(" %d",i);

else printf(" %d ",i);

if((i+dayOfWeek)%7 == 0) printf(" "); }

printf(" ");

}

int getFirstDayOfMonth(int mon, int year){ int day, century, result; mon = ((mon + 9) % 12) + 1; year = year-2000; if(mon > 10){ year--; } day = 1; century = 20; result = day + year+(13 * mon - 1) / 5 + year / 4 + century / 4 - 2 * century; result = result%7; result = result + 7; result = result%7; return result;

}

int getNumOfDaysInMonth(int mon, int year){ if(mon == 1 || mon == 3 || mon == 5 || mon == 7 || mon == 8 || mon == 10 || mon ==12) return 31; else if(mon == 4 || mon == 6 || mon == 9 || mon == 11) return 30; else return 28;

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Data Management Databases And Organizations

Authors: Richard T. Watson

2nd Edition

0471180742, 978-0471180746

More Books

Students also viewed these Databases questions