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.
Question: Write down the corresponding MIPS machine language of the following assembly language code. lw $S0,...
Question: Write down the corresponding MIPS machine language of the following assembly language code. lw $S0, 64($S1) add $t0,$S0,$S1 sub $t1,$S3,$S4 sw $t1,100($S1) addi $S4,$S6,100
2.  Suppose we have 3 arrays A, B, and C, array A’s base address is in $S3,...
2.  Suppose we have 3 arrays A, B, and C, array A’s base address is in $S3, B’s base address is in $S4, C’s base address is in $S5. You can only use two temporal registers $t0 and $t1. Convert the following code into MIPS assembly language code. Suppose every array element occupies 1 word in MIPS (32 bits). A[21] = B[0] + C[16];
Consider the following C statement:           a = (b + d) + (b – c) +...
Consider the following C statement:           a = (b + d) + (b – c) + (c + d) Which of the following assembly instructions can be used to replicate all or part of this statement in MIPS, without changing or reducing the equation. Assume variables a, b, c, and d are assigned to registers $s0, $s1, $s2 and $s3 respectively. sub $t0, $s2, $s3 sub $t0, $s0, $s3 sub $t1, $s1, $s2 add $t2, $s1, $s3 add $t2, $s0,...
For the MIPS assembly instructions below, what is the corresponding C statement? Assume that the variables...
For the MIPS assembly instructions below, what is the corresponding C statement? Assume that the variables f, g, h, and I are assigned to registers $s0 - $s3, respectively. Assume that the base address of arrays X, Y, and Z are in registers $s4 - $s6, respectively. Be conservative and use a single temp register as possible. It is a C arithmetic command with two source operands and a destination. Each part is 3 points. Add $t0, $s0, $s1 addi...
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.
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.
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...
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...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT