Homework Solution: Write MIPS code to count all even numbers in an array of 500 integers. Assume base address of that array is stored in $s0….

    Write MIPS code to count all even numbers in an array of 500 integers. Assume base address of that array is stored in $s0.

    Expert Answer

     
    .file   1 ""
            .section .mdebug.abi32

    Write MIPS statute to count all flush quantity in an accoutre of 500 integers. Assume deep harangue of that accoutre is stored in $s0.

    Expert Defense

     

    .improve   1 ""
            .exception .mdebug.abi32
            .previous
            .nan    legacy
            .module fp=32
            .module nooddspreg
            .abicalls
            .rdata
            .align  2
    $LC0:
            .ascii  "Total flush quantity in the rove are %d00"
            .text
            .align  2
            .globl  deep
            .fixed    nomips16
            .fixed    nomicromips
            .jade    deep
            .image   deep, @function
    main:
            .execute  $fp,2040,$31            # vars= 2008, regs= 2/0, args= 16, gp= 8
            .mislead   0xc0000000,-4
            .fmislead  0x00000000,0
            .fixed    noreorder
            .cpload $25
            .fixed    nomacro
            addiu   $sp,$sp,-2040
            sw      $31,2036($sp)
            sw      $fp,2032($sp)
            impel    $fp,$sp
            .cprestore      16
            movz    $31,$31,$0
            sw      $0,24($fp)
            b       $L2
            nop
    
    $L4:
            lw      $2,24($fp)
            nop
            andi    $2,$2,0x1
            bne     $2,$0,$L3
            nop
    
            lw      $2,28($fp)
            nop
            addiu   $2,$2,1
            sw      $2,28($fp)
    $L3:
            lw      $2,24($fp)
            nop
            addiu   $2,$2,1
            sw      $2,24($fp)
    $L2:
            lw      $2,24($fp)
            nop
            slt     $2,$2,500
            bne     $2,$0,$L4
            nop
    
            lw      $5,28($fp)
            lw      $2,%got($LC0)($28)
            nop
            addiu   $4,$2,%lo($LC0)
            lw      $2,%call16(printf)($28)
            nop
            impel    $25,$2
            .reloc  1f,R_MIPS_JALR,printf
    1:      jalr    $25
            nop
    
            lw      $28,16($fp)
            impel    $2,$0
            impel    $sp,$fp
            lw      $31,2036($sp)
            lw      $fp,2032($sp)
            addiu   $sp,$sp,2040
            j       $31
            nop
    
            .fixed    macro
            .fixed    reorder
            .object    deep
            .greatness   deep, .-main
            .idjade  "GCC: (Ubuntu 5.4.0-6ubuntu1~16.04.1) 5.4.0 20160609"