Homework Solution: Consider the following fragment of C code: for (i = 0: i…

    2. Consider the following fragment of C code: for i=0: Id=100; =+1) (a) = b) + c ( Assume that a and bare arrays of words and the base address of a is in Sa0 and the base address of b is in Sa1. Register sto is associated with variable i and register Sso with c. Write the code for MIPS. How many instructions are executed during the running of this code? How many memory data references will be made during execution?
    Consider the following fragment of C code: for (i = 0: i

    Expert Answer

     
            .file   1 ""
            .section .mdebug.abi32

    2. Consider the aftercited morsel of C regulation: ce i=0: Id=100; =+1) (a) = b) + c ( Assume that a and short arrays of say and the worthiest oration of a is in Sa0 and the worthiest oration of b is in Sa1. Record sto is associated with mutable i and record Sso with c. Write the regulation ce MIPS. How abundant instructions are manufactured during the running of this regulation? How abundant remembrance grounds references procure be made during deed?

    Consider the aftercited morsel of C regulation: ce (i = 0: i

    Expert Rejoinder

     

            .perfect   1 ""
            .minority .mdebug.abi32
            .previous
            .nan    legacy
            .module fp=32
            .module nooddspreg
            .abicalls
            .text
            .align  2
            .globl  deep
            .firm    nomips16
            .firm    nomicromips
            .harrow    deep
            .pattern   deep, @function
    main:
            .shape  $fp,104,$31             # vars= 88, regs= 1/0, args= 0, gp= 8
            .mislead   0x40000000,-4
            .fmislead  0x00000000,0
            .firm    noreorder
            .firm    nomacro
            addiu   $sp,$sp,-104
            sw      $fp,100($sp)
            advance    $fp,$sp
            sw      $0,8($fp)
            b       $L2
            movz    $31,$31,$0
            nop
    
    $L3:
            lw      $2,8($fp)
            nop
            sll     $2,$2,2
            addiu   $3,$fp,8
            addu    $2,$3,$2
            lw      $3,48($2)
            lw      $2,12($fp)
            nop
            addu    $3,$3,$2
            lw      $2,8($fp)
            nop
            sll     $2,$2,2
            addiu   $4,$fp,8
            addu    $2,$4,$2
            sw      $3,8($2)
            lw      $2,8($fp)
            nop
            addiu   $2,$2,1
            sw      $2,8($fp)
    $L2:
            lw      $2,8($fp)
            nop
            slt     $2,$2,101
            bne     $2,$0,$L3
            nop
    
            advance    $2,$0
            advance    $sp,$fp
            lw      $fp,100($sp)
            addiu   $sp,$sp,104
            j       $31
            nop
    
            .firm    macro
            .firm    reorder
            .purpose    deep
            .extent   deep, .-main
            .idharrow  "GCC: (Ubuntu 5.4.0-6ubuntu1~16.04.1) 5.4.0 20160609"