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

Translate C++ Merge function into MIPS assembly language. Clarification: The obj

ID: 3804048 • Letter: T

Question

Translate C++ Merge function into MIPS assembly language.

Clarification:

The objective of this problem is to translate the merge method written in C++ (which takes an array of two, adjacent sorted arrays i.e. [1,2,3,4,5,12,13,14,15,16] and sorts the array into one sorted array) into MIPS Assembly language. So essentially, a conversion of the code written above into MIPS

int c[100]; //c[100] is a global array

void merge(int a[], int low, int high, int mid){

int i, j, k;

i = low;

k = low;

j = mid + 1;

while (i <= mid && j <= high){

if (a[i] < a[j]) {

c[k] = a[i];

k++;

i++;

}

else {

c[k] = a[j];

k++; j++;

}

}

while (i <= mid){

c[k] = a[i];

k++;

i++;

}

while (j <= high){

c[k] = a[j];

k++;

j++;

}

for (i = low; i < k; i++){

a[i] = c[i];

}

Explanation / Answer

file 1 "" .section .mdebug.abi32 .previous .gnu_attribute 4, 1 .abicalls .text .align 2 .globl _Z5mergePiiii $LFB0 = . .set nomips16 .ent _Z5mergePiiii .type _Z5mergePiiii, @function _Z5mergePiiii: .frame $sp,0,$31 # vars= 0, regs= 0/0, args= 0, gp= 0 .mask 0x00000000,0 .fmask 0x00000000,0 .set noreorder .cpload $25 .set nomacro addiu $3,$7,1 addiu $9,$5,1 sll $2,$5,2 lw $11,%got(c)($28) nop movz $31,$31,$0 addu $11,$11,$2 move $10,$11 b $L2 move $2,$5 $L6: sw $12,0($10) b $L3 addiu $2,$2,1 $L19: addiu $3,$3,1 $L3: addiu $9,$9,1 addiu $10,$10,4 $L2: slt $12,$7,$2 bne $12,$0,$L4 addiu $8,$9,-1 slt $12,$6,$3 bne $12,$0,$L5 move $13,$3 sll $8,$2,2 addu $8,$4,$8 lw $12,0($8) sll $8,$3,2 addu $8,$4,$8 lw $8,0($8) nop slt $13,$12,$8 bne $13,$0,$L6 nop b $L19 sw $8,0($10) $L4: b $L8 move $13,$3 $L9: lw $12,0($10) nop sw $12,0($9) addiu $8,$8,1 addiu $2,$2,1 addiu $10,$10,4 slt $12,$7,$2 beq $12,$0,$L9 addiu $9,$9,4 $L8: slt $2,$6,$13 bne $2,$0,$L10 sll $2,$8,2 sll $7,$13,2 addu $7,$4,$7 lw $9,%got(c)($28) nop addu $2,$9,$2 $L11: lw $9,0($7) nop sw $9,0($2) addiu $8,$8,1 addiu $3,$3,1 addiu $7,$7,4 slt $9,$6,$3 beq $9,$0,$L11 addiu $2,$2,4 $L10: slt $2,$5,$8 beq $2,$0,$L21 sll $5,$5,2 addu $5,$4,$5 sll $8,$8,2 addu $4,$4,$8 $L13: lw $2,0($11) nop sw $2,0($5) addiu $5,$5,4 bne $5,$4,$L13 addiu $11,$11,4 $L21: j $31 nop $L5: sll $10,$2,2 addu $10,$4,$10 sll $9,$8,2 lw $12,%got(c)($28) b $L9 addu $9,$12,$9 .set macro .set reorder .end _Z5mergePiiii $LFE0: .size _Z5mergePiiii, .-_Z5mergePiiii .globl c .section .bss,"aw",@nobits .align 2 .type c, @object .size c, 400 c: .space 400 .ident "GCC: (Debian 4.4.5-8) 4.4.5"

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote