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 ) > 0) i++;
let a= s0, b= s1, d[a]= s2, whileb is not considered let c= s1
a) bgez $s0, $s1, greater \\ if (a > b)
blez $s0, $s1, smaller \\ if (a < b)
greater: addu $s2, $s1, 8 \\ d[a] = b + 8
smaller: sub $s2, $s1,16 \\ d[a] = b - 16
b) ori $s5, $s0, 0 \\ i=0
la $s6, d \\ $s6= d;
l1: bge $s5, $s1, done \\ i<a
lw s7 ,0($s6) \\ $s7= d[i]
addu $s0, $s7, $s1 \\ a = d[i] + c
j update
update: addi $s5, $s5, 1 \\ i++
addi $s6, $s6, 4
j l1
done: .data \\ initialize data
c) ori $s5, $s0, 0 \\ i=0
lw $s7 ,0($s6) \\ $s7= d[i]
l1: bne $s7, $s1, done
sub $s4, $s0, $s5
ble $s4, done
add $s1, $s1, 1
j l1
done: exit
Get Answers For Free
Most questions answered within 1 hours.