#/* Author : Rick van der Zwet # * S-number : 0433373 # * Version : $Id: myprog-optimized.s 237 2007-09-19 13:19:08Z rick $ # * Copyright : FreeBSD Licence # */ # space declaration to be used for the printf statement .data .align 4 space: .asciiz " " .align 4 # array A reservation 80/4 means a 20 in size A: .space 80 .align i # array B, same size as array A B: .space 80 .align 4 # declaration of integer C C: .word C .align 4 # declaration of integer i i: .word i .text .align 4 .ent main main: # init of C li $4,0x0000002a # 42 sw $4,C #Define B[1] - B[19] la $2,B li $3,0x00000001 # 1 sw $3,4($2) li $3,0x00000002 sw $3,8($2) li $3,0x00000003 sw $3,12($2) li $3,0x00000004 sw $3,16($2) li $3,0x00000005 sw $3,20($2) li $3,0x00000006 sw $3,24($2) li $3,0x00000007 sw $3,28($2) li $3,0x00000008 sw $3,32($2) li $3,0x00000009 sw $3,36($2) li $3,0x0000000a #10 sw $3,40($2) li $3,0x0000000b sw $3,44($2) li $3,0x0000000c sw $3,48($2) li $3,0x0000000d sw $3,52($2) li $3,0x0000000e sw $3,56($2) li $3,0x0000000f sw $3,60($2) li $3,0x00000010 sw $3,64($2) li $3,0x00000011 sw $3,68($2) li $3,0x00000012 sw $3,72($2) li $3,0x00000013 sw $3,76($2) #Special hack for A[1], cause B[0] is not defined lw $3,0($2) addu $3,$3,$4 la $2,A sw $3,4($2) #Define A[2] - A[19] li $3,0x0000002b # 42 + 1 = 43 sw $3,8($2) li $3,0x0000002c # 44 sw $3,12($2) li $3,0x0000002d # 45 sw $3,16($2) li $3,0x0000002e # 46 sw $3,20($2) li $3,0x0000002f # 47 sw $3,24($2) li $3,0x00000030 # 48 sw $3,28($2) li $3,0x00000031 # 49 sw $3,32($2) li $3,0x00000032 # 50 sw $3,36($2) li $3,0x00000033 # 51 sw $3,40($2) li $3,0x00000034 # 52 sw $3,44($2) li $3,0x00000035 # 53 sw $3,48($2) li $3,0x00000036 # 54 sw $3,52($2) li $3,0x00000037 # 55 sw $3,56($2) li $3,0x00000038 # 56 sw $3,60($2) li $3,0x00000039 # 57 sw $3,64($2) li $3,0x0000003a # 58 sw $3,68($2) li $3,0x0000003b # 59 sw $3,72($2) li $3,0x0000003c # 60 sw $3,76($2) # set the end registers to the end values #(last value of i, last loop compare) li $2,0x00000014 # 20 sw $2, i # (last loop compare) li $3,0x00000000 # 0 # Required output "60 19 20" # the print statements li $v0,1 la $3,A lw $a0,76($3) syscall #print A[19] li $v0, 4 # system call code for print_str la $a0, space # address of string to print syscall # print the string " " li $v0, 1 la $3,B lw $a0,76($3) syscall #print B[19] li $v0, 4 # la $a0, space # syscall # print the string " " li $v0,1 la $3,i lw $a0,0($3) syscall #print i $L1: .end main