Please answer in MIPS assembly language only Write the follo

Please answer in MIPS assembly language only.

Write the following nested function calls: int Func(int a, int b, int c, int d){return Max(a+b, c-d);} int Max( int m, int n){if(m > n) {return m;} else {return n;}} Also, write a main program that calls the Func function on the following data and prints out the result. a = 0,  b = 2,  c = 8, and d = 3. Write a recursive function that computes the smallest integer in a given array of integers. Use the following algorithm: int Min( int[]A, int low, int high){if (low== high) {return A[low];} int mid = (low+high)/2; int min1 = Min(A, low, mid); int min2 = Min(A, mid +1, high); if(min1>min2) {return min2;} else {return min1;}} Also, write a main program that calls the Min function on the following data and prints out the result. A = {5, 2, -9, 10, -23, 43, 2, 1, 3, 5, 10},  low = 0, and high = 10.

Solution

Following is the code that uses nested calls and also computes the smallest integer in a given array of integers.

.file   1 \"\"
   .section .mdebug.abi32
   .previous
   .gnu_attribute 4, 1
   .abicalls
   .rdata
   .align   2
$LC0:
   .ascii   \"Enter size of the array: \\000\"
   .align   2
$LC1:
   .ascii   \"%d\\000\"
   .align   2
$LC2:
   .ascii   \"Enter %d elements in array: \\000\"
   .align   2
$LC3:
   .ascii   \"Minimum element in array = %d\\012\\000\"
   .align   2
$LC4:
   .ascii   \"Maximum element in array = %d\\012\\000\"
   .text
   .align   2
   .globl   main
$LFB0 = .
   .set   nomips16
   .ent   main
   .type   main, @function
main:
   .frame   $fp,448,$31       # vars= 416, regs= 2/0, args= 16, gp= 8
   .mask   0xc0000000,-4
   .fmask   0x00000000,0
   .set   noreorder
   .cpload   $25
   .set   nomacro
  
   addiu   $sp,$sp,-448
$LCFI0:
   sw   $31,444($sp)
$LCFI1:
   sw   $fp,440($sp)
   movz   $31,$31,$0
$LCFI2:
   move   $fp,$sp
$LCFI3:
   .cprestore   16
   lw   $2,%got($LC0)($28)
   nop
   addiu   $4,$2,%lo($LC0)
   lw   $2,%call16(printf)($28)
   nop
   move   $25,$2
   jalr   $25
   nop

   lw   $28,16($fp)
   addiu   $2,$fp,36
   lw   $3,%got($LC1)($28)
   nop
   addiu   $4,$3,%lo($LC1)
   move   $5,$2
   lw   $2,%call16(scanf)($28)
   nop
   move   $25,$2
   jalr   $25
   nop

   lw   $28,16($fp)
   lw   $2,36($fp)
   lw   $3,%got($LC2)($28)
   nop
   addiu   $4,$3,%lo($LC2)
   move   $5,$2
   lw   $2,%call16(printf)($28)
   nop
   move   $25,$2
   jalr   $25
   nop

   lw   $28,16($fp)
   sw   $0,24($fp)
   b   $L2
   nop

$L3:
   lw   $2,24($fp)
   addiu   $3,$fp,40
   sll   $2,$2,2
   addu   $2,$3,$2
   lw   $3,%got($LC1)($28)
   nop
   addiu   $4,$3,%lo($LC1)
   move   $5,$2
   lw   $2,%call16(scanf)($28)
   nop
   move   $25,$2
   jalr   $25
   nop

   lw   $28,16($fp)
   lw   $2,24($fp)
   nop
   addiu   $2,$2,1
   sw   $2,24($fp)
$L2:
   lw   $2,36($fp)
   lw   $3,24($fp)
   nop
   slt   $2,$3,$2
   andi   $2,$2,0x00ff
   bne   $2,$0,$L3
   nop

   lw   $2,36($fp)
   addiu   $3,$fp,40
   move   $4,$3
   move   $5,$0
   move   $6,$2
   lw   $2,%got(_Z7maximumPiii)($28)
   nop
   move   $25,$2
   jalr   $25
   nop

   lw   $28,16($fp)
   sw   $2,32($fp)
   lw   $2,36($fp)
   addiu   $3,$fp,40
   move   $4,$3
   move   $5,$0
   move   $6,$2
   lw   $2,%got(_Z7minimumPiii)($28)
   nop
   move   $25,$2
   jalr   $25
   nop

   lw   $28,16($fp)
   sw   $2,28($fp)
   lw   $2,%got($LC3)($28)
   nop
   addiu   $4,$2,%lo($LC3)
   lw   $5,28($fp)
   lw   $2,%call16(printf)($28)
   nop
   move   $25,$2
   jalr   $25
   nop

   lw   $28,16($fp)
   nop
   lw   $2,%got($LC4)($28)
   nop
   addiu   $4,$2,%lo($LC4)
   lw   $5,32($fp)
   lw   $2,%call16(printf)($28)
   nop
   move   $25,$2
   jalr   $25
   nop

   lw   $28,16($fp)
   move   $2,$0
   move   $sp,$fp
   lw   $31,444($sp)
   lw   $fp,440($sp)
   addiu   $sp,$sp,448
   j   $31
   nop

   .set   macro
   .set   reorder
   .end   main
$LFE0:
   .size   main, .-main
   .align   2
   .globl   _Z7maximumPiii
$LFB1 = .
   .set   nomips16
   .ent   _Z7maximumPiii
   .type   _Z7maximumPiii, @function
_Z7maximumPiii:
   .frame   $fp,40,$31       # vars= 8, regs= 2/0, args= 16, gp= 8
   .mask   0xc0000000,-4
   .fmask   0x00000000,0
   .set   noreorder
   .cpload   $25
   .set   nomacro
  
   addiu   $sp,$sp,-40
$LCFI4:
   sw   $31,36($sp)
$LCFI5:
   sw   $fp,32($sp)
   movz   $31,$31,$0
$LCFI6:
   move   $fp,$sp
$LCFI7:
   .cprestore   16
   sw   $4,40($fp)
   sw   $5,44($fp)
   sw   $6,48($fp)
   lw   $2,48($fp)
   nop
   addiu   $3,$2,-2
   lw   $2,44($fp)
   nop
   slt   $2,$2,$3
   bne   $2,$0,$L6
   nop

   lw   $2,44($fp)
   nop
   sll   $2,$2,2
   lw   $3,40($fp)
   nop
   addu   $2,$3,$2
   lw   $3,0($2)
   lw   $2,44($fp)
   nop
   addiu   $2,$2,1
   sll   $2,$2,2
   lw   $4,40($fp)
   nop
   addu   $2,$4,$2
   lw   $2,0($2)
   nop
   slt   $2,$2,$3
   beq   $2,$0,$L7
   nop

   lw   $2,44($fp)
   nop
   sll   $2,$2,2
   lw   $3,40($fp)
   nop
   addu   $2,$3,$2
   lw   $2,0($2)
   b   $L8
   nop

$L7:
   lw   $2,44($fp)
   nop
   addiu   $2,$2,1
   sll   $2,$2,2
   lw   $3,40($fp)
   nop
   addu   $2,$3,$2
   lw   $2,0($2)
   b   $L8
   nop

$L6:
   lw   $2,44($fp)
   nop
   addiu   $2,$2,1
   lw   $4,40($fp)
   move   $5,$2
   lw   $6,48($fp)
   lw   $2,%got(_Z7maximumPiii)($28)
   nop
   move   $25,$2
   jalr   $25
   nop

   lw   $28,16($fp)
   sw   $2,24($fp)
   lw   $2,44($fp)
   nop
   sll   $2,$2,2
   lw   $3,40($fp)
   nop
   addu   $2,$3,$2
   lw   $3,0($2)
   lw   $2,24($fp)
   nop
   slt   $2,$2,$3
   beq   $2,$0,$L9
   nop

   lw   $2,44($fp)
   nop
   sll   $2,$2,2
   lw   $3,40($fp)
   nop
   addu   $2,$3,$2
   lw   $2,0($2)
   b   $L8
   nop

$L9:
   lw   $2,24($fp)
$L8:
   move   $sp,$fp
   lw   $31,36($sp)
   lw   $fp,32($sp)
   addiu   $sp,$sp,40
   j   $31
   nop

   .set   macro
   .set   reorder
   .end   _Z7maximumPiii
$LFE1:
   .size   _Z7maximumPiii, .-_Z7maximumPiii
   .align   2
   .globl   _Z7minimumPiii
$LFB2 = .
   .set   nomips16
   .ent   _Z7minimumPiii
   .type   _Z7minimumPiii, @function
_Z7minimumPiii:
   .frame   $fp,40,$31       # vars= 8, regs= 2/0, args= 16, gp= 8
   .mask   0xc0000000,-4
   .fmask   0x00000000,0
   .set   noreorder
   .cpload   $25
   .set   nomacro
  
   addiu   $sp,$sp,-40
$LCFI8:
   sw   $31,36($sp)
$LCFI9:
   sw   $fp,32($sp)
   movz   $31,$31,$0
$LCFI10:
   move   $fp,$sp
$LCFI11:
   .cprestore   16
   sw   $4,40($fp)
   sw   $5,44($fp)
   sw   $6,48($fp)
   lw   $2,48($fp)
   nop
   addiu   $3,$2,-2
   lw   $2,44($fp)
   nop
   slt   $2,$2,$3
   bne   $2,$0,$L12
   nop

   lw   $2,44($fp)
   nop
   sll   $2,$2,2
   lw   $3,40($fp)
   nop
   addu   $2,$3,$2
   lw   $3,0($2)
   lw   $2,44($fp)
   nop
   addiu   $2,$2,1
   sll   $2,$2,2
   lw   $4,40($fp)
   nop
   addu   $2,$4,$2
   lw   $2,0($2)
   nop
   slt   $2,$3,$2
   beq   $2,$0,$L13
   nop

   lw   $2,44($fp)
   nop
   sll   $2,$2,2
   lw   $3,40($fp)
   nop
   addu   $2,$3,$2
   lw   $2,0($2)
   b   $L14
   nop

$L13:
   lw   $2,44($fp)
   nop
   addiu   $2,$2,1
   sll   $2,$2,2
   lw   $3,40($fp)
   nop
   addu   $2,$3,$2
   lw   $2,0($2)
   b   $L14
   nop

$L12:
   lw   $2,44($fp)
   nop
   addiu   $2,$2,1
   lw   $4,40($fp)
   move   $5,$2
   lw   $6,48($fp)
   lw   $2,%got(_Z7minimumPiii)($28)
   nop
   move   $25,$2
   jalr   $25
   nop

   lw   $28,16($fp)
   sw   $2,24($fp)
   lw   $2,44($fp)
   nop
   sll   $2,$2,2
   lw   $3,40($fp)
   nop
   addu   $2,$3,$2
   lw   $3,0($2)
   lw   $2,24($fp)
   nop
   slt   $2,$3,$2
   beq   $2,$0,$L15
   nop

   lw   $2,44($fp)
   nop
   sll   $2,$2,2
   lw   $3,40($fp)
   nop
   addu   $2,$3,$2
   lw   $2,0($2)
   b   $L14
   nop

$L15:
   lw   $2,24($fp)
$L14:
   move   $sp,$fp
   lw   $31,36($sp)
   lw   $fp,32($sp)
   addiu   $sp,$sp,40
   j   $31
   nop

   .set   macro
   .set   reorder
   .end   _Z7minimumPiii
$LFE2:
   .size   _Z7minimumPiii, .-_Z7minimumPiii
   .section   .eh_frame,\"aw\",@progbits
$Lframe1:
   .4byte   $LECIE1-$LSCIE1
$LSCIE1:
   .4byte   0x0
   .byte   0x1
   .globl   __gxx_personality_v0
   .ascii   \"zP\\000\"
   .uleb128 0x1
   .sleb128 -4
   .byte   0x1f
   .uleb128 0x5
   .byte   0x0
   .4byte   __gxx_personality_v0
   .byte   0xc
   .uleb128 0x1d
   .uleb128 0x0
   .align   2
$LECIE1:
$LSFDE1:
   .4byte   $LEFDE1-$LASFDE1
$LASFDE1:
   .4byte   $LASFDE1-$Lframe1
   .4byte   $LFB0
   .4byte   $LFE0-$LFB0
   .uleb128 0x0
   .byte   0x4
   .4byte   $LCFI0-$LFB0
   .byte   0xe
   .uleb128 0x1c0
   .byte   0x4
   .4byte   $LCFI2-$LCFI0
   .byte   0x11
   .uleb128 0x1e
   .sleb128 2
   .byte   0x11
   .uleb128 0x1f
   .sleb128 1
   .byte   0x4
   .4byte   $LCFI3-$LCFI2
   .byte   0xd
   .uleb128 0x1e
   .align   2
$LEFDE1:
$LSFDE3:
   .4byte   $LEFDE3-$LASFDE3
$LASFDE3:
   .4byte   $LASFDE3-$Lframe1
   .4byte   $LFB1
   .4byte   $LFE1-$LFB1
   .uleb128 0x0
   .byte   0x4
   .4byte   $LCFI4-$LFB1
   .byte   0xe
   .uleb128 0x28
   .byte   0x4
   .4byte   $LCFI6-$LCFI4
   .byte   0x11
   .uleb128 0x1e
   .sleb128 2
   .byte   0x11
   .uleb128 0x1f
   .sleb128 1
   .byte   0x4
   .4byte   $LCFI7-$LCFI6
   .byte   0xd
   .uleb128 0x1e
   .align   2
$LEFDE3:
$LSFDE5:
   .4byte   $LEFDE5-$LASFDE5
$LASFDE5:
   .4byte   $LASFDE5-$Lframe1
   .4byte   $LFB2
   .4byte   $LFE2-$LFB2
   .uleb128 0x0
   .byte   0x4
   .4byte   $LCFI8-$LFB2
   .byte   0xe
   .uleb128 0x28
   .byte   0x4
   .4byte   $LCFI10-$LCFI8
   .byte   0x11
   .uleb128 0x1e
   .sleb128 2
   .byte   0x11
   .uleb128 0x1f
   .sleb128 1
   .byte   0x4
   .4byte   $LCFI11-$LCFI10
   .byte   0xd
   .uleb128 0x1e
   .align   2
$LEFDE5:
   .ident   \"GCC: (Debian 4.4.5-8) 4.4.5\"

Please answer in MIPS assembly language only. Write the following nested function calls: int Func(int a, int b, int c, int d){return Max(a+b, c-d);} int Max( in
Please answer in MIPS assembly language only. Write the following nested function calls: int Func(int a, int b, int c, int d){return Max(a+b, c-d);} int Max( in
Please answer in MIPS assembly language only. Write the following nested function calls: int Func(int a, int b, int c, int d){return Max(a+b, c-d);} int Max( in
Please answer in MIPS assembly language only. Write the following nested function calls: int Func(int a, int b, int c, int d){return Max(a+b, c-d);} int Max( in
Please answer in MIPS assembly language only. Write the following nested function calls: int Func(int a, int b, int c, int d){return Max(a+b, c-d);} int Max( in
Please answer in MIPS assembly language only. Write the following nested function calls: int Func(int a, int b, int c, int d){return Max(a+b, c-d);} int Max( in
Please answer in MIPS assembly language only. Write the following nested function calls: int Func(int a, int b, int c, int d){return Max(a+b, c-d);} int Max( in
Please answer in MIPS assembly language only. Write the following nested function calls: int Func(int a, int b, int c, int d){return Max(a+b, c-d);} int Max( in
Please answer in MIPS assembly language only. Write the following nested function calls: int Func(int a, int b, int c, int d){return Max(a+b, c-d);} int Max( in

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site