-
Notifications
You must be signed in to change notification settings - Fork 0
/
Coding of the Mips Program of Parking
544 lines (415 loc) · 15.6 KB
/
Coding of the Mips Program of Parking
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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
.data
.align 2
cararray: .space 40
bikearray1: .space 40
bikearray2: .space 40
displaymainmenu: .asciiz "\n _______________________________________________\n | Choose your Option |\n |_______________________________________________|\n | |\n | 1) Arrival of a Vehicle |\n | 2) No. of Vehicles Parked |\n | 3) Display Order of Vehicles Parked |\n | 4) Departure of a Vehicle |\n | |\n | 5) Exit |\n |_______________________________________________|\n Enter your choice : "
mainmenuend: .asciiz " |_______________________________________________|\n"
contPrompt: .asciiz "\n Press ENTER to continue..."
password: .asciiz "\n !!PASSWORD!!\n Enter the PIN code to continue : "
loginsuccessfull: .asciiz "\n Log in Successful....\n"
invalidpassword: .asciiz "\n Invalid Password....\n"
arrivalmenu: .asciiz "\n------------------------------------------------------------\n ARRIVAL\n------------------------------------------------------------\n For Car press 1\n For a Bike press 2\n Enter your vehicle type: "
arrivalmenuend: .asciiz "\n------------------------------------------------------------\n"
inputplatenumber: .asciiz "\n Enter Plate number of the vehicle: "
alreadypresentplatenumber: .asciiz "\n !!!WRONG PLATE NO.!!!\n !!!PLATE NO. ALREADY IN THE PARKING!!!\n"
inputerror: .asciiz "\n !!!WRONG INPUT!!!"
inputhourstobeparked: .asciiz "\n Enter hours you will park your vehicle: "
feeofparking: .asciiz "\n Fee of Parking : "
parkingfull: .asciiz "\n Parking Space is Full come back later.....\n"
displaynumberofvehicles: .asciiz "\n __________________________________________\n | Vehicles Parked \n |__________________________________________|\n\n Total no. of vehicles Parked: "
displaycars: .asciiz "\n\n Cars Parked: "
displaybikes: .asciiz "\n Bikes Parked: "
displaynumberend: .asciiz "\n __________________________________________\n"
displayorder: .asciiz "\n------------------------------------------------------------\n ORDER OF VEHICLES PARKED\n------------------------------------------------------------\n CAR PARKING AREA:\n"
displayorderbikes: .asciiz "\n\n BIKE PARKING AREA:\n"
gap:.asciiz " "
displayorderend: .asciiz "\n------------------------------------------------------------\n "
newLine: .asciiz "\n"
departuremenu: .asciiz "\n------------------------------------------------------\n DEPARTURE\n------------------------------------------------------\n\n For Car press 1\n For a Bike press 2\n Enter your vehicle type:"
GoodBye: .asciiz "\n ---------------------------------------\n | !!!GOOD BYE!!! |\n | !!!SEE YOU NEXT TIME!!! |\n | ##MNN JAAN BAAZM# |\n ---------------------------------------\n"
noRecord: .asciiz "\n !!!WRONG PLATE NO. ENTERED!!!\n !!!NO RECORD FOUND!!!\n"
parkingempty: .asciiz "\n Parking Space is empty.....\n"
parkingnotempty: .asciiz "\n !!!There are still Vehicles in the Parking!!!\n !!!Can't Shutdown!!!\n"
.text
Main:
li $v0,4
la $a0,password # System wil ask for password
syscall
li $v0,5 # Input password
syscall
beq $v0, 1111, initializearrays # if password is correct i.e. '1111' branch to initialize arrays
li $v0,4
la $a0,invalidpassword # else print 'invalid password'
syscall
b Main # again ask password.
initializearrays:
li $s1, 0 #tOTAL NUMBER OF CARS present IN PARKING
li $s2, 0 #Total number of bikes present in parking
li $v0,4
la $a0,loginsuccessfull # print that the login was successfull.
syscall
li $t0, 0 # the controller of iteration that will be from 0 to 10
li $t1,0 # contains value '0' which will be stored into the arrays
initializeloop:
beq $t0, 40, MainMenu # when the loop has ran 10 times branch to main menu
Sw $t1,cararray($t0) # initialize the car array, which will contain the plate number of cars parked, with '0'
Sw $t1,bikearray1($t0) # initialize the bike array, which will contain the plate number of bikes parked in Row 1, with '0'
Sw $t1,bikearray2($t0) # initialize the bike array, which will contain the plate number of bikes parked in Row 2, with '0'
addi $t0, $t0, 4
b initializeloop
MainMenu:
li $v0,4
la $a0,displaymainmenu # display the main menu and ask to choose an option
syscall
li $v0,5 # input an option
syscall
la $t2, ($v0)
li $v0,4
la $a0,mainmenuend
syscall
beq $t2, 1, arrival # if option choosen is one go to the procedure for arrival of vehical
beq $t2, 2, numberofvehiclesparked # else if option choosen is two go to the procedure for telling the information about the total number of vehicals parked
beq $t2, 3, displayorderofvehiclesparked # else if option choosen is three go to the procedure for displaying the plate numbers of the vehicals and where are they parked.
beq $t2, 4, departure # else if option choosen is four go to the procedure for departure of vehical
beq $t2, 5, exit # else if option choosen is five go to the procedure for exitting the parking system
li $v0, 4
la $a0, inputerror # else print an error
syscall
b enter # and branch to the enter function
arrival:
li $v0, 4
la $a0, arrivalmenu # will print and ask option to select the vehicle type
syscall
li $v0,5 # will take the input of the option
syscall
la $t2, ($v0)
li $v0, 4
la $a0, arrivalmenuend
syscall
beq $t2, 1, arrivalcheckincars # if the input is one i.e. car branch to the function
beq $t2, 2, arrivalcheckinbikes # else if the input is two i.e. bike branch to the function
li $v0, 4
la $a0, inputerror # else print error and branch to the 'enter' function
syscall
b enter
arrivalcheckincars:
beq $s1, 10, vehicletypeparkingfull # if the capacity of cars in parking i.e. 10 is reached branch to function
li $v0, 4
la $a0, inputplatenumber # else take input of the plate number
syscall
li $v0,5
syscall
la $t9, ($v0) # save the plate number in register t9
beq $t9, 0, enteredzeroinplatenumber # if the entered plate number is equal to zero branch to function
checkifalreadypresentincararray: # else proceed through this procedure
li $t0, 0
checkforcarpresentloop: # this function will check if there is any vehicle already present with the same entered number plate
beq $t0, 40, putincars # if the loop has been iterated 10 times branch to putincar function
lw $t1,cararray($t0)
beq $t9, $t1, platenumberalreadypresent # if the entered plate no. = already present plate no.
addi $t0, $t0, 4
b checkforcarpresentloop
arrivalcheckinbikes:
beq $s2, 20, vehicletypeparkingfull # if the capacity of cars in parking i.e. 20 is reached branch to function
li $v0, 4
la $a0, inputplatenumber # else take input of the plate number
syscall
li $v0,5
syscall
la $t9, ($v0) # save the plate number in register t9
beq $t9, 0, enteredzeroinplatenumber # if the entered plate number is equal to zero branch to function
checkifalreadypresentinbikearray: # else proceed through this procedure
li $t0, 0
checkforbikepresentloop: # this function will check if there is any vehicle already present with the same entered number plate
beq $t0, 40, putinbikes # if the loop has been iterated 10 times branch to putincar function
lw $t1,bikearray1($t0)
lw $t3,bikearray2($t0)
beq $t9, $t1, platenumberalreadypresent # if the entered plate no. = already present plate no.
beq $t9, $t3, platenumberalreadypresent # if the entered plate no. = already present plate no.
addi $t0, $t0, 4
b checkforbikepresentloop
vehicletypeparkingfull:
li $v0, 4
la $a0, parkingfull # if the vehicle parking for the vehicle type is full print message
syscall
b enter
putincars:
li $v0, 4
la $a0, inputhourstobeparked # ask to input no. of hours for which the vehicle will be parked
syscall
li $v0,5
syscall
la $t4, ($v0)
li $v0, 4
la $a0, feeofparking # print the message for showing fee of parking
syscall
li $t3, 50
mult $t4, $t3 # multiply hours by 50 (for cars) to obtain the fee
mflo $t4
li $v0, 1
move $a0, $t4
syscall # print the fee
putincararray: # this function will search for a place which is empty for parking (0 in the array shows that the place is empty)
li $t0, 0
putincararrayloop:
beq $t0, 40, enter
lw $t1,cararray($t0)
beq $t1, 0, putoncararray # if the data at the index of array is 0 go to function
addi $t0, $t0, 4
b putincararrayloop
putoncararray:
Sw $t9, cararray($t0) # array[index] = plate number
addi $s1,$s1,1 # increment the total number of cars present with 1
li $v0, 4
la $a0, arrivalmenuend
syscall
b enter
putinbikes:
li $v0, 4
la $a0, inputhourstobeparked # ask to input no. of hours for which the vehicle will be parked
syscall
li $v0,5
syscall
la $t4, ($v0)
li $v0, 4
la $a0, feeofparking # print the message for showing fee of parking
syscall
li $t3, 20
mult $t4, $t3 # multiply hours by 20 (for bikes) to obtain the fee
mflo $t4
li $v0, 1
move $a0, $t4
syscall # print the fee
putinbikearray1: # this function will search for a place which is empty for parking (0 in the array shows that the place is empty)
li $t0, 0
putinbikearray1loop:
beq $t0, 40, putinbikearray2 # if the row1 bike array has been completely traversed branch to check any empty space in row 2 bikearray
lw $t1,bikearray1($t0)
beq $t1, 0, putonbikearray1 # if the data at the index of array is 0 go to function
addi $t0, $t0, 4
b putinbikearray1loop
putinbikearray2:
li $t0, 0
putinbikearray2loop:
beq $t0, 40, enter
lw $t1,bikearray2($t0)
beq $t1, 0, putonbikearray2 # if the data at the index of array is 0 go to function
addi $t0, $t0, 4
b putinbikearray2loop
putonbikearray1:
Sw $t9, bikearray1($t0) # array[index] = plate number
addi $s2,$s2,1 # increment the total number of bikes present with 1
li $v0, 4
la $a0, arrivalmenuend
syscall
b enter
putonbikearray2:
Sw $t9, bikearray2($t0) # array[index] = plate number
addi $s2,$s2,1 # increment the total number of bikes present with 1
li $v0, 4
la $a0, arrivalmenuend
syscall
b enter
platenumberalreadypresent:
li $v0, 4
la $a0, alreadypresentplatenumber # print message if plate number is already present in parking
syscall
b enter
enteredzeroinplatenumber:
li $v0, 4
la $a0, inputerror # print message if plate number entered is '0'
syscall
b enter
numberofvehiclesparked:
li $v0, 4
la $a0, displaynumberofvehicles
syscall
add $t0,$s1,$s2 # add the total number of vehicles (both cars and bikes) and print them
li $v0,1
add $a0,$zero,$t0
syscall
li $v0, 4
la $a0, displaycars
syscall
li $v0, 1
move $a0, $s1 # display number of cars present in the parking
syscall
li $v0, 4
la $a0, displaybikes
syscall
li $v0, 1
move $a0, $s2 # display number of bikes present in the parking
syscall
li $v0, 4
la $a0, displaynumberend
syscall
b enter
displayorderofvehiclesparked:
li $v0, 4
la $a0, displayorder
syscall
b displayordercars
displayordercars: # display the array of cars
li $t0, 0
li $v0, 4
la $a0, gap
syscall
Whilecars:
beq $t0, 40, displaybikes1
lw $t6,cararray($t0)
addi $t0, $t0,4
li $v0,1
move $a0, $t6
syscall
li $v0, 4
la $a0, gap
syscall
j Whilecars
displaybikes1: # display the array of bikes row 1
li $v0, 4
la $a0, displayorderbikes
syscall
li $t0, 0
li $v0, 4
la $a0, gap
syscall
Whilebikes1:
beq $t0, 40, displaybikes2
lw $t6,bikearray1($t0)
addi $t0, $t0,4
li $v0,1
move $a0, $t6
syscall
li $v0, 4
la $a0, gap
syscall
j Whilebikes1
displaybikes2: # display the array of bikes row 2
li $t0, 0
li $v0, 4
la $a0, newLine
syscall
li $v0, 4
la $a0, gap
syscall
Whilebikes2:
beq $t0, 40, displayend
lw $t6,bikearray2($t0)
addi $t0, $t0,4
li $v0,1
move $a0, $t6
syscall
li $v0, 4
la $a0, gap
syscall
j Whilebikes2
displayend:
li $v0, 4
la $a0, displayorderend
syscall
b enter
departure:
li $v0, 4
la $a0, departuremenu # print to ask which vehicle type will be departing
syscall
li $v0,5 # take input of vehicle type
syscall
la $t2, ($v0)
li $v0, 4
la $a0, arrivalmenuend
syscall
beq $t2, 1, departurecheckincars # if the vehicle type entered is car branch to the function
beq $t2, 2, departurecheckinbikes # else if the vehicle type entered is bike branch to the function
li $v0, 4
la $a0, inputerror # else print error message
syscall
b enter
departurecheckincars:
beq $s1, 0, parkingempty # if the number of cars present in parking is zero branch
li $v0, 4
la $a0, inputplatenumber # input the plate number
syscall
li $v0,5
syscall
la $t9, ($v0)
beq $t9, 0, enteredzeroinplatenumber # if entered plate number is '0' branch
checkingthepositionofcar: # check the array for a match with the entered plate number
li $t0, 0
checkforpositionofcarloop:
beq $t0, 40, notpresent # if the end of loop is reached branch to function
lw $t1,cararray($t0)
beq $t9, $t1, deletecar # if array[index] = register t9, branch
addi $t0, $t0, 4
b checkforpositionofcarloop
deletecar:
li $t6, 0
Sw $t6,cararray($t0) # array[index] = 0
addi $s1,$s1,-1 # 1 will be subtracted from the number of cars present in the parking
li $v0, 4
la $a0, GoodBye # Good Bye will be printed
syscall
b enter
departurecheckinbikes:
beq $s2, 0, parkingempty # if the number of bikes present in parking is zero branch
li $v0, 4
la $a0, inputplatenumber # input the plate number
syscall
li $v0,5
syscall
la $t9, ($v0)
beq $t9, 0, enteredzeroinplatenumber # if entered plate number is '0' branch
checkingthepositionofbike1:
li $t0, 0
checkforpositionofbike1loop:
beq $t0, 40, checkingthepositionofbike2 # if the end of loop is reached branch to check row 2 array of bikes
lw $t1,bikearray1($t0)
beq $t9, $t1, deletebike1 # if array[index] = register t9, branch
addi $t0, $t0, 4
b checkforpositionofbike1loop
deletebike1:
li $t6, 0
Sw $t6,bikearray1($t0) # array[index] = 0
addi $s2,$s2,-1 # 1 will be subtracted from the number of bikes present in the parking
li $v0, 4
la $a0, GoodBye # Good Bye will be printed
syscall
b enter
checkingthepositionofbike2:
li $t0, 0
checkforpositionofbike2loop:
beq $t0, 40, notpresent # if the end of loop is reached branch to function
lw $t1,bikearray2($t0)
beq $t9, $t1, deletebike2 # if array[index] = register t9, branch
addi $t0, $t0, 4
b checkforpositionofbike2loop
deletebike2:
li $t6, 0
Sw $t6,bikearray2($t0) # array[index] = 0
addi $s2,$s2,-1 # 1 will be subtracted from the number of bikes present in the parking
li $v0, 4
la $a0, GoodBye # Good Bye will be printed
syscall
b enter
notpresent:
li $v0, 4
la $a0, noRecord # print message that the number plate is not present in the parking
syscall
b enter
parkingisnotempty:
li $v0, 4
la $a0, parkingnotempty # print that th eparking is not empty to shut the system down
syscall
b enter
enter: # Code for press enter to continue
li $v0, 4
la $a0, contPrompt
syscall
li $v0, 12 # sys code for readchar
syscall
move $t0, $v0
b MainMenu
exit:
bnez $s1, parkingisnotempty # if car present in parking is not equal to zero, branch
bnez $s2, parkingisnotempty # else if bikes present in parking is not equal to zero, branch
li $v0, 10 # end the program