-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.asm
209 lines (137 loc) · 3.62 KB
/
main.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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
.data
string: .asciiz "Welcome to Bank Management System\n"
array: .word 1000, 500
.word 1001, 900
.word 1002, 1500
.word 1003, 5000
.word 1004, 3000
.word 1005, 4000
input1: .asciiz "\nPress 1 for operation \nPress 2 to create account: "
choice: .asciiz "\nEnter 1 to deposit amount,\n2 to withdraw amount, \n3 for transfer : "
input2: .asciiz "\nEnter account number: "
input3: .asciiz "\nEnter amount to deposit"
in
.text
.globl main
.ent main
main:
#array address in t9
la $t9, array
#Displaying Welcome Message
li $v0, 4
la $a0, string
syscall
#Displaying input1 text
li $v0, 4
la $a0, input1
syscall
#Taking User Input, if it is 1 or 2
li $v0, 5
syscall
# $t0 = 1 or 2
move $t0, $v0
# hardcode $t1 = 2
addi $t1, $0, 2
#hardcode $t3 = 3
addi $t3, $0, 3
#branch if user input 2 to two
beq $t0, $t1, two
#displaying choice message
li $v0, 4
la $a0, choice
syscall
#taking User input 1, 2, 3
li $v0, 5
syscall
# $t2 = 1 2 OR 3
move $t2, $v0
# if choice is 2 then move to two two
beq $t2, $t1, twotwo
# if choice is 3 then move to three three
beq $t2, $t3, threethree
##########################################################################
#user wants to deposit amount
#Displaying the message to enter account number
li $v0, 4
la $a0, input2
syscall
#Reading user's account number
li $v0, 5
syscall
#saving account number to $t4
move $t4, $v0
#Displaying message to enter amount to deposit
li $v0, 4
la $a0, input3
syscall
#Reading user's input of amount to deposit
li $v0, 5
syscall
#saving amount to deposit into $t5
move $t5, $v0
#setting loop variable t6 to 0
addi $t6, $0, 0
#setting $t7 to 5
addi $t7, $0, 5
loop1:
beq $t6, $t7, exit
#setting column index to 0 which will remain constant
addi $a2, $0, 0
#setting row index to loop variable
addi $a1, $t6, 0
jal calculate_address
#address is in t8
move $s5, $v0
lw $t8, ($s5)
bne $t8, $t4, here
#loading amount of that account number into s3
lw $s3, 4($s5)
#adding amount to deposit to actual amount
add $s3, $s3, $t5
#storing back to that address
sw $s3, 4($s5)
j exit
here:
#adding 1 in loop variable
addi $t6, $t6, 1
j loop1
exit:
######
lw $s4, 4($s5)
li $v0,1
move $a0, $s4
syscall
######
li $v0,10
syscall
#########################################################################
twotwo:
threethree:
two:
#Exiting the program
li $v0, 10
syscall
######################################################################
# function to calculate address
calculate_address:
#column_size = 2
addi $s6, $0, 2
#data_size = 4
addi $s7, $0, 4
# row index
move $s0, $a1
# column index
move $s1, $a2
# s2 = rowindex * column size
mul $s2, $s0, $s6
# s2 = + cloumn index
add $s2, $s2, $s1
# s2 = * data_size
mul $s2, $s2, $s7
# adding base address
add $s2, $s2, $t9
#returning address answer
move $v0, $s2
jr $ra
.end calculate_address
.end main