Question: MIPS using MARS simulator Write a program that asks the user to enter the number of integers that needs to be added together. Then you

MIPS using MARS simulator

Write a program that asks the user to enter the number of integers that needs to be added together. Then you use the loop to get the integers check to see if they are even and add them together.

MIPS

.data

num: .asciiz "How many numbers do you want to add\t "

.text

main:

la $a0, num #system call to print str

li $v0, 4 #adress of string to print

syscall

li $s0, 0 #$s0 has the value of 0

li $s2, 2 #$s2 has the value of 2

li $v0, 5 #system call to read an integer from user --> $v0 (5) User inputs 5

syscall #executes

add $t0,$0,$v0 #store num from user from $v0 to $t0 ----> $t1 has user input which is 5 COUNTER

Loop: beq $s0, $t0,L1

li $v0, 5 #system call to read an integer from user --> $v0 (5) User inputs numbers

syscall #executes

add $t3,$0,$v0 #store user input from $v0 ---> $t3

L1: add $s0,$s0,1 #updates the counter

div $t3, $s2 #dividing by 2

mfhi $t1 #remainder goes to high assigns remainder to register $t1

bne $t1, $0, L2 #checking if remainder is and if $t1 = 0 then add even number

add $t4, $0, $t3

L2: j Loop #if odd num go back to Loop

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!