I would REALLY appreciate some help here: Dear Chegg tutors, Many students are s
ID: 3766133 • Letter: I
Question
I would REALLY appreciate some help here: Dear Chegg tutors, Many students are struggling with this exercice and many of you post random answers just to fill up the gap. Can anyone please take the time and energy to work on this? It has to assemble and compile correctly on MARS. I do not mind paying extra: Write and submit a MIPS Assembly Language program which: 1) reads the year of interest from user input, 2) displays the dates and time of all full moons for the year, and 3) identifies the monthly and seasonal blue moons which occur during that year. The program must make use of subprograms (functions, methods, subroutines, etc.). The program must be properly documented which includes in file comments. Again, if I have to, I would pay extra.
Explanation / Answer
MIPS Assembly Language program:
//loop function
mov ecx, n // initialize loop counter by loading n into 32 bit accumulator
LOP : push ecx // loop count index saved on stack
lea eax, getnext //ask for the next number
push eax // push the variable onto the stack
call printf // call printf, it will take parameter from the stack
add esp, 4 //clean the top position in the stack
lea eax, x // read the next number x
push eax // push the variable onto the stack
lea eax, format //address of the format string is saved in eax
push eax // push the variable onto the stack
call scanf // call printf, it will take parameter from the stack
add esp, 8 //clean the top 2 positions in the stack
mov eax, x //initialise eax as the number we just read
cmp eax, 0 //compare x (which is in eax) with 0
jne notzero // if x is not zero jump to notzero
add zero, 1 //add 1 to the variable zero
jmp next
notzero :
jl negative // if x is lower then 0 jump to negative
add pos, 1 //add 1 to the variable pos
jmp next
Code:
#include <stdio.h>
#include <stdlib.h>
#include "stdafx.h"
int main(void)
{
char getn[] = "Input how many numbers do you want to test (input n) :";
char getnext[] = "Insert next number ";
char numberzero[] = "The number of zero values is ";
char numbernegative[] = "The number of negative values is ";
char numberpositive[] = "The number of positive values is ";
char format[] = "%d"; // format string for the scanf function
char formatnumber[] = "%d "; //declaration of the format string to be used in printf function
int n;
int pos = 0; //declaration of an integer variable
int nega = 0; //declaration of an integer variable
int zero = 0; //declaration of an integer variable
int x;
_asm {
lea eax, getn // ask for the first number
push eax // push the variable onto the stack
// push the variable onto the stack
call printf // call printf, it will take parameter from the stack
add esp, 4 //clean the top position in the stack
lea eax, n //read it in
push eax // push the variable onto the stack
lea eax, format //address of the format string is saved in eax
push eax // push the variable onto the stack
call scanf // call printf, it will take parameter from the stack
add esp, 8 //clean the top 2 positions in the stack.