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

Need a writing program in Mars Mips The third program will demonstrate how to im

ID: 669322 • Letter: N

Question

Need a writing program in Mars Mips

The third program will demonstrate how to implement loops in MIPS. Your program should read from memory the contents of an array containing an arbitrary number of non-negative integer values, followed by a single negative value that acts as a sentinel. Your program should count the number of even values, the number of odd values, and the total number of values, and store these counts in three separate integer variables. (Do not include the sentinel value as part of any count.) Test your program using arrays of various lengths.

Explanation / Answer

.data
   .align 2
item:    .word 1
   .word 2
   .word 3
   .word 4
   .word 5
   .word 6
   .word 7
   .word 8
   .word 9
   .word 10
   .align 0
str:    .asciiz "The answer is "   ;this would print total array values sum
cr:   .asciiz " "
   .text
   .align 2
   .globl main
main:   ori $2, $0, 5
   syscall
   move $t0, $2

   la $t2, item           ; base address loading of item array into $t2
   beq $0, $t0, even       ;input==0 , then continue with even
oloop:   lw $t3, ($t2)       ; odd loop---load array value into $t3
   add $t1, $t1, $t3       ;addition t1 = t1+t3
   beq $t3, 9, done      
   addi $t2, $t2, 8      
   j oloop
even:   addi $t2, $t2, 4
eloop:   lw $t3, ($t2) ;even loop
   add $t1, $t1, $t3
   beq $t3, 10, done
   addi $t2, $t2, 8
   j eloop

done:    ori $2, $0, 4 ; pritning results finally
   la $4, str
   syscall
   ori $2, $0, 1
   add $4, $t1, $0
   syscall
   ori $2, $0, 4
   la $4, cr
   syscall

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