Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

can you help me complete the printArray procedure in this code .data myArray: .word 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 inputPrompt: .asciiz Enter the number of integers: numPrompt: .asciiz

can you help me complete the printArray procedure in this code

.data

myArray: .word 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0

inputPrompt: .asciiz "Enter the number of integers: "

numPrompt: .asciiz "Enter an integer: "

outputPrompt: .asciiz "The sorted array is: "

space: .asciiz " "

.text

main:

li $v0, 4

la $a0, inputPrompt

syscall

li $v0, 5

syscall

move $s0, $v0

la $a0, myArray

move $a1, $s0

jal read_array

la $a0, myArray

move $a1, $s0

jal sort

li $v0, 4

la $a0, outputPrompt

syscall

move $a1, $s0

jal print_array

j exit

read_array:

li $t0, 0

move $s1, $s0

la $s2, myArray

while:

bge $t0, $s1, endWhile

li $v0, 4

la $a0, numPrompt

syscall

li $v0, 5

syscall

sw $v0, 0($s2)

addi $s2, $s2, 4

addi $t0, $t0, 1

j while

endWhile:

move $v0, $s0

jr $ra

sort: # Two arguments: a0 for the starting address of the array; a1 is the number of integers

addi $sp,$sp,-20 # make room on stack for 5 registers

sw $ra, 16($sp) # save $ra on stack

sw $s3,12($sp) # save $s3 on stack

sw $s2, 8($sp) # save $s2 on stack

sw $s1, 4($sp) # save $s1 on stack

sw $s0, 0($sp) # save $s0 on stack

move $s2, $a0 # save $a0 into $s2

move $s3, $a1 # save $a1 into $s3

move $s0, $zero # i = 0

for1tst:

slt $t0, $s0, $s3 # $t0 = 0 if $s0 $s3 (i n)

beq $t0, $zero, exit1 # go to exit1 if $s0 $s3 (i n)

addi $s1, $s0,-1 # j = i 1

for2tst:

slti $t0, $s1, 0 # $t0 = 1 if $s1 < 0 (j < 0)

print_array: ### print the sorted array, myArray. The size of the array will be in a1. Use appropriate output text.

### ### you need to create a while loop

### ### Use t registers for counters and array indices ###

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

Advanced MySQL 8 Discover The Full Potential Of MySQL And Ensure High Performance Of Your Database

Authors: Eric Vanier ,Birju Shah ,Tejaswi Malepati

1st Edition

1788834445, 978-1788834445

More Books

Students also viewed these Databases questions