-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPE_5.2.asm
More file actions
93 lines (67 loc) · 2.48 KB
/
PE_5.2.asm
File metadata and controls
93 lines (67 loc) · 2.48 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
.data
#Calorie program data
iterationMessage: .asciiz "Calories burned after "
iterationMessage2: .asciiz " minutes: "
calorieProgramTitle: .asciiz "CALORIE PROGRAM--------------\n"
calorieNumber: .float 3.9
startingTime: .float 5.0
startTimeIncrementor: .float 5.0
#General data
doneMessage: .asciiz "Done!"
newLine: .asciiz "\n"
.text
main:
jal calorieDriver
li $v0, 10
syscall
#Running on a particular treadmill you burn 3.9 calories
#per minute. Design a program that uses a loop to display the
#number of calories burned after 10, 15, 20, 25, and 30 minutes.
calorieDriver:
#display title of program
la $v0, 4
la $a0, calorieProgramTitle
syscall
# i = 1
addi $t0, $zero, 1
#loading conversion factor into register
lwc1 $f1, calorieNumber
#loading time interval values into registers
lwc1 $f2, startTimeIncrementor
lwc1 $f3, startingTime
while:
bgt $t0, 5, exit #if t0 > 10, branch to exit label
#Display prompts----------------------------------#
#Displaying first part of prompt #
li $v0, 4 #
la $a0, iterationMessage #
syscall #
#
#Displaying time interval we wish to calculate #
add.s $f12, $f2, $f3 #
li $v0, 2 #
syscall #
#
#Displaying second part of prompt #
li $v0, 4 #
la $a0, iterationMessage2 #
syscall #
#-------------------------------------------------#
#multiplying current time with conversion factor
mul.s $f12, $f12, $f1
li $v0, 2
syscall
#Displaying new Line
li $v0, 4
la $a0, newLine
syscall
#increment startingTime
add.s $f3, $f3, $f2
# increment counter
addi $t0, $t0, 1 # i++
j while #jump back to while
exit:
li $v0, 4
la $a0, doneMessage
syscall
jr $ra