Question

In: Computer Science

Prompt user to enter an integer number from console. Use 3 methods to check if this...

Prompt user to enter an integer number from console. Use 3 methods to check if this number is even or odd. Display result.

This is required to be done in MIPS assembly language.

Solutions

Expert Solution

Please up vote ,comment if any query . Thanks for Question . Be safe .

Note : check attached image for output ,code compiled and tested in MARS MIPS simulator.

Program Plan :

  1. to read input call getInput function use syscall 4 to prompt string
  2. syscall 1 to read integer input and return from function
  3. now call checkEvenOdd function if num is odd it will return 0 else 1
  4. call display result to print number is odd/even .
  5. terminate program .

Program :

.data
   even:    .asciiz "Number is even.\n"
   odd:    .asciiz "Number is odd.\n"
   prompt: .asciiz "Enter number : "
  
  
.text
   main:
       #call method to get input from user
       #user input from return from function stored in $v0
       jal getInput
       #$a0 is argument register
      
       addi $a0,$v0,0 #move user input($v0) in $a0
       #pass user input to function checkEvenOdd
       #if value is even it will 1 else return 0
       #return value in $v0
       jal checkEvenOdd
       #move return value in $a0
       addi $a0,$v0,0
       #call displayResult to print number is even or odd
       jal displayResult
      
       #terminate program using syscall 10
       li $v0,10
       syscall
      
      
#method getInput       
getInput:
   la $a0,prompt #load address of prompt string in $a0 register
   li $v0,4 #syscall 4 to print string
   syscall
  
   #read input stored in $v0
   li $v0,5
   syscall
   #return to address save in $ra (address of code section from it called)
   jr $ra

#function to check user input odd or even
checkEvenOdd:
   li $t0,2 #load 2 in $t0 register
   div $a0,$t0 #divide user input $a0 by 2($a0) and result stored in lo(quotient) and hi(reminder) register
  
   mfhi $t0 #store reminder of above divide in $t0
  
   seq $v0,$t0,0 #if $t0==0 set 1 to $v0 else set 0 to $v0
  
   jr $ra #return value of $v0 and go to addres from it called
  
#function displayResult to print result  
displayResult:
   #if argument $a0 is 0 than jump to printOdd label else go to next line print even
   beq $a0,0,printOdd
   la $a0,even #load address of even in $a0
   li $v0,4 #syscall 4 to print string
   syscall
   j return #jump to return label
    printOdd: #print odd label
       la $a0,odd #load address of odd string
       la $v0,4 #syscall 4 to print string
       syscall
      
    return: #return label
       jr $ra  
  
      
  
  

Output :   

Please comment if you want any changes . up vote ,


Related Solutions

Prompt user to enter an integer number from console. Use 2 methods to multiply this number...
Prompt user to enter an integer number from console. Use 2 methods to multiply this number by factor 7, display result. This is required to be done in MIPS Assembly Language.
Prompt the user to enter an integer Then, prompt the user to enter a positive integer...
Prompt the user to enter an integer Then, prompt the user to enter a positive integer n2. Print out all the numbers that are entered after the last occurrence of n1 and whether each one is even or odd If n1 does not occur or there are no values after the last occurrence of n1, print out the message as indicated in the sample runs below. Sample: Enter n1: -2 Enter n2: 7 Enter 7 values: -2 3 3 -2...
4. Prompt user to enter a double number from console. Round this number so it will...
4. Prompt user to enter a double number from console. Round this number so it will keep 2 places after the decimal point. Display new number. For example, number 12.3579 will round to 12.36; number 12.4321 will round to 12.43 This is meant to be written in Java 14.0
Prompt user to enter 2 integer numbers from console, compare and display these 2 numbers from...
Prompt user to enter 2 integer numbers from console, compare and display these 2 numbers from small to great. This is required to be done in MIPS assembly language.
A. Write a program 1. Prompt the user to enter a positive integer n and read...
A. Write a program 1. Prompt the user to enter a positive integer n and read in the input. 2. Print out n of Z shape of size n X n side by side which made up of *. B. Write a C++ program that 1. Prompt user to enter an odd integer and read in the value to n. 2. Terminate the program if n is not odd. 3. Print out a cross shape of size n X n...
Create a C++ program that will prompt the user to input an integer number and output...
Create a C++ program that will prompt the user to input an integer number and output the corresponding number to its numerical words. (From 0-1000000 only) **Please only use #include <iostream>, switch and if-else statements only and do not use string storing for the conversion in words. Thank you.** **Our class is still discussing on the basics of programming. Please focus only on the basics. Thank you.** Example outputs: Enter a number: 68954 Sixty Eight Thousand Nine Hundred Fifty Four...
Write a PowerShell script which will prompt user to enter the number of the day of...
Write a PowerShell script which will prompt user to enter the number of the day of the week (e.g. 1,2,3,4,5,6,7) and return the day of the week. (e.g. Sunday...etc.) (Hint: Sunday is the 1st day of the week).
Use a while(true) loop to ask the user to “Enter a non-negative integer (enter negative integer...
Use a while(true) loop to ask the user to “Enter a non-negative integer (enter negative integer to quit):” and store this into an int named n. If the user enters a negative int for n, the while loop is broken via the brake statement. Otherwise, in the remaining part of the while loop, use a for loop to compute the sum of the inverse factorials from 0 to n, that is sum = 1/0! + 1/1! + 1/2! + ....
JAVA Programming Implement the class DataProcess and prompt a user to enter 5 integer numbers. Once...
JAVA Programming Implement the class DataProcess and prompt a user to enter 5 integer numbers. Once The program should output the average, largest, and smallest of 5 numbers. You must implement the methods listed below in your program. static float getAverage(int[] data) {...} static int getLargest(int[] data) {...} static int getSmallest(int[] data) {...}
Nice Number Programming: Nice program ask user to enter three integers from keyboard (java console), the...
Nice Number Programming: Nice program ask user to enter three integers from keyboard (java console), the three integers represent left bound, right bound and arbitrary digit ‘m’, where left bound is less than right bound. Program should print all nice numbers in the given range that doesn’t contain digit 'm'. The number is nice if its every digit is larger than the sum of digits which are on the right side of that digit. For example 741 is a nice...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT