complete code for this selection sort. .data values: .word 20 prompt1: .asciiz "\n Enter a value and press enter: \n" pr

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899604
Joined: Mon Aug 02, 2021 8:13 am

complete code for this selection sort. .data values: .word 20 prompt1: .asciiz "\n Enter a value and press enter: \n" pr

Post by answerhappygod »

complete code for this selection sort.
.data
values: .word 20
prompt1: .asciiz "\n Enter a value and press enter: \n"
prompt2: .asciiz "\n Your Array Is: \n"
breakline: .asciiz "\n"
.text
main:
addi $s0, $zero, 41
addi $s1, $zero, 35
addi $s2, $zero, 64
addi $s3, $zero, 11
addi $s4, $zero, 50

addi $t0, $zero, 0

sw $s0, values($t0)
addi $t0, $t0, 4
sw $s1, values($t0)
addi $t0, $t0, 4
sw $s2, values($t0)
addi $t0, $t0, 4
sw $s3, values($t0)
addi $t0, $t0, 4
sw $s4, values($t0)

addi $t0, $zero, 0

li $s0, 20 #size
li $t0, 0 #i = 0
add $t1, $t0, 1 #j = i+1

#after populating array
jal fori
fori:
beq $t0, $t1, printArray

j forj
forj:
beq $t1, $t1, fori

j forj
#Displaying message "Your Array
Is:"
li $v0, 4
la $a0, prompt2
syscall

printArray:
beq $t0, 20, exit_print #when the end of array
is reached, jump to exit_print method to end printArray loop
lw $t6, values($t0)
addi $t0, $t0, 4 #noving pointer 4 spaces
forward to the next value
li $v0, 1
move $a0, $t6
syscall

#breaking line
li, $v0, 4
la, $a0, breakline
syscall

j printArray

exit_print:
li $v1, 0
syscall
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply