Question

please can you help me to solve it in Mips Assembly that works on Mars 4.5:...

please can you help me to solve it in Mips Assembly that works on Mars 4.5:

  1. The function isEven, tests whether a number num is even or not.
  2. Write the main function of a program that reads a nuber num, calls the function isEven and then prints a message to indicate whether num is even or not. And then, ask the user if she wants to continue or not (Y/N).
please answer it
0 0
Add a comment Improve this question Transcribed image text
Answer #1

MARS- MIPS Assembler and Runtime Simulator.

  • An IDE for MIPS Assembly Language Programming.
  • MARS is a lightweight interactive development environment (IDE) for programming in MIPS assembly language, intended for educational-level use.

Step 1- program in Mips assembly

.data

        prompt: .asciiz "\n Enter a number: "
        even_msg: .asciiz "\n The number is even.\n"
        odd_msg: .asciiz "\n The number is odd.\n"
        goodbye: .asciiz "\n If continew press Y\n"
.text
main:
        j loop
loop:
        la $a0, prompt
        li $v0, 4
        syscall

        # Read in value
        li $v0, 5
        syscall

        # If number is negative, exit program.
        slt $t0, $v0, $zero
        bne $t0, $zero, exit

        # Call even_or_odd on value
        add $a0, $v0, $zero
        jal even_or_odd
        j loop
even_or_odd:
        addi $t0, $zero, 2 # Set divisor to 2
        div $a0, $t0
        mfhi $t0           # Save remainder
        beq $t0, $zero, even
        j odd
even:
        la $a0, even_msg        
        li $v0, 4
        syscall
        j return
odd:
        la $a0, odd_msg
        li $v0, 4
        syscall
        j return
return:
        lw $t0, 0($sp)  
        addi $sp, $sp, 4
        jr $ra
exit:
        la $a0, If continew press Y 
        li $v0, 4
        syscall
        li $v0, 10
        syscall

Step 2- In this program first just message printed then function defined to check given no is even or odd.

Add a comment
Know the answer?
Add Answer to:
please can you help me to solve it in Mips Assembly that works on Mars 4.5:...
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
  • ASSEMBLY LANGUAGE (Mars MIPS) Starting code: Factorial: #Factorial Recursive function subu $sp, $sp, 4 sw $ra,...

    ASSEMBLY LANGUAGE (Mars MIPS) Starting code: Factorial: #Factorial Recursive function subu $sp, $sp, 4 sw $ra, 4($sp) # save the return address on stack beqz $a0, terminate # test for termination subu $sp, $sp, 4 # do not terminate yet sw $a0, 4($sp) # save the parameter sub $a0, $a0, 1 # will call with a smaller argument jal Factorial # after the termination condition is reached these lines # will be executed lw $t0, 4($sp) # the argument I...

  • Can someone help me solve this MIPS question, it must be able to run on qtspim....

    Can someone help me solve this MIPS question, it must be able to run on qtspim. Write a MIPS code which involves three functions: a. main b. poly C. Pow to compute the value of the polynomial given below for any value of x, as given by the user. f(x) = 3x + 2x4 - 5x +7-6 Your program must pass arguments to functions such as poly and pow and get return values from these functions. The input to the...

  • can someone please help me with this. I need to use java. Recursion Write and run...

    can someone please help me with this. I need to use java. Recursion Write and run a program that reads in a set of numbers and stores them in a sequential array. It then calls a recursive function to sort the elements of the array in ascending order. When the sorting is done, the main function prints out the elements of the newly sorted array Hint: How do you sort an array recursively? Place the smallest element of the array...

  • PROJECT 6    Functions You are to write a PYTHON program which: *Defines the following 4  functions: whoamI()...

    PROJECT 6    Functions You are to write a PYTHON program which: *Defines the following 4  functions: whoamI() This function prints out your name and lists any programming course you have taken prior to this course. isEven(number) This function accepts one parameter, a number, and prints out a message indicating if the number is even or odd. Keep in mind that a number is even if there is no remainder when the number is divided by two. printEven(number) This function accepts one...

  • PLEASE USE VERY BASIC REGISTERS AND CODE TO DO THE FOLLOWING Objectives: -write assembly language programs...

    PLEASE USE VERY BASIC REGISTERS AND CODE TO DO THE FOLLOWING Objectives: -write assembly language programs to:             -define a recursive procedure/function and call it.             -use syscall operations to display integers and strings on the console window             -use syscall operations to read integers from the keyboard. Assignment Description: Implement a MIPS assembly language program that defines "main", and "function1" procedures. The function1 is recursive and should be defined as: function1(n) = (2*n)+9                      if n <= 5              =...

  • I've been trying to do this and cant figure it out. Please help me with this...

    I've been trying to do this and cant figure it out. Please help me with this whole code, especially the section that is highlighted. Thank you!! Write a complete Java program to do the following: The main program reads in and prints three bowling scores, scorel, Score2, and score3. then calls a series of methods to process these scores. It The main program calls a method validGroup() to determine if this set of three values forms a valid group. The...

  • This exercise is also from C++ How do I even figure this out? please help me...

    This exercise is also from C++ How do I even figure this out? please help me solve so I can get the answer correctly! Question 28 10 pts (SHORT ANSWER) Define a function named findEvenOrOdd that has 1 int parameter: num. When the function is called, it should use an if/else statement -OR- conditional expression to determine whether the variable num is an even or odd number and display appropriate message as follows: • If the value in num is...

  • Can someone help me with this problem. We're using microsoft visual studios and its from my...

    Can someone help me with this problem. We're using microsoft visual studios and its from my assembly code language class. we're using this template in class from the lecture slides Write a program and verify it using visual studio that does the following: Use type, lengthof, and size to make your program more independent of the data type. 3) Write a program that first reads the message entered by the user and stores it in Myname. Then it prints the...

  • Can anyone help to solve this MIPS assembly language problem? Please help. Translate the fowlowwing C...

    Can anyone help to solve this MIPS assembly language problem? Please help. Translate the fowlowwing C code to MIPS assembly language. void main() { int i, sum, begin, end; for(i=0; i < 5; i++){ scanf(“%d, %d”, &begin, &end); sum = accum_range(begin, end); printf(“sum[%d: %d] = %d\n”, begin, end, sum); } int accum_range(int a, int b){ return accum (b) - accum(a); } int accum(int final) { int sum = 0; for (int I = 1; I <= final; I = I...

  • Please help me figure out why my code is not working properly.I had thought my logic...

    Please help me figure out why my code is not working properly.I had thought my logic was sound but later found it will run one time through fine however if the user opts to enter another value it will always be returned as an error. #include <iomanip> #include <iostream> #include <cstdlib> using namespace std; int const TRUE = 1; int const FALSE = 0; // declares functions void GetZipcode(); void RunAgain(); int GetSum(char d1, char d2, char d3, char d4,...

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