-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunctionExample.asm
More file actions
154 lines (119 loc) · 2.66 KB
/
functionExample.asm
File metadata and controls
154 lines (119 loc) · 2.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
#need to do
#Done. ask user how many triangles to calculate
#Done. associate name with triangle and print out
#Done. display at each iteration which triangle we are currently working on
#Done. change title to include the number of iterations
.data
recNumPrompt: .asciiz "Enter number of rectangles you wish to process: "
areaPrompt1: .asciiz "\nCalculating the area of "
areaPrompt2: .asciiz " rectanlges.\n"
recNumber: .asciiz "\nRectangle "
lengthPrompt: .asciiz "\nLength: "
widthPrompt: .asciiz "Width: "
areaOutPut: .asciiz "Area: "
termMessage: .asciiz "\nDone!"
newLine: .asciiz "\n"
.text
main:
#prompting user to enter number of rectangles they wish to
#process
jal displayRecPrompt
#reading number of rectangles user wishes to process
li $v0, 5
syscall
#moving user input from v0 to t1
move $t1, $v0
#displaying first part of title
jal displayTitle1
#print number of triangles user wishes to process
li $v0, 1
move $a0, $t1
syscall
#displaying second part of title
jal displayTitle2
addi $t0, $zero, 0 #Incrementor
while:
beq $t0, $t1, exit
#displaying rectangle
li $v0, 4
la $a0, recNumber
syscall
#displaying rectangle number
li $v0, 1
addi $a0, $t0, 1
syscall
#propmt for length.
jal displayLengthPrompt
#Reading uiLength
li $v0, 6 #stored in f0
syscall
mov.s $f1, $f0 #moving uiLength to f1
#prompt for width.
jal displayWidthPrompt
#Reading uiWidth
li $v0, 6
syscall #stored in f0
mov.s $f2, $f0 #moving uiWidth to f2
#Display output
jal displayOutPut
#Calling calArea to multiply both values
jal calcArea
#Displaying new line
jal displaynewLine
#clearing f0, f1, f2
mul.s $f0, $f10, $f0
mul.s $f1, $f10, $f1
mul.s $f2, $f10, $f2
addi $t0, $t0, 1 #i++
j while
exit:
li $v0, 4
la $a0, termMessage
syscall
li $v0, 10
syscall
displayRecPrompt:
li $v0, 4
la $a0, recNumPrompt
syscall
jr $ra
displayTitle1:
#Displays title.
li $v0, 4
la $a0, areaPrompt1
syscall
jr $ra
displayTitle2:
#Displays title.
li $v0, 4
la $a0, areaPrompt2
syscall
jr $ra
displayLengthPrompt:
#Displays length prompt.
li $v0, 4
la $a0, lengthPrompt
syscall
jr $ra
displayWidthPrompt:
#Displays width Prompt.
li $v0, 4
la $a0, widthPrompt
syscall
jr $ra
displayOutPut:
li $v0, 4
la $a0, areaOutPut
syscall
jr $ra
displaynewLine:
li $v0, 4
la $a0, newLine
syscall
jr $ra
#Procedure to multiply 2 f register values
calcArea:
li $v0, 2
mul.s $f12, $f1, $f2
syscall
jr $ra