Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

who can explain this MIPS code in details every step. I need to understand every line of this code. The comments didnt help me. its

who can explain this MIPS code in details every step. I need to understand every line of this code. The comments didnt help me. its simple code, need to input 10 numbers and output in order(from big to small ) Thnx in advance !

.data

array:

.space 40

separate:

.asciiz " "

line:

.asciiz " "

.text

.globl main

main:

la $t0, array #starting address

add $t1, $zero, $t0

addi $t8, $t0, 40 #terminating address

inputData:

li $v0, 5 #inputing the integers

syscall

sw $v0, 0($t1) #saving the array

addi $t1, $t1, 4

addi $t3, $t3, 1 #incrementing

slti $s0, $t3, 10 #if less then 10,continue the input of data

bnez $s0, inputData

addi $t3, $zero, 0 #outter loop counter

outLoop:

add $t1, $zero, $t0

slti $s0, $t3, 10 #inner loop counter

beqz $s0, print #if i > 10 terminate

addi $t4, $t3, -1 #j = i - 1

inLoop:

slti $s0, $t4, 0 #if j < 0 exit the inner loop

bnez $s0, exitInLoop

sll $t5, $t4, 2

add $t5, $t1, $t5

lw $t6, 0($t5) #$t6 = a[j]

lw $t7, 4($t5) #$t7 = a[j + 1]

slt $s0, $t6, $t7 #a[j] < a[j + 1] swaping

bnez $s0, swap

addi $t4, $t4, -1 #j--

j inLoop

swap:

sw $t6, 4($t5) #$t6 = a[j + 1]

sw $t7, 0($t5) #$t7 = a[j]

addi $t4, $t4, -1

j inLoop

exitInLoop:

addi $t3, $t3, 1

j outLoop

print:

lw $a0, 0($t0)

li $v0, 1

syscall

la $a0, separate

li $v0, 4

syscall

addi $t0, $t0, 4

bne $t0, $t8, print

la $a0, line

li $v0, 4

syscall

j exit

exit:

li $v0, 10

syscall

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

Sybase Database Administrators Handbook

Authors: Brian Hitchcock

1st Edition

0133574776, 978-0133574777

More Books

Students also viewed these Databases questions