Create a MIPS asm program that requests for three numbers from the user. Month,
ID: 3802861 • Letter: C
Question
Create a MIPS asm program that requests for three numbers from the user. Month, Day, and Year. You may assume that a valid date is given. Your program will return the DAY number of the year. Your program should accurately calculate leap years. Your program function should accept the month (1 through 12), day, and year as unsigned integers. As an example, January 1, 1994 is day 1. December 31, 1993 is day 365. December 31, 1996 is day 366 since 1996 is a leap year. A year is a leap year if it’s divisible by four, except that any year divisible by 100 is a leap year only if it’s also divisible by 400.
Program MUST use recursive for the modulo and be a MIPS asm program! This is for an entry level class! Please add comments so that I may fully understand what is going on in the program, Thank you!
Here is an example output, the output should match this:
Month: 1
Day: 1
Year: 1995
1
Month: 12
Day: 31
Year: 1996
366
Explanation / Answer
Answer:
#include <stdio.h>
int leap (int annual, int input);
int inc_read (int read, int inc);
int value;
int main()
{
int day;
int read;
int annual;
printf("Enter a read=>");
scanf("%d", &read);
printf("Enter a day=>");
scanf("%d", &day);
printf("Enter a annual=>");
scanf("%d", &annual);
int leap (int annual, int input);
int inc_read (int read, int inc);
printf("The day inputber is %d", value);
return 0;
}
int leap (int annual, int input)
{
if((annual % 4) == 0)
input = 1;
else
input = 0;
if((annual % 100 == 0) && ((annual % 400)) == 0)
input = 1;
return input;
}
int inc_read (int read, int inc)
{
if (read == 1)
inc= 0;
else
if (read == 2)
inc = 31;
else
if (read == 3)
inc = 59;
else
if (read == 4)
inc = 90;
else
if (read == 5)
inc = 120;
else
if (read == 6)
inc = 151;
else
if (read == 7)
inc =181;
else
if (read == 8)
inc = 212;
else
if (read == 9)
inc = 243;
else
if (read == 10)
inc = 273;
else
if (read == 11)
inc = 304;
else
if (read == 12)
inc = 334;
return inc;
}
int day_inc (int inc, int input, int day, int value)
{
value = inc + input + day;
return value;
}