-
Notifications
You must be signed in to change notification settings - Fork 0
/
Lab3 - Functions
131 lines (119 loc) · 3.43 KB
/
Lab3 - Functions
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
##############################################
# Program Name: Assignment 1 Palindromes
# Programmer: Max Waldt
# Date 02/3/15
#############################################
# Functional Description:
# A program to find palindromes from integers a user inputs
#############################################
# Cross References:
# v0: N,
# fp8: Sum
###########################################
.data # Data declaration section
COORD: .asciiz "\n Please input coordinates: "
MC: .asciiz "\n To calculate the area of a circle enter 1"
MS: .asciiz "\n To calculate the area of a square enter 2"
MR: .asciiz "\n To calculate the area of a rectangle enter 3"
EX: .asciiz "\n To exit enter 3"
MI: .asciiz "\n Input: "
CT: .asciiz "\n The area of a circle is: "
ST: .asciiz "\n The area of a square is: "
RT: .asciiz "\n The area of a rectangle is: "
Bye: .asciiz "\n ****** Program Terminated ******"
.globl main
.text
###########################################
main: # Start of code section
Inputs:
#Prompt user for input of position
jal printst
jal readnum
mov.d $f24, $f0 #x1
jal printst
jal readnum
mov.d $f26, $f0 #x2
jal printst
jal readnum
mov.d $f28, $f0 #x3
jal printst
jal readnum
mov.d $f30, $f0 #x4
jal lengx #gets distances between x's
jal lengy #gets distances between y's
jal CalcSquares #x and y distances squared
jal CircleArea
jal SquareArea
jal RectangleArea
b Exit
###########################################
printst:
li $v0, 4 #System call code for Print String
la $a0, COORD #load add.dress of prompt into $a0
syscall #print the prompt message
jr $ra
###########################################
readnum:
#Wait on input
li $v0, 7 #system call code for Read Integer
syscall #reads the value of N into $v0
jr $ra
###########################################
lengx:
sub.d $f2, $f28, $f24 #x2-x1
jr $ra
###########################################
lengy:
sub.d $f4, $f30, $f26 #y2-y1
jr $ra
###########################################
CalcSquares:
mul.d $f6, $f2, $f2 #(x2-x1)^2
mul.d $f8, $f4, $f4 #(y2-y1)^2
jr $ra
###########################################
CircleArea:
li $v0, 314156
mtc1.d $v0, $f10
cvt.d.w $f10, $f10 #Pi*10,000
li $v0, 100000
mtc1.d $v0, $f14
cvt.d.w $f14, $f14 #10,000
add.d $f12, $f6, $f8 #r^2 = (x2-x1)^2 + (y2-y1)^2 or A = side^2
mul.d $f16, $f10, $f12 #314156 * r^2
div.d $f12, $f16, $f14 #(314156 * r^2)/10000
li $v0, 4 #System call code for Print String
la $a0, CT #load add.dress of prompt into $a0
syscall
la $s0, AreaPrint
jalr $s1, $s0
jr $ra
###########################################
SquareArea:
add.d $f12, $f6, $f8
li $v0, 4 #System call code for Print String
la $a0, ST #load add.dress of prompt into $a0
syscall
la $s0, AreaPrint
jalr $s1, $s0
jr $ra
###########################################
RectangleArea:
mul.d $f12, $f2, $f4
li $v0, 4 #System call code for Print String
la $a0, RT #load add.dress of prompt into $a0
syscall
la $s0, AreaPrint
jalr $s1, $s0
jr $ra
###########################################
AreaPrint:
li $v0, 3 #System call code for Print String
#move $a0, $f12 #load add.dress of prompt into $a0
syscall
jr $s1
###########################################
Exit:
li $v0, 10 #terminate program run and
syscall #return control to the system
# END OF PROGRAM