-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program2Task1_Bradley_Gunawan.asm
137 lines (107 loc) · 2.47 KB
/
Program2Task1_Bradley_Gunawan.asm
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
#Bradley Gunawan
#11/16/2024
#Task 1: Return a letter grade from user input
#includes:
#a user menu
#a main label, looping label, and exit label
#a way for users to continue getting grades or to quit
#invalid input handling
.data
mainBorder: .asciiz "\n~~~~~~~~~~~~~ MAIN MENU ~~~~~~~~~~~~~~~~~~\n"
getLetter: .asciiz "(1) Get Letter Grade\n"
exitLabel: .asciiz "(2) Exit Program\n"
firstOption: .asciiz "Enter '1' or '2' for your selection: "
scoreInputmsg: .asciiz "\nPlease enter a score as an integer value: "
outputmsg: .asciiz "\nThe grade is: "
gradeAString: .asciiz "A\n"
gradeBString: .asciiz "B\n"
gradeCString: .asciiz "C\n"
gradeDString: .asciiz "D\n"
gradeFString: .asciiz "F\n"
newScore: .asciiz "\nDo you want to enter a new score? Yes(Y) No(N)"
invalidInput: .asciiz "\nInvalid input. Please try again.\n"
#macro to print string
.macro prString(%str)
li $v0, 4
la $a0, %str
syscall
.end_macro
.text
main:
#prints the main menu labels
prString mainBorder
prString getLetter
prString exitLabel
prString firstOption
#read the user's selection
li $v0, 5
syscall
move $s0, $v0
#check choices
beq $s0, 1, grades
beq $s0, 2, exit
b invalid
grades:
#show prompt for score
li $v0, 4
la $a0, scoreInputmsg
syscall
#read the score
li $v0, 5
syscall
move $s1, $v0
nop
li $t0, 0
li $t1, 100
blt $s1, $t0, invalid
#determine what letter will suit the input
li $s2, 90
bge $s1, $s2, gradeA
li $s2, 80
bge $s1, $s2, gradeB
li $s2, 70
bge $s1, $s2, gradeC
li $s2, 60
bge $s1, $s2, gradeD
li $s2, 0
bge $s1, $s2, gradeF
gradeA:
prString outputmsg
prString gradeAString
b postScore
gradeB:
prString outputmsg
prString gradeBString
b postScore
gradeC:
prString outputmsg
prString gradeCString
b postScore
gradeD:
prString outputmsg
prString gradeDString
b postScore
gradeF:
prString outputmsg
prString gradeFString
b postScore
postScore:
#ask the user if they want to input another score
prString newScore
#read the user's selection
li $v0, 12
syscall
move $s0, $v0
#check choices
beq $s0, 'Y', grades
beq $s0, 'y', grades
beq $s0, 'N', main
beq $s0, 'n', main
b invalid
invalid:
#sends users back to the main menu for invalid inputs
prString invalidInput
b main
exit:
li $v0, 10
syscall