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

Write and test a MIPS program consisting of four functions. In the following des

ID: 3739348 • Letter: W

Question

Write and test a MIPS program consisting of four functions. In the following descriptions, the symbol & means "address of" 1. void main0: The main function must 1) print your name 2) call the readData function 3) call count function 4) complete the program. The main function must set up all parameters before calling each of the functions 2. int readData (&array;): The starting address of an array is passed to the function as a parameter using Sa0. The function must prompt for and read and store integers in the array until either a zero is entered or 10 numbers are read. Once the tenth integer is entered, your program must stop reading. The function must return (using Sv0) the number of values read and stored in the array (10 or less). The zero input is not part of the array and must not be stored in the array. If the first input is a zero, then the array will be empty and the count returned is zero

Explanation / Answer

ANS:-

  

# note that .set,.type etc should be removed to execute as they are not MIPS

  comm   arr,40,4            .comm   i,4,4          .rdata          .align  2  $LC0:          .ascii  "%d"          .text          .align  2          .globl  read          .set    nomips16          .set    nomicromips          .ent    read          .type   read, @function  read:          .frame  $fp,32,$31              # vars= 0, regs= 2/0, args= 16, gp= 8          .mask   0xc0000000,-4          .fmask  0x00000000,0          .set    noreorder          .cpload $25          .set    nomacro          addiu   $sp,$sp,-32          sw      $31,28($sp)          sw      $fp,24($sp)          move    $fp,$sp          .cprestore      16          movz    $31,$31,$0          sw      $4,32($fp)          lw      $2,%got(i)($28)          nop          sw      $0,0($2)          b       $L2          nop    $L4:          lw      $2,%got(i)($28)          nop          lw      $2,0($2)          nop          addiu   $3,$2,1          lw      $2,%got(i)($28)          nop          sw      $3,0($2)  $L2:          lw      $2,%got(i)($28)          nop          lw      $2,0($2)          nop          sll     $2,$2,2          lw      $3,32($fp)          nop          addu    $2,$3,$2          move    $5,$2          lw      $2,%got($LC0)($28)          nop          addiu   $4,$2,%lo($LC0)          lw      $2,%call16(__isoc99_scanf)($28)          nop          move    $25,$2          .reloc  1f,R_MIPS_JALR,__isoc99_scanf  1:      jalr    $25          nop            lw      $28,16($fp)          beq     $2,$0,$L3          nop            lw      $2,%got(i)($28)          nop          lw      $2,0($2)          nop          sll     $2,$2,2          lw      $3,32($fp)          nop          addu    $2,$3,$2          lw      $2,0($2)          nop          bne     $2,$0,$L4          nop    $L3:          lw      $2,%got(i)($28)          nop          lw      $2,0($2)          move    $sp,$fp          lw      $31,28($sp)          lw      $fp,24($sp)          addiu   $sp,$sp,32          j       $31          nop            .set    macro          .set    reorder          .end    read          .size   read, .-read          .align  2          .globl  count          .set    nomips16          .set    nomicromips          .ent    count          .type   count, @function  count:          .frame  $fp,8,$31               # vars= 0, regs= 1/0, args= 0, gp= 0          .mask   0x40000000,-4          .fmask  0x00000000,0          .set    noreorder          .cpload $25          .set    nomacro          addiu   $sp,$sp,-8          sw      $fp,4($sp)          move    $fp,$sp          lw      $2,%got(i)($28)          nop          movz    $31,$31,$0          lw      $2,0($2)          move    $sp,$fp          lw      $fp,4($sp)          addiu   $sp,$sp,8          j       $31          nop    #       .set    macro          .set    reorder          .end    count          .size   count, .-count          .rdata          .align  2  $LC1:          .ascii  "Rahul Panda"          .text          .align  2          .globl  main  #       .set    nomips16  #       .set    nomicromips  #       .ent    main  #       .type   main, @function  main:          .frame  $fp,32,$31              # vars= 0, regs= 2/0, args= 16, gp= 8          .mask   0xc0000000,-4          .fmask  0x00000000,0          .set    noreorder          .cpload $25          .set    nomacro          addiu   $sp,$sp,-32          sw      $31,28($sp)          sw      $fp,24($sp)          move    $fp,$sp          .cprestore      16          movz    $31,$31,$0          lw      $2,%got($LC1)($28)          nop          addiu   $4,$2,%lo($LC1)          lw      $2,%call16(printf)($28)          nop          move    $25,$2          .reloc  1f,R_MIPS_JALR,printf  1:      jalr    $25          nop            lw      $28,16($fp)          nop          lw      $4,%got(arr)($28)          lw      $2,%got(read)($28)          nop          move    $25,$2          .reloc  1f,R_MIPS_JALR,read  1:      jalr    $25          nop            lw      $28,16($fp)          nop          lw      $2,%got(count)($28)          nop          move    $25,$2          .reloc  1f,R_MIPS_JALR,count  1:      jalr    $25          nop            lw      $28,16($fp)          move    $5,$2          lw      $2,%got($LC0)($28)          nop          addiu   $4,$2,%lo($LC0)          lw      $2,%call16(printf)($28)          nop          move    $25,$2          .reloc  1f,R_MIPS_JALR,printf  1:      jalr    $25          nop            lw      $28,16($fp)          nop          move    $sp,$fp          lw      $31,28($sp)          lw      $fp,24($sp)          addiu   $sp,$sp,32          j       $31          nop  

# note that .set,.type etc should be removed to execute as they are not MIPS

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