Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Put Your Data To Work 52 Tips And Techniques For Effectively Managing Your Database

Authors: Wes Trochlil

1st Edition

0880343079, 978-0880343077

More Books

Students also viewed these Databases questions