source: liacs/ca/opdr1/myprog.s@ 18

Last change on this file since 18 was 2, checked in by Rick van der Zwet, 15 years ago

Initial import of data of old repository ('data') worth keeping (e.g. tracking
means of URL access statistics)

File size: 2.6 KB
RevLine 
[2]1#/* Author : Rick van der Zwet
2# * S-number : 0433373
3# * Version : $Id: myprog.s 237 2007-09-19 13:19:08Z rick $
4# * Copyright : FreeBSD Licence
5# */
6# space declaration to be used for the printf statement
7 .data
8 .align 4
9space: .asciiz " "
10 .align 4
11# array A reservation 80/4 means a 20 in size
12A: .space 80
13 .align i
14# array B, same size as array A
15B: .space 80
16 .align 4
17# declaration of integer C
18C: .word C
19 .align 4
20# declaration of integer i
21i: .word i
22 .text
23 .align 4
24 .ent main
25main:
26# store the content of 1 into the memory location i
27 li $2,0x00000001 # 1
28 sw $2,i
29$L2:
30# initiation of the first for loop
31 lw $2,i
32# the i<=19 condition check
33 slt $3,$2,20
34# jump to L5 when not done or else exit loop to to L3
35 bne $3,$0,$L5
36 j $L3
37$L5:
38#inner part of loop 1
39 lw $2,i
40#copy the value of $2 -> $3, by using an addition with 0
41 addi $3,$2,0
42#multiple the value of i by 4 to find the offset address
43# where the value in array B will be stored
44 sll $2,$3,2
45#load B (begin array) and add the offset of the array to find the
46#location it needs to be stored
47 la $3,B
48 addu $2,$2,$3
49 addi $3,$2,0
50#store the value of i into the the correct location in the B array
51 lw $2,i
52 sw $2,0($3)
53$L4:
54# raise the value of i by 1 (by using a tmp value) and jump
55# to the begin of the loop
56 lw $3,i
57 addu $2,$3,1
58 move $3,$2
59 sw $3,i
60 j $L2
61$L3:
62# init of C and i (counter for loop)
63 li $2,0x0000002a # 42
64 sw $2,C
65 li $2,0x00000001 # 1
66 sw $2,i
67$L6:
68# inner of loop 2, the for loop condition check, jump to L7 when done
69# else exec L9
70 lw $2,i
71 slt $3,$2,20
72 bne $3,$0,$L9
73 j $L7
74$L9:
75#calculate the offset for array A
76 lw $2,i
77 move $3,$2
78 sll $2,$3,2
79#set the array of storage in A into $2
80 la $4,A
81 addu $3,$2,$4
82 move $2,$3
83#calculate offset of B
84 lw $3,i
85 move $4,$3
86 sll $3,$4,2
87#set initial start to -4 to accomplish i-1
88 la $4,B
89 addi $4,$4,-4
90 addu $3,$3,$4
91 move $4,$3
92#load value of B and C, compare and store in location in array A
93 lw $3,0($4)
94 lw $4,C
95 addu $3,$3,$4
96 sw $3,0($2)
97$L8:
98# same as L4, except the jump goes to L6
99# raise the value of i by 1 (by using a tmp value) and jump
100# to the begin of the loop
101 lw $3,i
102 addu $2,$3,1
103 move $3,$2
104 sw $3,i
105 j $L6
106$L7:
107# the print statements
108 li $v0,1
109 la $3,A
110 lw $a0,76($3)
111 syscall #print A[19]
112
113 li $v0, 4 # system call code for print_str
114 la $a0, space # address of string to print
115 syscall # print the string " "
116
117 li $v0, 1
118 la $3,B
119 lw $a0,76($3)
120 syscall #print B[19]
121
122 li $v0, 4 #
123 la $a0, space #
124 syscall # print the string " "
125
126 li $v0,1
127 la $3,i
128 lw $a0,0($3)
129 syscall #print i
130$L1:
131 .end main
Note: See TracBrowser for help on using the repository browser.