Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Convert the following function from C to MIPS assembly. It may be helpful to use

ID: 3725600 • Letter: C

Question

Convert the following function from C to MIPS assembly. It may be helpful to use basic blocks to outline your program (especially your loop). You are allowed to use MIPS pseudo-instructions e.g., blt, bgt, etc. Additionally, assume the array always has at least one element. Per convention, arr will be in $a0 and num_elements will be in $a1. int find_min(int arr[], int num_elements) { int i, min = arr[0]; for (i = 0; i < num_elements; i++) { if (arr[i] < min) { min = arr[i]; } } return min; }

Explanation / Answer

.file 1 "" .section .mdebug.abi32 .previous .nan legacy .module fp=32 .module nooddspreg .abicalls .text .align 2 .globl find_min .set nomips16 .set nomicromips .ent find_min .type find_min, @function find_min: .frame $fp,24,$31 # vars= 8, regs= 1/0, args= 0, gp= 8 .mask 0x40000000,-4 .fmask 0x00000000,0 .set noreorder .set nomacro addiu $sp,$sp,-24 sw $fp,20($sp) move $fp,$sp sw $4,24($fp) sw $5,28($fp) movz $31,$31,$0 lw $2,24($fp) nop lw $2,0($2) nop sw $2,12($fp) sw $0,8($fp) b $L2 nop $L4: lw $2,8($fp) nop sll $2,$2,2 lw $3,24($fp) nop addu $2,$3,$2 lw $3,0($2) lw $2,12($fp) nop slt $2,$3,$2 beq $2,$0,$L3 nop lw $2,8($fp) nop sll $2,$2,2 lw $3,24($fp) nop addu $2,$3,$2 lw $2,0($2) nop sw $2,12($fp) $L3: lw $2,8($fp) nop addiu $2,$2,1 sw $2,8($fp) $L2: lw $3,8($fp) lw $2,28($fp) nop slt $2,$3,$2 bne $2,$0,$L4 nop lw $2,12($fp) move $sp,$fp lw $fp,20($sp) addiu $sp,$sp,24 j $31 nop .set macro .set reorder .end find_min .size find_min, .-find_min .ident "GCC: (Ubuntu 5.4.0-6ubuntu1~16.04.9) 5.4.0 20160609"