Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Exercise 1 a Counting Loop Write an MIPS program that computes the sum of the integers from 1 to 100 by addition: 1 + 2

Exercise 1 a Counting Loop

Write an MIPS program that computes the sum of the integers from 1 to 100 by addition: 1 + 2 + 3 + 4 + 5 + ... + 98 + 99 + 100 Do this by using the blt macro (branch if less than). Before the loop, initialize a register to zero to contain the sum, initialize another register to one (to be the counter), and another register to 101 to mark the end of the sequence. Inside the loop, add the counter to the sum, increment the counter and blt back to the top of the loop if the counter is less than 101. Single-step the program until you get a good idea of how it is working. Then let the program run. To stop the program, use syscall with the code 10 in $v0. Exercise 2 more counting

Extend your program from exercise 1 to compute three sums: 1 + 2 + 3 + 4 + ... + 99 + 100 # all values 1100 1 + 3 + 5 + 7 + ... + 97 + 99 # all odd values 1100 2 + 4 + 6 + 8 + ... + 98 + 100 # all even values 1100 Use a register (say $t0) for the sum of evens, a register (say $t1) for the sum of odds, and another (say $t2) for the sum of all numbers. Do this with only one counting loop. The loop body will contain the logic to add the count to the proper sums. Don't use division to check odd or even, it is not necessary. A bitwise instruction is enough. Again, stop the program with a syscall with 10 in $v0.

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

Select Healthcare Classification Systems And Databases

Authors: Katherine S. Rowell, Ann Cutrell

1st Edition

0615909760, 978-0615909769

More Books

Students also viewed these Databases questions

Question

What are the Five Phases of SDLC? Explain each briefly.

Answered: 1 week ago

Question

How can Change Control Procedures manage Project Creep?

Answered: 1 week ago