Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

HELP PLEASE I WILL GIVE U THUMPS UP 2.3 (10 pts) [5] Translate the following C language instruction to MIPS assembly language: C[k] = A[i]+B[i-j];

HELP PLEASE I WILL GIVE U THUMPS UP

2.3 (10 pts) [5] Translate the following C language instruction to MIPS assembly language:

C[k] = A[i]+B[i-j];

This will require multiple MIPS commands: you will need to add, subtract, load, store, and multiply. For this problem we will use the conventional register names that we would see in real MIPS assembly code. There is a table here: http://www.cs.uwm.edu/classes/cs315/Bacon/Lecture/HTML/ch05s03.html#mips_regs_convention

Let us try and stay within $s0-$s7 for the starting addresses for the three arrays and the indices (i, j, k).

If we need temporary regisers for intermediate values, use any of the eight registers $t0 through $t7.

A command reference is found in Appendix A, section 10 (which is included in your zyBook).

The formulas behind each command can be found in the MIPS Reference Data card (found at mips_reference_data.pdf in the Extras & Helpful Info folder on Google Drive.

Assume that the variables have been loaded as follows into registers:

Variable

Register name

unused

$s0

i

$s1

j

$s2

k

$s3

unused

$s4

A

$s5

B

$s6

C

$s7

Lets talk about these registers a little more. For i, j, and k, the values in the $s registers are signed integers used as indices into the arrays. However, were on a 32-bit architecture in this book with MIPS, which is 4 bytes. Each array element thus takes 4 bytes. Therefore, we must multiply the index values by 4 before adding them to the base addresses for the arrays.

There are two ways to multiply by 4: muland sll. If you shift left with sll by 2 bits, its the same as multiplying by 4.

The contents of $s5, $s6 and $s7 is a positive integer that is an address of a specific bytein RAM where the array begins. Each element takes up 4 bytes, thus the need to hop by 4.

Offset commands are very helpful when indexing arrays or stacks, because they let you add or subtract right on the command line. 4($s0) means add 4 bytes to the address in $s0. -8($s0) means .

If we load or store a word using lw or sw, we need to only give the starting byte address; the system will take care of pulling or pushing the 4-byte block.

Lets go step-by-step.

Again the equation:

C[k] = A[i]+B[i-j];

For A[i]:

a. Put the value of iin a temporary register

b. Multiply it by 4 using slland shifting left by 2 bits, store it in your temp register.

c. Add the result to the base address for A, in $s5, and store it in your temp register.

d. Load the contents of that location from memory using lw, and place the result in a temp register.

For B[i-j]:

a. Subtract j from i by subtracting $s2 by $s1. Store the result in a temp register.

b. Multiply it by 4.

c. Add it to the starting address for array B, found in $s6.

d. Load that word from memory and store in a temp register.

For C[k]:

a. Calculate k*4, add it to Cs base address and store the resulting memory byte address in a temp variable.

b. Add the two parts from above from arrays A and B, and store in a temp register.

c. Store the result in the address from (a).

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_2

Step: 3

blur-text-image_3

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 Driven Web Sites

Authors: Joline Morrison, Mike Morrison

2nd Edition

? 061906448X, 978-0619064488

More Books

Students also viewed these Databases questions

Question

explain what is meant by experiential learning

Answered: 1 week ago