-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.asm
1060 lines (798 loc) · 27.4 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
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
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#this script is a simple agenda for appointments make in MIPS assembly
# tested on MARS 4.5
# data segment
.data
#constants
#strings
MAX_EVENTS: .word 100
MAX_LENGTH_EVENT_NAME: .word 50
MIN_HOUR: .float 0.0
MAX_HOUR: .float 23.5999
MAX_MINUTES: .float 0.5999
#flags
editer_flag: .word 0
#variables
#action inserted by the user
action: .word 0
# counter of events
eventCounter: .word 1
#event number for remove and edit
eventNumber: .word 0
#auxiliary inputs
aux_eventStartTime: .float 0.0
aux_eventEndTime: .float 0.0
aux_eventString: .space 50
aux_eventName: .space 50
# events name array with MAX_LENGTH_EVENT_NAME * MAX_EVENTS bytes
eventsName: .space 5000
# events day array with 4 * MAX_EVENTS bytes
eventsDay: .space 400
# events start time hours array with 4 * MAX_EVENTS bytes
eventsStartTime: .space 400
# events end time minutes array with 4 * MAX_EVENTS bytes
eventsEndTime: .space 400
# strings returned to the user
actions: .asciiz "Available actions:\n[1] insert\n[2] print\n[3] remove\n[4] edit\n[0] quit\n"
invalidAction: .asciiz "\nInvalid Action!\n"
errorInput: .asciiz "\nUnable to insert :(\n"
welcome: .asciiz "Welcome to AppointmentAgenda!\n"
notImplemented: .asciiz "Not implemented yet!\n"
errorWrongInput: .asciiz "\nWrong input!\n"
operationSucceeded: .asciiz "\nOperation succeeded!\n"
# line break
lineBreak: .asciiz "\n"
# insert function outputs
insert_eventName: .asciiz "What is the event name?\n"
insert_eventDay: .asciiz "What day does this event occur?\n"
insert_eventStartTime: .asciiz "What is the event start time? Format: HH.MM\n"
insert_eventEndTime: .asciiz "What is the event end time? Format: HH.MM?\n"
# print function outputs
print_eventName: .asciiz "Event name: "
print_eventDay: .asciiz "Event day: "
print_eventStartTime: .asciiz "Event start time: "
print_eventEndTime: .asciiz "Event end time: "
print_eventNumber: .asciiz "Event number: "
print_noEventToPrint: .asciiz "There is no event to print!\n"
# remove function outputs
remove_eventNumber: .asciiz "What is the event number to be removed?\n"
remove_noEventToRemove: .asciiz "There is no event to remove!\n"
# edit function outputs
edit_eventNumber: .asciiz "What is the event number to be edited?\n"
edit_eventName: .asciiz "Event name: "
edit_eventDay: .asciiz "Event day: "
edit_eventStartTime: .asciiz "Event start time: "
edit_eventEndTime: .asciiz "Event end time: "
edit_noEventToEdit: .asciiz "There is no event to edit!\n"
edit_keepThis: .asciiz "\nChange this value?\n[1] Yes\n[0] No\n"
edit_whatsNew: .asciiz "What is the new value?\n"
.text
.globl main
# welcome message
li $v0, 4
la $a0, welcome
syscall
j loop_action
# this function inserts a new event
insert:
# printing the event name question
li $v0, 4
la $a0, insert_eventName
syscall
# eventCounter starts in 1, so we need to multiply it by MAX_LENGTH_EVENT_NAME to get the correct position in the array
lw $t0, eventCounter
mul $t0, $t0, 50 #MAX_LENGTH_EVENT_NAME
# reading the event name
li $v0, 8
la $a0, aux_eventName
li $a1, 50 #MAX_LENGTH_EVENT_NAME
syscall
# eventCounter starts in 1, so we need to multiply it by 4 to get the correct position in the array
lw $t0, eventCounter
mul $t0, $t0, 4
# printing the event day question
li $v0, 4
la $a0, insert_eventDay
syscall
# reading the event day as integer
li $v0, 5
syscall
move $s0, $v0
# if $v0 is smaller than 1 or bigger than 31 we need to print the errorInput message
blt $v0, 1, errorInsert
bgt $v0, 31, errorInsert
# printing the event start question
li $v0, 4
la $a0, insert_eventStartTime
syscall
# reading the event start time as float
li $v0, 6
syscall
s.s $f0, aux_eventStartTime
# verify if is a valid hour
# if the hour is less than 0, we need to print the errorInput message
l.s $f12, MIN_HOUR
c.lt.s $f0, $f12 # Compare if $f0 less than $f12
bc1t errorInsert # if true, print error message
# if the hour is greater than 23.59, we need to print the errorInput message
l.s $f12, MAX_HOUR
c.lt.s $f12, $f0 # Compare if $f12 less than $f0
bc1t errorInsert # if true, print error message
# for minutes greater than 59, we need to print the errorInput message
# storage aux_eventStartTime in $f12
l.s $f12, aux_eventStartTime
# Convert the floating-point value in f12 to an integer
cvt.w.s $f22, $f12 # Convert single-precision floating point to 32-bit integer in f0
# Store the integer part in an integer register
mfc1 $t6, $f22 # Move the integer value from f0 to $t0
# Move the integer value from $t6 to a floating-point register $f12
mtc1 $t6, $f16 # Move the integer value in $t6 to floating-point register $f12
# Convert the integer value in $f12 to a floating-point value
cvt.s.w $f16, $f16 # Convert 32-bit integer in $f12 to single-precision float in $f12
# Subtract the value in f16 from f12 and store the result in f12
sub.s $f12, $f12, $f16
# storage MAX_MINUTES in $f19
l.s $f19, MAX_MINUTES
# compare if the minutes is greater than 59
c.lt.s $f19, $f12
bc1t errorInsert
# print event end time
li $v0, 4
la $a0, insert_eventEndTime
syscall
# reading the event end time as float
li $v0, 6
syscall
s.s $f0, aux_eventEndTime
l.s $f15, aux_eventStartTime
c.lt.s $f0, $f15 # if f0 < f15
bc1t errorInsert
c.eq.s $f0, $f15 # if f0 == f15
bc1t errorInsert
# verify if is a valid hour
# if the hour is less than 0, we need to print the errorInput message
l.s $f12, MIN_HOUR
c.lt.s $f0, $f12 # Compare if $f0 less than $f12
bc1t errorInsert # if true, print error message
# if the hour is greater than 23.59, we need to print the errorInput message
l.s $f12, MAX_HOUR
c.lt.s $f12, $f0 # Compare if $f12 less than $f0
bc1t errorInsert # if true, print error message
# if the hour is less than the start time, we need to print the errorInput message
l.s $f12, aux_eventStartTime
c.lt.s $f0, $f12 # Compare if $f0 less than $f12
bc1t errorInsert # if true, print error message
# for minutes greater than 59, we need to print the errorInput message
# storage aux_eventStartTime in $f12
l.s $f12, aux_eventEndTime
# Convert the floating-point value in f12 to an integer
cvt.w.s $f22, $f12 # Convert single-precision floating point to 32-bit integer in f0
# Store the integer part in an integer register
mfc1 $t6, $f22 # Move the integer value from f0 to $t0
# Move the integer value from $t6 to a floating-point register $f12
mtc1 $t6, $f16 # Move the integer value in $t6 to floating-point register $f12
# Convert the integer value in $f12 to a floating-point value
cvt.s.w $f16, $f16 # Convert 32-bit integer in $f12 to single-precision float in $f12
# Subtract the value in f16 from f12 and store the result in f12
sub.s $f12, $f12, $f16
# storage MAX_MINUTES in $f19
l.s $f19, MAX_MINUTES
# compare if the minutes is greater than 59
c.lt.s $f19, $f12
bc1t errorInsert
j compareDay
day_insert:
exit_sortArray:
# increase at one the eventCounter
lw $t0, eventCounter
addi $t0, $t0, 1
sw $t0, eventCounter
# print operation succeeded message
li $v0, 4
la $a0, operationSucceeded
syscall
# print line break
li $v0, 4
la $a0, lineBreak
syscall
j loop_action
compareDay:
# using auxCounter set to value 1
li $t1, 1
lw $t2, eventCounter
# compare if the day inserted already exists withing the eventsDay array
loop_compareDay:
# if auxCounter is equal to eventCounter, we have compared all days, the value inserted is the biggest
bge $t1, $t2, exit_compareDay
mul $t3, $t1, 50 #MAX_LENGTH_EVENT_NAME
# aux_eventName into eventsName array
la $t4, aux_eventString
la $t5, eventsName($t3)
# loop to copy the aux_eventName into eventsName
loop_insertNameinAux:
lb $t7, 0($t5)
sb $t7, 0($t4)
addi $t4, $t4, 1
addi $t5, $t5, 1
bne $t7, $zero, loop_insertNameinAux
j exit_insertNameinAux
exit_insertNameinAux:
mul $t3, $t1, 4 #MAX_LENGTH_DAY
lw $t4, eventsDay($t3) # current event day
l.s $f14, eventsStartTime($t3) # current event start time
l.s $f16, eventsEndTime($t3) # current event end time (these are loaded to be used in the sort function when needed)
# if the day inserted($s0) is equal to current day($t4) in the array, we need to compare the hours
beq $t4, $s0, compareHour
exit_compareHour:
# if the day inserted is smaller than any day in the array, we need to insert it in current position
blt $s0, $t4, sortArray
# Increment auxCounter
addi $t1, $t1, 1
j loop_compareDay
compareHour:
mul $t5, $t1, 4 #MAX_LENGTH_HOUR
# store the start time and end time of the event inserted confliction and atual event
l.s $f18, aux_eventStartTime
l.s $f19, aux_eventEndTime
l.s $f20, eventsStartTime($t5)
l.s $f21, eventsEndTime($t5)
# verify if the event inserted confliction with the atual event
c.lt.s $f19, $f20 # if aux_eventEndTime < eventsStartTime
bc1t sortArray # if true we insert in the current position and sort the array
c.lt.s $f21, $f18 # if eventsEndTime($t5) < aux_eventStartTime
bc1t exit_compareHour # if true we insert in the next position and sort the array
j errorInsert
# This function stores the event inserted in the aux variables in the current position from compareDay and pushes the events to the right to the next positions
sortArray:
# store aux_eventName into eventsName array
mul $t3, $t1, 50 #MAX_LENGTH_EVENT_NAME
# aux_eventName into eventsName array
la $t6, aux_eventName
la $t7, eventsName($t3)
# loop to copy the aux_eventName into eventsName
loop_insertAuxName:
lb $t3, 0($t6)
sb $t3, 0($t7)
addi $t6, $t6, 1
addi $t7, $t7, 1
bne $t3, $zero, loop_insertAuxName
j exit_insertAuxName
exit_insertAuxName:
mul $t3, $t1, 4 #MAX_LENGTH_DAY
# store day inserted in the array
sw $s0, eventsDay($t3)
# store start time inserted in the array
l.s $f12, aux_eventStartTime
s.s $f12, eventsStartTime($t3)
# store end time inserted in the array
l.s $f13, aux_eventEndTime
s.s $f13, eventsEndTime($t3)
loop_sortArray:
# $t1=auxCounter, $t2=eventCounter, $t3=position in the array, $t4=day in the array
beq $t1, $t2, exit_sortArray # if auxCounter is equal to eventCounter, the array is sorted
addi $t1, $t1, 1 # Increment auxCounter($t1)
mul $t3, $t1, 4 # position in the array, auxCounter * 4
# event day in the array sorted
lw $t5, eventsDay($t3) # day in the array
sw $t4, eventsDay($t3) # store day in the array in $t4
move $t4, $t5 # move day in the array to $t4
# event start time in the array sorted
l.s $f15, eventsStartTime($t3) # start time in the array
s.s $f14, eventsStartTime($t3) # store start time in the array in $f12
mov.s $f14, $f15 # move start time in the array to $f12
# event end time in the array sorted
l.s $f17, eventsEndTime($t3) # end time in the array
s.s $f16, eventsEndTime($t3) # store end time in the array in $f12
mov.s $f16, $f17 # move end time in the array to $f12
# event name in the array sorted
mul $t3, $t1, 50 #MAX_LENGTH_EVENT_NAME
# copy from eventsName($t3) to aux_eventName
la $t6, eventsName($t3)
la $t7, aux_eventName
loop_nameSort:
lb $t8, 0($t6)
sb $t8, 0($t7)
addi $t6, $t6, 1
addi $t7, $t7, 1
bne $t8, $zero, loop_nameSort
j exit_nameSort
exit_nameSort:
# store aux_eventString into eventsName($t3) array
la $t6, aux_eventString
la $t7, eventsName($t3)
loop_nameSort2:
lb $t8, 0($t6)
sb $t8, 0($t7)
addi $t6, $t6, 1
addi $t7, $t7, 1
bne $t8, $zero, loop_nameSort2
j exit_nameSort2
exit_nameSort2:
# move aux_eventName to aux_eventString
la $t6, aux_eventName
la $t7, aux_eventString
loop_nameSort3:
lb $t8, 0($t6)
sb $t8, 0($t7)
addi $t6, $t6, 1
addi $t7, $t7, 1
bne $t8, $zero, loop_nameSort3
j exit_nameSort3
exit_nameSort3:
j loop_sortArray
exit_compareDay:
# day greater than any event, so we can insert it in the end of the array
# event day in the array sorted
sw $s0, eventsDay($t0)
# event start time in the array sorted
l.s $f12, aux_eventStartTime
s.s $f12, eventsStartTime($t0)
# event end time in the array sorted
l.s $f13, aux_eventEndTime
s.s $f13, eventsEndTime($t0)
insertAuxEvent:
# set t0 apropiate position in the array
lw $t0, eventCounter
mul $t0, $t0, 50 #MAX_LENGTH_EVENT_NAME
# aux_eventName into eventsName array
la $t1, aux_eventName
la $t2, eventsName($t0)
# loop to copy the aux_eventName into eventsName
loop_insertName:
lb $t3, 0($t1)
sb $t3, 0($t2)
addi $t1, $t1, 1
addi $t2, $t2, 1
bne $t3, $zero, loop_insertName
j exit_insertName
exit_insertName:
j day_insert
errorInsert:
li $v0, 4
la $a0, errorInput
syscall
# print line break
li $v0, 4
la $a0, lineBreak
syscall
j loop_action
# function of print all events
print:
# using auxCounter set to 1
li $t0, 1
lw $t1, eventCounter
beq $t0, $t1, errorNoEventToPrint
# loop to print all information about events
loop_print:
# if auxCounter is equal to eventCounter, we have printed all events
bge $t0, $t1, exit_print
# Print text of event number
li $v0, 4
la $a0, print_eventNumber
syscall
# print t0
li $v0, 1
move $a0, $t0
syscall
# Print line break
li $v0, 4
la $a0, lineBreak
syscall
# Print text of event name
li $v0, 4
la $a0, print_eventName
syscall
# Print event name
li $v0, 4
la $a0, eventsName
mul $t2, $t0, 50 #MAX_LENGTH_EVENT_NAME
add $a0, $a0, $t2
syscall
# Print text of event day
li $v0, 4
la $a0, print_eventDay
syscall
# We need to multiply the counter by 4 to get the correct position in the array
mul $t2, $t0, 4 #MAX_LENGTH_DAY
# Print event day
li $v0, 1
lw $a0, eventsDay($t2)
syscall
# Print line break
li $v0, 4
la $a0, lineBreak
syscall
# Print text of event start time
li $v0, 4
la $a0, print_eventStartTime
syscall
# Print event start time
li $v0, 2
l.s $f12, eventsStartTime($t2)
syscall
# Print line break
li $v0, 4
la $a0, lineBreak
syscall
# Print text of event end time
li $v0, 4
la $a0, print_eventEndTime
syscall
# Print event end time
li $v0, 2
l.s $f12, eventsEndTime($t2)
syscall
# Print line break
li $v0, 4
la $a0, lineBreak
syscall
# Increment auxCounter
addi $t0, $t0, 1
# Print line break
li $v0, 4
la $a0, lineBreak
syscall
j loop_print
exit_print:
j loop_action
errorNoEventToPrint:
# Print line break
li $v0, 4
la $a0, lineBreak
syscall
# print error message
li $v0, 4
la $a0, print_noEventToPrint
syscall
# Print line break
li $v0, 4
la $a0, lineBreak
syscall
j loop_action
# function to remove an event
remove:
# if eventCounter is equal to 1, we have no events to remove
lw $t0, eventCounter
beq $t0, 1, errorNoEventToRemove
# print the event number question
li $v0, 4
la $a0, remove_eventNumber
syscall
# store the event number in the eventNumber variable
li $v0, 5
syscall
sw $v0, eventNumber
# if $v0 is smaller than 1 or bigger than eventCounter we need to print the errorInput message
blt $v0, 1, errorWrongInputf
sub $t0, $t0, 1
bgt $v0, $t0, errorWrongInputf
edit_remover:
# eventNumber is number of the event to be removed
lw $t0, eventNumber
lw $t1, eventCounter
# loop to move all events right to the event removed one position to the left
loop_remover:
addi $t0, $t0, 1
bge $t0, $t1, exit_remover
mul $t2, $t0, 50 #MAX_LENGTH_EVENT_NAME
sub $t5, $t2, 50 #MAX_LENGTH_DAY
la $t4, eventsName($t2)
la $t6, eventsName($t5)
loop_nameRemover:
lb $t7, 0($t4)
sb $t7, 0($t6)
addi $t4, $t4, 1
addi $t6, $t6, 1
bne $t7, $zero, loop_nameRemover
j exit_nameRemover
exit_nameRemover:
mul $t2, $t0, 4 #MAX_LENGTH_DAY
sub $t5, $t2, 4 #MAX_LENGTH_DAY
lw $t4, eventsDay($t2)
sw $t4, eventsDay($t5)
l.s $f12, eventsStartTime($t2)
s.s $f12, eventsStartTime($t5)
l.s $f13, eventsEndTime($t2)
s.s $f13, eventsEndTime($t5)
j loop_remover
exit_remover:
# decrease eventCounter
lw $t1, eventCounter
subi $t1, $t1, 1
sw $t1, eventCounter
# if editer_flag is equal to 1, we need to jump to edit_insert, else we need to print the operationSucceeded message
lw $t0, editer_flag
beq $t0, $zero removeSuccess
j edit_insert
removeSuccess:
# operation succeeded message
li $v0, 4
la $a0, operationSucceeded
syscall
# print line break
li $v0, 4
la $a0, lineBreak
syscall
j loop_action
errorNoEventToRemove:
li $v0, 4
la $a0, remove_noEventToRemove
syscall
j loop_action
# function to edit an event
edit:
# if eventCounter is 1, we need to print the errorEdit message
lw $t0, eventCounter
beq $t0, 1, errorNoEvent
# print the event number question
li $v0, 4
la $a0, edit_eventNumber
syscall
# store the event number in the eventNumber variable
li $v0, 5
syscall
sw $v0, eventNumber
# if $v0 is smaller than 1 or bigger than eventCounter we need to print the errorInput message
blt $v0, 1, errorWrongInputf
sub $t0, $t0, 1
bgt $v0, $t0, errorWrongInputf
# set editer_flag to 1
lw $t0, editer_flag
addi $t0, $t0, 1
sw $t0, editer_flag
# load the eventday in s0
lw $t0, eventNumber
mul $t0, $t0, 4 #MAX_LENGTH_DAY
lw $s0, eventsDay($t0)
# store the event start time in aux_eventStartTime
l.s $f12, eventsStartTime($t0)
s.s $f12, aux_eventStartTime
# store the event end time in aux_eventEndTime
l.s $f12, eventsEndTime($t0)
s.s $f12, aux_eventEndTime
# store the event name in aux_eventName
lw $t0, eventNumber
mul $t0, $t0, 50 #MAX_LENGTH_EVENT_NAME
la $t1, eventsName($t0)
la $t2, aux_eventName
loop_nameEdit:
lb $t3, 0($t1)
sb $t3, 0($t2)
addi $t1, $t1, 1
addi $t2, $t2, 1
bne $t3, $zero, loop_nameEdit
j exit_nameEdit
exit_nameEdit:
# jumps to remove function with editer_flag set to 1
j edit_remover
edit_insert:
# printing the event name question
li $v0, 4
la $a0, edit_eventName
syscall
# print the value storage on aux_eventName
li $v0, 4
la $a0, aux_eventName
syscall
# eventCounter starts in 1, so we need to multiply it by MAX_LENGTH_EVENT_NAME to get the correct position in the array
lw $t0, eventCounter
mul $t0, $t0, 50 #MAX_LENGTH_EVENT_NAME
# print keep event question
li $v0, 4
la $a0, edit_keepThis
syscall
# reading the option
li $v0, 5
syscall
move $t3, $v0
# if $t3 is equal zero, jump to edit_jumpName
beq $t3, $zero, edit_jumpName
# print what's new question
li $v0, 4
la $a0, edit_whatsNew
syscall
# reading the event name
li $v0, 8
la $a0, aux_eventName
li $a1, 50 #MAX_LENGTH_EVENT_NAME
syscall
edit_jumpName:
# eventCounter starts in 1, so we need to multiply it by 4 to get the correct position in the array
lw $t0, eventCounter
mul $t0, $t0, 4
# printing the event day question
li $v0, 4
la $a0, edit_eventDay
syscall
# print the value storage on s0
li $v0, 1
move $a0, $s0
syscall
# print keep event question
li $v0, 4
la $a0, edit_keepThis
syscall
# reading the option
li $v0, 5
syscall
move $t3, $v0
# if $t3 is equal zero, jump to edit_jumpDay
beq $t3, $zero, edit_jumpDay
# print what's new question
li $v0, 4
la $a0, edit_whatsNew
syscall
# reading the event day as integer
li $v0, 5
syscall
move $s0, $v0
# if $v0 is smaller than 1 or bigger than 31 we need to print the errorInput message
blt $v0, 1, errorInsert
bgt $v0, 31, errorInsert
edit_jumpDay:
# printing the event start question
li $v0, 4
la $a0, edit_eventStartTime
syscall
# print the value storage on aux_eventStartTime
li $v0, 2
l.s $f12, aux_eventStartTime
syscall
# print keep event question
li $v0, 4
la $a0, edit_keepThis
syscall
# reading the option
li $v0, 5
syscall
move $t3, $v0
# if $t3 is equal zero, jump to edit_jumpStartTime
beq $t3, $zero, edit_jumpStartTime
# print what's new question
li $v0, 4
la $a0, edit_whatsNew
syscall
# reading the event start time as float
li $v0, 6
syscall
s.s $f0, aux_eventStartTime
edit_jumpStartTime:
# verify if is a valid hour
# if the hour is less than 0, we need to print the errorInput message
l.s $f12, MIN_HOUR
c.lt.s $f0, $f12 # Compare if $f0 less than $f12
bc1t errorInsert # if true, print error message
# if the hour is greater than 23.59, we need to print the errorInput message
l.s $f12, MAX_HOUR
c.lt.s $f12, $f0 # Compare if $f12 less than $f0
bc1t errorInsert # if true, print error message
# for minutes greater than 59, we need to print the errorInput message
# storage aux_eventStartTime in $f12
l.s $f12, aux_eventStartTime
# Convert the floating-point value in f12 to an integer
cvt.w.s $f22, $f12 # Convert single-precision floating point to 32-bit integer in f0
# Store the integer part in an integer register
mfc1 $t6, $f22 # Move the integer value from f0 to $t0
# Move the integer value from $t6 to a floating-point register $f12
mtc1 $t6, $f16 # Move the integer value in $t6 to floating-point register $f12
# Convert the integer value in $f12 to a floating-point value
cvt.s.w $f16, $f16 # Convert 32-bit integer in $f12 to single-precision float in $f12
# Subtract the value in f16 from f12 and store the result in f12
sub.s $f12, $f12, $f16
# storage MAX_MINUTES in $f19
l.s $f19, MAX_MINUTES
# compare if the minutes is greater than 59
c.lt.s $f19, $f12
bc1t errorInsert
# print event end time
li $v0, 4
la $a0, edit_eventEndTime
syscall
# print the value storage on aux_eventEndTime
li $v0, 2
l.s $f12, aux_eventEndTime
syscall
# print keep event keep
li $v0, 4
la $a0, edit_keepThis
syscall
# reading the option
li $v0, 5
syscall
move $t3, $v0
# if $t3 is equal zero, jump to edit_jumpEndTime
beq $t3, $zero, edit_jumpEndTime
# print what's new question
li $v0, 4
la $a0, edit_whatsNew
syscall
# reading the event end time as float
li $v0, 6
syscall
s.s $f0, aux_eventEndTime
edit_jumpEndTime:
l.s $f15, aux_eventStartTime
c.lt.s $f0, $f15 # if f0 < f15
bc1t errorInsert
c.eq.s $f0, $f15 # if f0 == f15
bc1t errorInsert
# verify if is a valid hour
# if the hour is less than 0, we need to print the errorInput message
l.s $f12, MIN_HOUR
c.lt.s $f0, $f12 # Compare if $f0 less than $f12
bc1t errorInsert # if true, print error message
# if the hour is greater than 23.59, we need to print the errorInput message
l.s $f12, MAX_HOUR
c.lt.s $f12, $f0 # Compare if $f12 less than $f0
bc1t errorInsert # if true, print error message
# if the hour is less than the start time, we need to print the errorInput message
l.s $f12, aux_eventStartTime
c.lt.s $f0, $f12 # Compare if $f0 less than $f12
bc1t errorInsert # if true, print error message
# for minutes greater than 59, we need to print the errorInput message
# storage aux_eventStartTime in $f12
l.s $f12, aux_eventEndTime
# Convert the floating-point value in f12 to an integer
cvt.w.s $f22, $f12 # Convert single-precision floating point to 32-bit integer in f0
# Store the integer part in an integer register
mfc1 $t6, $f22 # Move the integer value from f0 to $t0
# Move the integer value from $t6 to a floating-point register $f12
mtc1 $t6, $f16 # Move the integer value in $t6 to floating-point register $f12
# Convert the integer value in $f12 to a floating-point value
cvt.s.w $f16, $f16 # Convert 32-bit integer in $f12 to single-precision float in $f12
# Subtract the value in f16 from f12 and store the result in f12
sub.s $f12, $f12, $f16
# storage MAX_MINUTES in $f19
l.s $f19, MAX_MINUTES
# compare if the minutes is greater than 59
c.lt.s $f19, $f12
bc1t errorInsert
# reset editer flag
lw $t9, editer_flag
subi $t9, $t9, 1
sw $t9, editer_flag