MIPS Arrays
MIPS Arrays
CS@VT October 2009 Computer Organization I ©2006-09 McQuain, Feng & Ribbens
Array Example MIPS Arrays 2
.data
string_space: .space 1024
...
# prior to the loop, $t1 is set to the address of the first
# char in string_space, and $t2 is set to the last one
test_loop:
bge $t1, $t2, is_palin # if lower pointer >= upper
# pointer, yes
CS@VT October 2009 Computer Organization I ©2006-09 McQuain, Feng & Ribbens
Example 1: Array Traversal in C MIPS Arrays 3
// PrintList.c
#include <stdio.h>
int main() {
int Sz = 10;
int Array[10] = {1, 1, 2, 3, 5, 8, 13, 21, 34, 55};
int Pos = 0;
while ( Pos < Sz ) {
CS@VT October 2009 Computer Organization I ©2006-09 McQuain, Feng & Ribbens
Example 1: Array Traversal in MIPS MIPS Arrays 4
# PrintList.asm
.data
Sz: .word 10
Array: .word 1, 1, 2, 3, 5, 8, 13, 21, 34, 55
NL: .asciiz "\n"
.text
main:
lw $s7, Sz # get size of list
move $s1, $zero # set counter for # of elems printed
move $s2, $zero # set offset from Array
print_loop:
bge $s1, $s7, print_loop_end # stop after last elem is printed
CS@VT October 2009 Computer Organization I ©2006-09 McQuain, Feng & Ribbens
Example 2: C Bubblesort MIPS Arrays 5
int main() {
int Sz = 10;
int List[10] = {17, 5, 92, 87, 41, 10, 23, 55, 72, 36};
CS@VT October 2009 Computer Organization I ©2006-09 McQuain, Feng & Ribbens
Example 2: Analysis MIPS Arrays 6
CS@VT October 2009 Computer Organization I ©2006-09 McQuain, Feng & Ribbens
Example 2: MIPS Bubblesort MIPS Arrays 7
.data
Sz: .word 10
List: .word 17, 5, 92, 87, 41, 30, 23, 55, 72, 36
.text
main:
#################################################### bubble_sort
lw $s3, Sz # set outer loop limit
addi $s3, $s3, -1
CS@VT October 2009 Computer Organization I ©2006-09 McQuain, Feng & Ribbens
Example 2: MIPS Bubblesort MIPS Arrays 8
CS@VT October 2009 Computer Organization I ©2006-09 McQuain, Feng & Ribbens