Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Note: Your solutions are not required to be finished, MARS-ready programs for the issues listed below. Instead, create program slivers. (But, if you decide to

Note: Your solutions are not required to be finished, MARS-ready programs for the issues listed below. Instead, create program slivers. (But, if you decide to include the additional code required to execute your programs in MARS, kindly provide the entire scripts.) You're not required to design whole assembly-language processes, but you should assume that inputs will be in $a registers and results will be in $v registers when your programs begin. (That is, you don't have to worry about saving registers to memory before using them or about switching to another operation after you're done.) Program variables should be mapped to $s registers, and intermediate results should be stored in $t registers. At the conclusion of each line, include succinct comments that describe what is occurring.

1. Convert the following code snippet to MIPS assembly. Suppose that at program startup, register $a0 contains array a's base address.

if(a[] == 5)

a[0] = 0;

else a[1] = a[1] -2;

2. Create an assembly code sequence that, given a non-negative integer for n, will calculate 2n. Suppose n is in $a0 at program startup, and place the outcome in $v0. For a hint, multiply 1 by n and then by n2. Your code must execute successfully when n is 0 to receive full credit.

3. The number of 1 bits in an integer's binary representation can be calculated by writing a series of assembly instructions. As an illustration, the output for an input of 199 should be 5, as the binary encoding of 199 (11000111) contains 5 ones. Leave the outcome in $v0 and presuming that the corresponding integer is in $a0 at program startup. Hint: Shift, then repeatedly scrutinize the bit with the least significance (on the right).

 

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

Database Concepts

Authors: David M Kroenke, David J Auer

6th Edition

0132742926, 978-0132742924

More Books

Students also viewed these Databases questions

Question

What is DDL?

Answered: 1 week ago