MARS- MIPS Assembler and Runtime Simulator.
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.
please can you help me to solve it in Mips Assembly that works on Mars 4.5:...
The program I'm using is MIPS (mars) assembly; Write a program that in the main routine ask the user input n numbers(2<n<11) and pass n and array pointer to FillArray to stores numbers in the array. Main again passes the pointer to AddElement Function to add the elements of the array, and return the result back to main to print it.
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.
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 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() 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 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 =...
Please help me with MIPS programming language. Thank you 1) Write MIPS assembly for an array of words: array[12] = h + array[8]; Assume Map: $s2 = h $s3 = base address of array $t1 = temp 2) Write MIPS assembly for an array of words: g = h + array[i]; Assume Map: $s1 = g $s2 = h $s3 = base address of array $s4 = i
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...
IN MIPS PLEASE. Need help writing a MIPS program that reads from a text file named "input.txt" and places it in a buffer. A buffer of 80 bytes is more than enough. Before you call your function, set $a0 equal to the address of the filename and $a1 to the address of the buffer where data is stored. The function should return the number of bytes read in $v0. In the main program, print an error message and terminate the...
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...