%!PS-Adobe-1.0 %%DocumentFonts: Courier %%Title: array.s (mpage) %%Creator: mpage %%CreationDate: Mon Feb 1 10:38:00 1999 %%Pages: (atend) %%BoundingBox: 20 20 596 776 %%EndComments /mp_stm usertime def /mp_pgc statusdict begin pagecount end def statusdict begin /jobname (array.s) def end /Courier findfont 11 scalefont setfont (a) stringwidth pop /mp_a_x exch def (\t'a' length ) print mp_a_x == flush %%EndProlog %%Page: 1 1 save 0 setlinewidth 20 20 moveto 20 772 lineto 592 772 lineto 592 20 lineto closepath stroke 20 396 moveto 592 396 lineto stroke gsave 24 768 translate -90 rotate 368 80 mp_a_x mul div 564 792 div scale 0 -4 moveto 0 792 lineto 80 mp_a_x mul 792 lineto 80 mp_a_x mul -4 lineto closepath clip 0 mp_a_x mul 780 moveto (# CS 2734, Fall 1999) show 0 mp_a_x mul 768 moveto (# Array loop examples, using index and using pointer) show 0 mp_a_x mul 756 moveto (# Print 10 integers) show 0 mp_a_x mul 744 moveto (# address of A and later B is in $s5) show 8 mp_a_x mul 720 moveto (.globl main) show 0 mp_a_x mul 708 moveto (main: # main has to be a global label) show 8 mp_a_x mul 696 moveto (addu $s7, $0, $ra # save return address in global register) show 8 mp_a_x mul 672 moveto (la $s5, A # $s5 has the starting address of A) show 0 mp_a_x mul 660 moveto (## Start of simple loop example) show 8 mp_a_x mul 648 moveto (addi $s3, $zero, 0 # s3 = 0, used for index i) show 8 mp_a_x mul 636 moveto (addi $s4, $zero, 10 # s4 = 10) show 0 mp_a_x mul 600 moveto (Loop:) show 8 mp_a_x mul 588 moveto (add $t1, $s3, $s3 # Temporary register $t1 = 2*i ) show 8 mp_a_x mul 576 moveto (add $t1, $t1, $t1 # Double again so temporary register has 4*i) show 8 mp_a_x mul 564 moveto (add $t1, $t1, $s5 # Add A start address so t1 has addr of A[i]) show 8 mp_a_x mul 552 moveto (lw $t0, 0\($t1\) # Temporary register $t0 has value of A[i]) show 0 mp_a_x mul 540 moveto (## Print array element and a blank) show 8 mp_a_x mul 528 moveto (li $v0, 1 # print_int \(system call 1\)) show 8 mp_a_x mul 516 moveto (add $a0, $0, $t0 # put value A[i] == $t0 in $a0 for printing) show 8 mp_a_x mul 504 moveto (syscall) show 8 mp_a_x mul 492 moveto (li $v0, 4 # print_str \(system call 4\)) show 8 mp_a_x mul 480 moveto (la $a0, blank # takes the address of string as an argument ) show 8 mp_a_x mul 468 moveto (syscall) show 0 mp_a_x mul 456 moveto (## Ready for next loop) show 8 mp_a_x mul 444 moveto (addi) show 16 mp_a_x mul 444 moveto ($s3, $s3, 1) show 8 mp_a_x mul 432 moveto (bne $s4, $s3, Loop # if \(i != 10\) go to Loop) show 0 mp_a_x mul 408 moveto (## Print a newline) show 8 mp_a_x mul 396 moveto (li $v0, 4 # print_str \(system call 4\)) show 8 mp_a_x mul 384 moveto (la $a0, newl # takes the address of string as an argument ) show 8 mp_a_x mul 372 moveto (syscall) show 0 mp_a_x mul 324 moveto (#############################################################################) show 0 mp_a_x mul 312 moveto (## Start of second simple loop example) show 8 mp_a_x mul 300 moveto (la) show 16 mp_a_x mul 300 moveto ($s5, B) show 8 mp_a_x mul 288 moveto (addi $s3, $zero, 0 # s3 = 0, used for index i) show 8 mp_a_x mul 276 moveto (addi $s4, $zero, 10 # s4 = 10) show 8 mp_a_x mul 264 moveto (add) show 16 mp_a_x mul 264 moveto ($s6, $zero, $s5 # used for pointer into B, address of B[i]) show 0 mp_a_x mul 240 moveto (Loop2:) show 8 mp_a_x mul 228 moveto (lw $t0, 0\($s6\) # Temporary register $t0 has value of B[i]) show 0 mp_a_x mul 216 moveto (## Print array element and a blank) show 8 mp_a_x mul 204 moveto (li $v0, 1 #print_int \(system call 1\)) show 8 mp_a_x mul 192 moveto (add $a0, $0, $t0 #put value B[i] == $t0 in $a0 for printing) show 8 mp_a_x mul 180 moveto (syscall) show 8 mp_a_x mul 168 moveto (li $v0, 4 # print_str \(system call 4\)) show 8 mp_a_x mul 156 moveto (la $a0, blank # takes the address of string as an argument ) show 8 mp_a_x mul 144 moveto (syscall) show 0 mp_a_x mul 132 moveto (## Ready for next loop) show 8 mp_a_x mul 120 moveto (addi) show 16 mp_a_x mul 120 moveto ($s3, $s3, 1) show 8 mp_a_x mul 108 moveto (addi $s6, $s6, 4) show 8 mp_a_x mul 96 moveto (bne $s4, $s3, Loop2 # if \(i != 10\) go to Loop2) show 0 mp_a_x mul 72 moveto (## Print a newline) show 8 mp_a_x mul 60 moveto (li $v0, 4 # print_str \(system call 4\)) show 8 mp_a_x mul 48 moveto (la $a0, newl # takes the address of string as an argument ) show 8 mp_a_x mul 36 moveto (syscall) show 0 mp_a_x mul 12 moveto (## Usual stuff at the end of the main) show 8 mp_a_x mul 0 moveto (addu $ra, $0, $s7 #restore the return address) show grestore gsave 24 392 translate -90 rotate 368 80 mp_a_x mul div 564 792 div scale 0 -4 moveto 0 792 lineto 80 mp_a_x mul 792 lineto 80 mp_a_x mul -4 lineto closepath clip 8 mp_a_x mul 780 moveto (jr $ra #return to the main program) show 8 mp_a_x mul 756 moveto (.data) show 8 mp_a_x mul 744 moveto (.align 2 # Let's make sure that it's aligned ) show 0 mp_a_x mul 732 moveto (A: .word 11,13,15,17,19,21,23,25,27,29 ) show 0 mp_a_x mul 720 moveto (B: .word 15,20,25,30,35,40,45,50,55,60) show 0 mp_a_x mul 708 moveto (blank: .asciiz " " # string to print) show 0 mp_a_x mul 696 moveto (newl: .asciiz "\\n" # string to print) show 0 mp_a_x mul 684 moveto (### output) show 0 mp_a_x mul 672 moveto (# four06% spim -file array.s) show 0 mp_a_x mul 660 moveto (# SPIM Version 6.0 of July 21, 1997) show 0 mp_a_x mul 648 moveto (# Copyright 1990-1997 by James R. Larus \(larus@cs.wisc.edu\).) show 0 mp_a_x mul 636 moveto (# All Rights Reserved.) show 0 mp_a_x mul 624 moveto (# See the file README for a full copyright notice.) show 0 mp_a_x mul 612 moveto (# Loaded: /usr/local/lib/trap.handler) show 0 mp_a_x mul 600 moveto (# 11 13 15 17 19 21 23 25 27 29 ) show 0 mp_a_x mul 588 moveto (# 15 20 25 30 35 40 45 50 55 60 ) show grestore restore showpage %%Trailer statusdict begin jobname print flush (: Job finished:\n) print (\tmpage time (s) = ) print flush usertime mp_stm sub 1000 div == (\tmpage pages = ) print flush pagecount mp_pgc sub == end flush %%Pages: 1