Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Program the code using MARS simulator. How to fix the code without using size? .data array: .word 0,0,0,0,0,0,0,0,0,0 #size: .word 0 str1: .asciiz How many

Program the code using MARS simulator.

How to fix the code without using size?

.data array: .word 0,0,0,0,0,0,0,0,0,0 #size: .word 0 str1: .asciiz "How many number you like to enter: " str2: .asciiz "Enter number " str3: .asciiz "Error Invalid number, Please try again!! " str4: .asciiz "The median is: " .text main:

li $v0, 4 la $a0, str1 syscall

li $v0, 5 syscall blt $v0,1,notInRange bgt $v0,10,notInRange add $t0, $v0,$0 #la $s1, size

sw $t0, 0($s1) la $s0, array

li $t2,0 loop: add $t2,$t2,1 beq $t0, $0, done li $v0, 4 la $a0,str2 syscall

li $v0, 5 syscall sw $v0, 0($s0) addi $t0, $t0, -1 addi $s0, $s0, 4 j loop

done:

exit: #lw $s0,size la $s1,array div $t0,$s0,2 #divide number by two mfhi $t1 #get reminder beqz $t1,evenNumbers #if reminder is zero it is even number #odd numbers of elements mul $t1,$t0,4 #get integer index add $t1,$t1,$s1 #get base address of integer index A[mid] lw $t1,($t1) j print evenNumbers: mul $t1,$t0,4 #get integer index add $t1,$t1,$s1 #get base address of integer index A[mid] lw $t3,($t1) #get mid two numbers lw $t2,-4($t1) add $t1,$t3,$t2 #add them div $t1,$t1,2 #divide by two

print: li $v0,4 la $a0,str4 syscall

li $v0,1 move $a0,$t1 syscall

li $v0, 10 syscall

notInRange: li $v0,4 la $a0,str3 #it will print prompt syscall j main

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle 10g SQL

Authors: Joan Casteel, Lannes Morris Murphy

1st Edition

141883629X, 9781418836290

More Books

Students also viewed these Databases questions

Question

=+c. Savings as the Star focus on price.

Answered: 1 week ago