Question

We assume the following $s0 = a $s1 = b $s2 = c $s3 = i...

We assume the following

$s0 = a

$s1 = b

$s2 = c

$s3 = i

$s4 = address of ar[0]

Write MIPS assembly code for the following C code.

for (i = 10; i < 30; i ++)

{

if ((ar[i] > b) || (ar[i] <= c))

ar[i] = 0;

else

ar[i] = a;

}

Homework Answers

Answer #1
# $s0 = a, $s1 = b, $s2 = c, $s3 = i, $s4 = address of ar[0]

li $s3, 0  # i = 0
for:   bge $s3, 30, end   # for (i < 30)
   
   sll $t0, $s3, 2       # i indexable
   add $t0, $t0, $s4  # $t0 = &ar[i]
   lw  $t1, 0($t0)       # $t1 = ar[i]
   
   bgt $t1, $s1, if   # if (ar[i] > b)
   ble $t1, $s2, if   # if  (ar[i] <= c)
   
   sw $s0, 0($t0) # else - ar[i] = a;
   j end
   if:
      sw $zero, 0($t0)   # if - ar[i] = 0;
   end:
   
   addi $s3, $s3, 1   # i++
   j for
end:
Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Assume that $s1 = 0x87654321. Determine the content of registers $s2 to $s4 after executing the...
Assume that $s1 = 0x87654321. Determine the content of registers $s2 to $s4 after executing the following instructions: sll $s2,$s1, 16 # $s2 = srl $s3,$s1, 8 # $s3 = sra $s4,$s1, 12 # $s4 = Write mips assembly language program to execute these instructions and verify the content of registers $s2 to $s4. COMMENT COMPLETE CODE PLEASE
Assume that $s1 = 0x87654321. Determine the content of registers $s2 to $s4 after executing the...
Assume that $s1 = 0x87654321. Determine the content of registers $s2 to $s4 after executing the following instructions: sll $s2,$s1, 16 # $s2 = srl $s3,$s1, 8 # $s3 = sra $s4,$s1, 12 # $s4 = Write a mips assembly language program to execute these instructions and verify the content of registers $s2 to $s4.
2. (7 pts) Translate the following block of C code to MIPS assembly: if (i >...
2. (7 pts) Translate the following block of C code to MIPS assembly: if (i > 10) MemArray[i] = 0; else MemArray[i] = - MemArray[i]; Assume that the variable i is bound to register $t0, and that the base address of array MemArray is in register $s0.
Let S = {s1, s2, s3, s4, s5, s6} be the sample space associated with the...
Let S = {s1, s2, s3, s4, s5, s6} be the sample space associated with the experiment having the following probability distribution. (Enter your answers as fractions.) Outcome s1 s2 s3 s4 s5 s6 Probability 3 12 1 12 4 12 1 12 2 12 1 12 (a) Find the probability of A = {s1, s3}. (b) Find the probability of B = {s2, s4, s5, s6}. (c) Find the probability of C = S.
This is a homework assignment for Computer Architecture and some question use MIPS Assembly language. 1.    ...
This is a homework assignment for Computer Architecture and some question use MIPS Assembly language. 1.     In the following MIPS assembly code, translate all the instructions to their corresponding machine code in hexadecimal format. This code is stored in the memory from address 0x1fff0000. Loop: sw $t1, 4($s0)        addi $t1, $t1, -1    sll $t1, $t1, 2        bne $t1, $s5, Exit    addi $s0, $s0, 4          j Loop Exit: … 2.     Find the MIPS...
State of Nature Decision Alternative s1 s2 s3 s4 d1 600 400 -100 120 d2 700...
State of Nature Decision Alternative s1 s2 s3 s4 d1 600 400 -100 120 d2 700 -200 0 400 d3 700 -200 0 400 P(si) 0.3 0.4 0.2 0.1 For a lottery having a payoff 700 with probability p and -200 with probability (1-p), the decision maker expressed the following indifference probability. Suppose U (700) =100 and U (-200) =-10. Payoff Indifferent Probability 600 0.95 400 0.8 120 0.5 0 0.35 -100 0.2 a) Complete the utility table by using...
SUPPLIER Sno Sname Status City s1 Smith 20 London s2 Jones 10 Paris s3 Blake 30...
SUPPLIER Sno Sname Status City s1 Smith 20 London s2 Jones 10 Paris s3 Blake 30 Paris s4 Clark 20 London s5 Adams 30 NULL PART Pno Pname Color Weight City p1 Nut Red 12 London p2 Bolt Green 17 Paris p3 Screw NULL 17 Rome p4 Screw Red 14 London p5 Cam Blue 12 Paris p6 Cog Red 19 London SHIPMENT Sno Pno Qty Price s1 p1 300 .005 s1 p2 200 .009 s1 p3 400 .004 s1 p4...
The C++ program steps through the array x[]. For each i, if x[i] < x[i+1], i...
The C++ program steps through the array x[]. For each i, if x[i] < x[i+1], i is saved in the array ascend[], in order. Compile and run the program; it should print 0 4 5. In this exercise, you’ll try to translate the C++ program to MIPS. Some of the more tedious parts are already given in Assignment3.F19.s. You won’t have to write the data allocation sections, some of the initializations, and the output loop at the end. So the...
(MIPS Assembly Language): Write the following sequence of code using *native* MIPS instructions: x = x...
(MIPS Assembly Language): Write the following sequence of code using *native* MIPS instructions: x = x - y[0] + y[1]; In memory x, y are stored beginning at 0x010000cc. Use registers $s1 for x,  and $s2 for the base address of y. Make sure your code includes all necessary declarations such that it could run in SPIM.
Convert each of the below C code snippet to LEGv8 assembly code. Assume variable a, b,...
Convert each of the below C code snippet to LEGv8 assembly code. Assume variable a, b, and c is stored in registers X19, X20, and X21 respectively. Base address of d is stored in register X22. Comment your assembly code. (24 Points) a. if (a > b) d[a] = b + 8; else d[a] = b - 16; b. for (i=0;i<a; i++) a = d[i] + c; c. i = 0; while ( d[i] == b) if(( a - i...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT