Assignment 4 1. Discuss the importance and value of register Sv0 when using sysc
ID: 3890450 • Letter: A
Question
Assignment 4 1. Discuss the importance and value of register Sv0 when using syscall 2. Write a program in MIPS assembly language that implements the following a. Ask the user to input his/her name b. Greet the user with his/her name and ask for an integer. The message should look like "Hello (user name), please input an integer and press Enter." c. If the integer is odd print "The integer is odd" d. If the integer is even print "The integer is even" e. Terminate with politely greeting the user using his/her name. The message should look like "Goodbye (user name), thank you for your input"Explanation / Answer
Given below is the MIPS code for the question. Output is shown. Please rate the answer if it helped. Thank you.
.data
name: .space 25
prompt: .asciiz " Please enter your name: "
hello: .asciiz " Hello "
input: .asciiz "Please input an integer and press Enter "
goodbye: .asciiz " Goodbye "
thanku: .asciiz "Thank you for your input"
oddmsg: .asciiz "The integer is odd "
evenmsg: .asciiz "The integer is even "
.text
#prompt for name and get string input
li $v0, 4
la $a0, prompt
syscall
li $v0, 8
la $a0, name #address where to stroe string input
li $a1, 25 #the max length
syscall
#greet the user and prompt for int input
li $v0, 4
la $a0, hello
syscall
#display name
li $v0, 4
la $a0, name
syscall
li $v0, 4
la $a0, input
syscall
#get int input and save to $t0
li $v0, 5
syscall
move $t0, $v0
#find out if the number is odd or even. div by 2 and if remainder is 0, its even
li $t1, 2 #load the number 2 into $t1
div $t0, $t1 #quotient is in low and remainder in hi
mfhi $t1 #get the remainder into t1
beqz $t1, display_even
#display odd msg
li $v0, 4
la $a0, oddmsg
syscall
b finish
display_even:
#display even msg
li $v0, 4
la $a0, evenmsg
syscall
finish:
#say good bye
li $v0, 4
la $a0, goodbye
syscall
li $v0, 4
la $a0, name
syscall
li $v0, 4
la $a0, thanku
syscall
#exit
li $v0, 10
syscall
output
Please enter your name: Raji
Hello Raji
Please input an integer and press Enter 5
The integer is odd
Goodbye Raji
Thank you for your input
-- program is finished running --
Please enter your name: Raji
Hello Raji
Please input an integer and press Enter 8
The integer is even
Goodbye Raji
Thank you for your input
-- program is finished running --