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;
}
# $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:
Get Answers For Free
Most questions answered within 1 hours.