Question

please rewrite or convert this C program into Assembly language and please make a notice of...

please rewrite or convert this C program into Assembly language and please make a notice of which function is which!

#include <stdio.h>
#include <stdlib.h>

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 >.<!: %d ! Must be between 1 and 12\n",mon);
return 1;
}

printf("Year : ");
fflush(stdout);
scanf("%d",&year);
  
if(year < 2000){
printf("Invalid year >.<!: %d! Must be 2000 or later!\n",year);
return 1;
}

printf("\n");
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 >.<!: %d ! Must be between 1 and 12\n",mon);
break;
}

}

}

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

}

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;

}

void printDays(int mon, int year){
  
int dayOfWeek = getFirstDayOfMonth(mon,year);
  
for(int i=0;i<dayOfWeek;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("\n");
}

printf("\n");

}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Qo.

ANS:

Assembly Code is:

.global main
   .func main
   main:
       MOV r1, #1
       CMP r1, #0
       BEQ case_1
       C case_def
   case_1:
       LDR r0,=op_1
       C END
   case_2:
       LDR r0,=op_2
       C END
   case_3:
       LDR r0,=op_3
       C END
   case_4:
       LDR r0,=op_4
       C END
   case_5:
       LDR r0,=op_5
       C END
   case_6:
       LDR r0,=op_6
       C END
   case_7:
       LDR r0,=op_7
       C END
   case_8:
       LDR r0,=op_8
       C END
   case_9:
       LDR r0,=op_9
       C END
   case_10:
       LDR r0,=op_10
       C END
   case_11:
       LDR r0,=op_11
       C END
   case_12:
       LDR r0,=op_12
       C END
   case_def:
       LDR r0, =op_def
   END:
       BL puts
       MOV R7,
       SWI 0  
   .data
   op_1: .asciz "January"
   op_2: .asciz "February"
   op_3: .asciz "March"
   op_4: .asciz "April"
   op_5: .asciz "MAy"
   op_6: .asciz "June"
   op_7: .asciz "July"
   op_8: .asciz "August"
   op_9: .asciz "September"
   op_10: .asciz "October"
   op_11: .asciz "Novembber"
   op_12: .asciz "December"
   op_def: .asciz "Wrong year"  
   .global puts

------------------------------------------------------------------------------------------------------------------

THANKS!!

Add a comment
Know the answer?
Add Answer to:
please rewrite or convert this C program into Assembly language and please make a notice of...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Could you do that in C language? Here is the code which we got #include <stdio.h>...

    Could you do that in C language? Here is the code which we got #include <stdio.h> #define MAX_SIZE 20 // function definitions void displaySpiral(int matrix[][MAX_SIZE], int size); void displayMatrix(int matrix[][MAX_SIZE], int size); int takeInput(int inputMatrix[][MAX_SIZE]); int main() { int matrix[MAX_SIZE][MAX_SIZE]; int matrixSize = takeInput(matrix); printf("Displaying the whole matrix:\n"); fflush(stdout); displayMatrix(matrix, matrixSize); printf("Now, displaying the matrix in a spiral way:\n"); fflush(stdout); displaySpiral(matrix, matrixSize); return 0; } // already implemented for you int takeInput(int inputMatrix[][MAX_SIZE]) { int size; printf("What is the size...

  • Can someone fix my coding please it's a calendar some days are placed wrong. I just...

    Can someone fix my coding please it's a calendar some days are placed wrong. I just want the Main menu to display first and second option and four option to end the program properly. Please remove option number 3 Find the number of days between 2 selected dates and the code that belongs to this function. #include<stdio.h> void days(int,int,int,int,int,int); int month(int,int); int mon[12]={31,28,31,30,31,30,31,31,30,31,30,31}; #define TRUE 1 #define FALSE 0 int days_in_month[]={0,31,28,31,30,31,30,31,31,30,31,30,31}; char *months[]= { " ", "\n\n\nJanuary", "\n\n\nFebruary", "\n\n\nMarch", "\n\n\nApril",...

  • Why isnt my MyCalender.java working? class MyCalender.java : package calenderapp; import java.util.Scanner; public class MyCalender {...

    Why isnt my MyCalender.java working? class MyCalender.java : package calenderapp; import java.util.Scanner; public class MyCalender { MyDate myDate; Day day; enum Day { Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday }    public static void main(String[] args) { Scanner sc= new Scanner(System.in); System.out.println("Enter date below :"); System.out.println("Enter day :"); int day = sc.nextInt(); System.out.println("Enter Month :"); int month = sc.nextInt(); System.out.println("Enter year :"); int year = sc.nextInt(); MyDate md = new MyDate(day, month, year); if(!md.isDateValid()){ System.out.println("\n Invalid date . Try...

  • Fix the errors in C code #include <stdio.h> #include <stdlib.h> void insertAt(int *, int); void Delete(int...

    Fix the errors in C code #include <stdio.h> #include <stdlib.h> void insertAt(int *, int); void Delete(int *); void replaceAt(int *, int, int); int isEmpty(int *, int); int isFull(int *, int); void removeAt(int *, int); void printList(int *, int); int main() { int *a; int arraySize=0,l=0,loc=0; int choice; while(1) { printf("\n Main Menu"); printf("\n 1.Create list\n 2.Insert element at particular position\n 3.Delete list.\n4. Remove an element at given position \n 5.Replace an element at given position\n 6. Check the size of...

  • Convert the C program into a C++ program.Replace all C input/output statements with C++ statements (cin,...

    Convert the C program into a C++ program.Replace all C input/output statements with C++ statements (cin, cout, cin.getline) . Re-make the func function by the following prototype: void func( double, double &); #include int user_interface(); double func(double); void print_table(); int main (int argc, char *argv[]) {    print_table(user_interface());    return 0 ; } int user_interface(int val){    int input = 0;    printf("This function takes in x and returns an output\n");    printf("Enter Maximum Number of X:");    scanf("%d", &input);...

  • Rewrite the following highlighted if...else section using a switch. Only rewrite the code that you need...

    Rewrite the following highlighted if...else section using a switch. Only rewrite the code that you need to change, not the entire code. #include #include #define TRUE 1 #define FALSE 0 int main(void ) { enum Pops{ Coke = 1, Pepsi, Root_Beer, Grape, Seven_Up, Mountain_Dew, Dr_Pepper, Orange }; int PopSelection, DietStyle; float Price; printf( "Please enter your favourite pop: \n"); printf( "1. Coke\ n"); printf( "2. Pepsi \n" ); printf( "3. Root Beer\ n"); printf( "4. Grape \n" ); printf( "5....

  • 1) Compile thread2.c (remember the -lpthread flag). Run it numerous times, and notice the output usually...

    1) Compile thread2.c (remember the -lpthread flag). Run it numerous times, and notice the output usually differs. a) Why is the variable myglobal usually not 40? Be specific, be precise. b) In what special case would myglobal be 40? Be specific, be precise. #include <pthread.h> #include <stdlib.h> #include <unistd.h> #include <stdio.h> #include <fcntl.h> /* Purpose: Use 2 threads to increment myglobal exactly 40 times in total. Compile: using -pthread option */ int myglobal = 0; void *thread_function(void *arg) {   ...

  • In the Source Folder (src) of this project create a new C source file called "gcd.c"....

    In the Source Folder (src) of this project create a new C source file called "gcd.c". Once again, copy the contents of the "main.c" file above into the "gcd.c" source file. Modify this program to NOT ask the user to input the second Positive Integer, if the user has entered a program terminating value for the "first" input Postitive Integer. #include <stdlib.h> #include <stdio.h> int main(int argc, char *argv[]) { //============================== setbuf(stdout, NULL); // turns standard output buffering off int...

  • Convert C++ language to PEP/8 assembly language

    Convert this C++ language to PEP/8 assembly language. #include <stdio.h> int main(void) {        int num, rem;     printf("Enter a number: ");     scanf("%d", &num);     printf("Roman numerals: ");             while(num != 0)     {         if (num >= 1000)       // 1000 - m         {            printf("m");            num -= 1000;         }         else if (num >= 900)   // 900 -  cm         {            printf("cm");            num -= 900;         }                 else if (num >= 500)   // 500 - d         {                       printf("d");            num -= 500;         }         else if (num >= 400)   // 400 -  cd         {            printf("cd");            num -= 400;         }         else if (num >= 100)   // 100 - c         {            printf("c");            num -= 100;                                }         else if (num >= 90)    // 90 - xc         {            printf("xc");            num -= 90;                                                       }         else if (num >= 50)    // 50 - l         {            printf("l");            num -= 50;                                                                              }         else if (num >= 40)    // 40 - xl         {            printf("xl");                       num -= 40;         }         else if (num >= 10)    // 10 - x         {            printf("x");            num -= 10;                    }         else if (num >= 9)     // 9 - ix         {            printf("ix");            num -= 9;                                  }         else if (num >= 5)     // 5 - v         {            printf("v");            num -= 5;                                              }         else if (num >= 4)     // 4 - iv         {            printf("iv");            num -= 4;                                                                     }         else if (num >= 1)     // 1 - i         {            printf("i");            num -= 1;                                                                                            }     }     return 0;}

  • C++ HELP I need help with this program. I have done and compiled this program in...

    C++ HELP I need help with this program. I have done and compiled this program in a single file called bill.cpp. It works fine. I am using printf and scanf. Instead of printf and scanf use cin and cout to make the program run. after this please split this program in three files 1. bill.h = contains the class program with methods and variables eg of class file class bill { } 2. bill.cpp = contains the functions from class...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT