Sunteți pe pagina 1din 3

  TEXTBOOK SOLUTIONS EXPERT Q&A

home / study / engineering / computer science / computer science questions and answers / 1. write a mips assembly language program that asks …

Question: 1. Write a MIPS assembly language program that asks the use…

1. Write a MIPS assembly language program that asks the user for 20 integers, bubblesorts them, and then
prints them out in ascending order.
2. When printing you will need to add a space between each number printed.

Expert Answer
Anonymous answered this
Was this answer helpful?
36 answers

MIPS PROGRAM :-

.data

prompt: .ascii "Please enter a number :"

print_prompt: .ascii "The array in ascending order : "

space_c: .ascii " "

arr: .space 80

.text

main:

li $t0,0

li $t1,20

la $s0,arr

LOOP:

beq $t0,$t1,OUT_OF_LOOP

li $v0,4

la $a0,prompt

syscall

li $v0,5

syscall

move $s1,$v0

sw $s1,0($s0)

addi $s0,$s0,4

addi $t0,$t0,1

j LOOP

OUT_OF_LOOP:

li $s1,20

li $s2,0

li $s3,4

la $t1,arr

SORTING_LOOP:

beq $s1,$s2,PRINT_ARRAY

add $t1,$t1,$s2

lw $t0,0($t1) #a[i]

L3: beq $s3,$s1,incc

add $t1,$t1,$s3

lw $t2,0($t1) #a[j]

slt $t3,$t0,$t2

beq $t3,$0,swap
L4: addi $s3,$s3,4

j L3

swap:

sw $t0,0($t1)

sub $t1,$t1,$s2

sw $t2,0($t1)

j L4

incc:

addi $s2,$s2,4

j SORTING_LOOP

PRINT_ARRAY:

li $t0,0

li $t1,20

la $s0,arr

li $v0,4

la $a0,print_prompt

syscall

PRINT_LOOP:

beq $t0,$t1,END_EXIT

li $v0,1

sw $a0,0($s0)

syscall

li $v0,4

la $a0,space_c

syscall

addi $s0,$s0,4

addi $t0,$t0,1

j PRINT_LOOP

END_EXIT:

li $v0,10

syscall


View comments (2)

ABOUT CHEGG LEGAL CHEGG PRODUCTS AND SERVICES CHEGG NETWORK CUSTOMER SERVICE

Become a Tutor Advertising Choices Cheap Textbooks Online Tutoring CareerMatch Customer Service
Chegg For Good Cookie Notice Chegg Coupon Sell Textbooks Easybib Give Us Feedback
College Marketing General Policies Updated Chegg Play Solutions Manual Internships.com Help with Chegg Tutors
Corporate Development Intellectual Property Rights Chegg Study Help Study 101 Studyblue Help with eTextbooks
Investor Relations International Privacy Policy College Textbooks Test Prep Help to use EasyBib Plus
Jobs Terms of Use Updated eTextbooks Textbook Rental Manage Chegg Study
Join Our Affiliate Program Chegg Tutors Terms of Chegg Math Solver Used Textbooks Subscription

Media Center Service Mobile Apps Digital Access Codes Return Your Books

Site Map US Privacy Policy Textbook Return Policy


Your CA Privacy Rights
© 2003-2019 Chegg Inc. All rights reserved.

S-ar putea să vă placă și