Convert the highlevel function from Exercise 618 into MIPS a
Convert the high-level function from Exercise 6.18 into MIPS assembly code. Solution to 6.18, which you will need: int find42(int array[], int size) {int i; for (i = 0; i
Solution
Given C Program :-
int find42(int array[] ,int size)
{
int i
for(i=0;i<size;i++)
{
if(array[i]==42)
return i;
}
return -1;
}
MIPS Assembly Code :-
$Ltext0:
$LFB0 = .
find42(int*, int):
addiu $sp,$sp,-16
sw $fp,12($sp)
move $fp,$sp
sw $4,16($fp)
sw $5,20($fp)
sw $0,4($fp)
$L5:
lw $3,4($fp)
lw $2,20($fp)
slt $2,$3,$2
beq $2,$0,$L2
nop
lw $2,4($fp)
sll $2,$2,2
lw $3,16($fp)
addu $2,$3,$2
lw $3,0($2)
li $2,42 # 0x2a
bne $3,$2,$L3
nop
lw $2,4($fp)
b $L4
nop
$L3:
lw $2,4($fp)
addiu $2,$2,1
sw $2,4($fp)
b $L5
nop
$L2:
li $2,-1 # 0xffffffffffffffff
$L4:
move $sp,$fp
lw $fp,12($sp)
addiu $sp,$sp,16
j $31
nop
$LFE0:
$Letext0:
$Ldebug_info0:
$Ldebug_abbrev0:
$Ldebug_line0:
$LASF0:
$LASF1:
$LASF3:
$LASF4:
$LASF2:
$LASF5:
![Convert the high-level function from Exercise 6.18 into MIPS assembly code. Solution to 6.18, which you will need: int find42(int array[], int size) {int i; fo Convert the high-level function from Exercise 6.18 into MIPS assembly code. Solution to 6.18, which you will need: int find42(int array[], int size) {int i; fo](/WebImages/1/convert-the-highlevel-function-from-exercise-618-into-mips-a-966877-1761495156-0.webp)