MIPS Programming Assignment: Bubble Sort, Euclidean Algorithm, Strings

Verified

Added on  2023/04/24

|7
|495
|393
Homework Assignment
AI Summary
This document presents a solution to a MIPS programming assignment. The solution includes implementations of several key algorithms and programming concepts. Specifically, it provides the MIPS assembly code for a bubble sort algorithm, designed to sort a sequence of numbers. Additionally, the assignment incorporates the Euclidean algorithm, a method for computing the greatest common divisor of two integers, demonstrating the use of functions and control flow in MIPS. The solution also addresses string comparison, showcasing how to compare strings and handle string data within the MIPS environment. The code is well-commented, and the document also includes data segments for strings and integer values used in the program. The code demonstrates how to use the syscall function to print output and read input in MIPS assembly language. The assignment covers fundamental MIPS programming principles and provides practical examples of algorithm implementation.
Document Page
Running head: PROGRAMMING IN MIPS
Programming in MIPS
Name of the Student
Name of the University
Author Note
tabler-icon-diamond-filled.svg

Secure Best Marks with AI Grader

Need help grading? Try our AI Grader for instant feedback on your assignments.
Document Page
1
PROGRAMMING IN MIPS
Bubble Sort:
move $t0, $a0
li $s0, 1
li $t1, 0
li $t2, 0
li $s1, 9
loop:
beqz $s0, exit
li $s0, 0
addiu $t1, $t1, 1
move $t2, $0
subu $s2, $s1, $t1
forLoop:
bge $t2, $s2, exitForLoop
lw $a0, 0($t0)
lw $a1, 4($t0)
ble $a0, $a1, update
sw $a1, 0($t0)
sw $a0, 4($t0)
Document Page
2
PROGRAMMING IN MIPS
li $s0, 1
update:
addiu $t2, $t2, 1
sll $t3, $t2, 2
addu $t0, $t0, $t3
j forLoop
exitForLoop:
j loop
exit:
jr $ra
Comparing Ingredients
.data
str1: .asciiz "Comp"
str2: .asciiz "Comp"
.text
main:
la $s2, str1
la $s3, str2
move $s6, $s2
Document Page
3
PROGRAMMING IN MIPS
move $s7, $s3
li $s1, 5
beq $s6, $s7, exit
move $a0, $s1
li $v0, 1
syscall
exit:
li $v0, 10
syscall
Euclidean’s Algorithm
.text
.globl main
main:
sub $sp,$sp,8
sw $ra,0($sp)
li $v0,4
la $a0,pow
syscall
li $v0,5
syscall
tabler-icon-diamond-filled.svg

Secure Best Marks with AI Grader

Need help grading? Try our AI Grader for instant feedback on your assignments.
Document Page
4
PROGRAMMING IN MIPS
move $t2,$v0
li $v0,4
la $a0,bas
syscall
li $v0,5
syscall
move $a0,$t2
move $a1,$v0
jal euc
sw $v0,4($sp)
li $v0,4
la $a0,str
syscall
li $v0,1
lw $a0,4($sp)
syscall
lw $ra,0($sp)
add $sp,$sp,8
jr $ra
.data
Document Page
5
PROGRAMMING IN MIPS
str:
.asciiz "value = “
bas:
.asciiz "second integer = "
pow:
.asciiz "first integer = "
.text
euc:
sub $sp,$sp,4
sw $s0,0($sp)
bne $a1,$zero,L1
j EXIT
L1:
beq $a1, $zero, EXIT
move $t4,$a1
rem $a1,$a0,$a1
move $a0,$t4
j L1
EXIT:
move $v0,$a0
Document Page
6
PROGRAMMING IN MIPS
lw $s0,0($sp)
add $sp,$sp,4
jr $ra
chevron_up_icon
1 out of 7
circle_padding
hide_on_mobile
zoom_out_icon
logo.png

Your All-in-One AI-Powered Toolkit for Academic Success.

Available 24*7 on WhatsApp / Email

[object Object]