Question

Lab-3B Two-Way Branch Write a MIPS program to read a positive integer and to determine and...

Lab-3B Two-Way Branch

Write a MIPS program to read a positive integer and to determine and display whether it is an even number or odd.

A positive integer X is odd if its last digit is 1. Otherwise X is odd if X AND 1 is 1, or in other words X is even if X AND 1 is 0.

Example Input/Output

Give a positive number X= 41

X is an odd number

Give a positive number X= 40

X is an even number

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

Given below is the code for the question. Please do rate the answer if it helped. Thank you.


.data
   inMsg: .asciiz "Give a positive number X = "
   oddMsg: .asciiz "X is an odd number"
   evenMsg: .asciiz "X is an even number"

.text
   #print string
   li $v0, 4
   la $a0, inMsg
   syscall
  
  
   #read int
   li $v0, 5
   syscall
   move $t0, $v0
  
   and $t1, $t0, 1
   beq $t1, 1, odd
even:
   #print string
   li $v0, 4
   la $a0, evenMsg
   syscall
   b exit
odd:
   #print string
   li $v0, 4
   la $a0, oddMsg
   syscall

exit:
   #exit
   li $v0, 10
   syscall
  

======
output
------

Give a positive number X = 41
X is an odd number
-- program is finished running --

Give a positive number X = 40
X is an even number
-- program is finished running --

Add a comment
Know the answer?
Add Answer to:
Lab-3B Two-Way Branch Write a MIPS program to read a positive integer and to determine and...
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
  • Write a complete C++ program that do following. 1) Read a positive integer from the user...

    Write a complete C++ program that do following. 1) Read a positive integer from the user with proper prompt. Assume that this user is nice and he/she would not start the integer with digit 0. 2) Create a size 10 array as counters for digits 0 - 9. 3) Use a while loop for processing a) Single out the current last digit using modular 10 technique b) Increment the corresponding counter through the index derived in a). 4) At the...

  • Program : Write a complete C++ program that Input: Read a positive integer from the keyboard...

    Program : Write a complete C++ program that Input: Read a positive integer from the keyboard (user) with proper prompt text and save it to a variable. The integer have up to five digits. Processing: From the right most digit, extract every digit from the input integer using modular operator %then save the digit to a separate variable. Remove the right most digit from the integer using integer division operator /. Repeat above two steps till all digits have been...

  • the user should be prompted to enter an integer and then your program will produce another...

    the user should be prompted to enter an integer and then your program will produce another integer depending on whether the input was even or odd. The following is an example of what you might see when you run the program; the input you type is shown in green (press Enter at the end of a line), and the output generated by the program is shown in black text. Enter an integer: 1234 Number is even, taking every other digit...

  • Question 4 (3 mark) : Write a Java program to ask the user to input an...

    Question 4 (3 mark) : Write a Java program to ask the user to input an integer number from the keyboard. The output should indicate whether it is positive, zero, or negative, an even number or an odd number. REQUIREMENTS • Your code should ask user to input an integer number, then decide its sign and parity based on this input. • Your code should use if-else statement. Your code must work exactly as the specification and the output should...

  • A java program Write a program that prompts for and reads in a positive    integer...

    A java program Write a program that prompts for and reads in a positive    integer into a variable n. Your program should then sum    the first n ODD integers and display the sum. For    example, if 3 is entered for n, your program should display    the the sum 1 + 3 + 5. If 5 is entered, your program should    display the sum 1 + 3 + 5 + 7 + 9. What is the...

  • 4.14 LAB: Convert to binary Write a program that takes in a positive integer as input,...

    4.14 LAB: Convert to binary Write a program that takes in a positive integer as input, and outputs a string of 1's and 0's representing the integer in binary. For an integer x, the algorithm is: As long as x is greater than 0 Output x % 2 (remainder is either 0 or 1) x = x / 2 Note: The above algorithm outputs the 0's and 1's in reverse order. Ex: If the input is: 6 the output is:...

  • 5.14 LAB: Convert to binary Write a program that takes in a positive integer as input,...

    5.14 LAB: Convert to binary Write a program that takes in a positive integer as input, and outputs a string of 1's and 0's representing the integer in binary. For an integer x, the algorithm is: As long as x is greater than 0 Output x modulo 2 (remainder is either 0 or 1) Assign x with x divided by 2 Note: The above algorithm outputs the 0's and 1's in reverse order. Ex: If the input is: 6 the...

  • python la ab X, X Lab 7 Design and implement a Python program that uses a...

    python la ab X, X Lab 7 Design and implement a Python program that uses a while loop and selection statements to print the sum of the even numbers and the sum of the odd numbers (all integers) read from the keyboard. The sequence of numbers ends with a negative number: So, all numbers considered for printing the two sums are greater than or equal to 0. The sequence may be empty. Here is a possible interaction. Enter an integer:...

  • Introduction: In this lab, you will write a MIPS program to read in (up to) 50...

    Introduction: In this lab, you will write a MIPS program to read in (up to) 50 integer values from the user, store them in an array, print out the amay, one number per line, reverse the elements in the array and finally print out the elements in the just-reversed) array. Feel free to do this lab and all assembly programming labs) in Windows. You must use MARS Getting started: l. In MARS, create a new assembly file with the name...

  • Edit: Not sure what more information you need. Write a MIPS assembly program to determine the...

    Edit: Not sure what more information you need. Write a MIPS assembly program to determine the range between pairs of numbers. Keep things very basic with instructions such as load (lw), store (sw), add (addi and add), subtract (sub), multiplication (mul), branch (beq and bne), jump (j), and set on less than (slt) instructions. Your program should meet the following functional requirements: Input: an arbitrary number of integer pairs (in all pairs, the first number will be the max value)...

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