QuestionQuestion

Originally, this project was going to require that you implement Bubble Sort over strings. However, it turned out that that project was too hard, so I simplified it. Instead of performing Bubble Sort, you will implement string compare (comparable to C’s standard function strcmp()) between strings that are on an array. This program has multiple modes; in one mode, you will print out all of the strings from an array; in another, you will print a single character from one of the strings in the array; in the last, you will compare two strings - and swap them in the array if they are out of order.

When writing MIPS assembly, the only instructions that you are allowed to use
(so far) are:
• add, addi, sub
• sll, srl, sra

Solution PreviewSolution Preview

These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction of bibliographies out of text citations and references. Students may use these solutions for personal skill-building and practice. Unethical use is strictly forbidden.

main:
# Function prologue -- even main has one
addiu $sp, $sp, -24   # allocate stack space -- default of 24 here
sw    $fp, 0($sp)    # save caller's frame pointer
sw    $ra, 4($sp)    # save return address
addiu $fp, $sp, 20    # setup main's frame pointer

lb $t0, mode # t0 = mode
beq $t0, 2, prntStr # if mode = 2, print the strings
beq $t0, 3, dblIdx # if mode = 3, do the double indexing task
beq $t0, 4, strCmp # if mode = 4, compare the strings and swap if needed

la $a0, errorMsg # printing the error message if mode is not equal to 2, 3 or 4
addi $v0, $zero, 4
syscall

j done

prntStr:
lb $t0, numStrs # t0 = numStrs
la $t1, strings # t1 = &(&strings[0])
nxt:
beq $t0, $zero, done# while t0 > 0
lw $t2, ($t1) # t2 = address of the next string in array

la $a0, ($t2) # print the next string
addi $v0, $zero, 4
syscall

la $a0, newLine # print the new line
addi $v0, $zero, 4
syscall

addi $t1, $t1, 4 # t1 += 4, points to the address of the next string of array
sub $t0, $t0, 1 # t0--
j nxt # end while

dblIdx:
lb $t0, s1 # t0 = s1
lh $t1, c # t1 = c
la $t2, strings # t2 = &(&strings[0])...

By purchasing this solution you'll be able to access the following files:
Solution.s.

$40.00
for this solution

or FREE if you
register a new account!

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available Assembly Language Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Decision:
Upload a file
Continue without uploading

SUBMIT YOUR HOMEWORK
We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats