-
Notifications
You must be signed in to change notification settings - Fork 13
/
bai1.asm
754 lines (691 loc) · 17.8 KB
/
bai1.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
.eqv IN_ADRESS_HEXA_KEYBOARD 0xFFFF0012
.eqv OUT_ADRESS_HEXA_KEYBOARD 0xFFFF0014
.eqv KEY_CODE 0xFFFF0004 # ASCII code from keyboard, 1 byte
.eqv KEY_READY 0xFFFF0000 # =1 if has a new keycode ?
# Auto clear after lw
#-------------------------------------------------------------------------------
# Marsbot
.eqv HEADING 0xffff8010 # Integer: An angle between 0 and 359
# 0 : North (up)
# 90: East (right)
# 180: South (down)
# 270: West (left)
.eqv MOVING 0xffff8050 # Boolean: whether or not to move
.eqv LEAVETRACK 0xffff8020 # Boolean (0 or non-0):
# whether or not to leave a track
.eqv WHEREX 0xffff8030 # Integer: Current x-location of MarsBot
.eqv WHEREY 0xffff8040 # Integer: Current y-location of MarsBot
#===============================================================================
#===============================================================================
.data
# Key value
.eqv KEY_0 0x11
.eqv KEY_1 0x21
.eqv KEY_2 0x41
.eqv KEY_3 0x81
.eqv KEY_4 0x12
.eqv KEY_5 0x22
.eqv KEY_6 0x42
.eqv KEY_7 0x82
.eqv KEY_8 0x14
.eqv KEY_9 0x24
.eqv KEY_a 0x44
.eqv KEY_b 0x84
.eqv KEY_c 0x18
.eqv KEY_d 0x28
.eqv KEY_e 0x48
.eqv KEY_f 0x88
#-------------------------------------------------------------------------------
#Control code
MOVE_CODE: .asciiz "1b4"
STOP_CODE: .asciiz "c68"
GO_LEFT_CODE: .asciiz "444"
GO_RIGHT_CODE: .asciiz "666"
TRACK_CODE: .asciiz "dad"
UNTRACK_CODE: .asciiz "cbc"
GO_BACK_CODE: .asciiz "999"
WRONG_CODE: .asciiz "Wrong control code!"
#-------------------------------------------------------------------------------
inputControlCode: .space 50
lengthControlCode: .word 0
nowHeading: .word 0
#---------------------------------------------------------
# duong di cua masbot duoc luu tru vao mang path
# moi 1 canh duoc luu tru duoi dang 1 structure
# 1 structure co dang {x, y, z}
# trong do: x, y la toa do diem dau tien cua canh
# z la huong cua canh do
# mac dinh: structure dau tien se la {0,0,0}
# do dai duong di ngay khi bat dau la 12 bytes (3x 4byte)
#---------------------------------------------------------
path: .space 600
lengthPath: .word 12 #bytes
#===============================================================================
#===============================================================================
.text
main:
li $k0, KEY_CODE
li $k1, KEY_READY
#---------------------------------------------------------
# Enable the interrupt of Keyboard matrix 4x4 of Digital Lab Sim
#---------------------------------------------------------
li $t1, IN_ADRESS_HEXA_KEYBOARD
li $t3, 0x80 # bit 7 = 1 to enable
sb $t3, 0($t1)
#---------------------------------------------------------
loop: nop
WaitForKey: lw $t5, 0($k1) #$t5 = [$k1] = KEY_READY
beq $t5, $zero, WaitForKey #if $t5 == 0 then Polling
nop
beq $t5, $zero, WaitForKey
ReadKey: lw $t6, 0($k0) #$t6 = [$k0] = KEY_CODE
beq $t6, 127 , continue #if $t6 == delete key then remove input
#127 is delete key in ascii
bne $t6, '\n' , loop #if $t6 != '\n' then Polling
nop
bne $t6, '\n' , loop
CheckControlCode:
la $s2, lengthControlCode
lw $s2, 0($s2)
#----------------
bne $s2, 3, pushErrorMess
la $s3, MOVE_CODE
jal isEqualString
beq $t0, 1, go
la $s3, STOP_CODE
jal isEqualString
beq $t0, 1, stop
la $s3, GO_LEFT_CODE
jal isEqualString
beq $t0, 1, goLeft
la $s3, GO_RIGHT_CODE
jal isEqualString
beq $t0, 1, goRight
la $s3, TRACK_CODE
jal isEqualString
beq $t0, 1, track
la $s3, UNTRACK_CODE
jal isEqualString
beq $t0, 1, untrack
la $s3, GO_BACK_CODE
jal isEqualString
beq $t0, 1, goBack
beq $t0, 0, pushErrorMess
printControlCode:
li $v0, 4
la $a0, inputControlCode
syscall
nop
continue:
jal removeControlCode
nop
j loop
nop
j loop
#-----------------------------------------------------------
# storePath procedure, store path of marsbot to path variable
# param[in] nowHeading variable
# lengthPath variable
#-----------------------------------------------------------
storePath:
#backup
addi $sp,$sp,4
sw $t1, 0($sp)
addi $sp,$sp,4
sw $t2, 0($sp)
addi $sp,$sp,4
sw $t3, 0($sp)
addi $sp,$sp,4
sw $t4, 0($sp)
addi $sp,$sp,4
sw $s1, 0($sp)
addi $sp,$sp,4
sw $s2, 0($sp)
addi $sp,$sp,4
sw $s3, 0($sp)
addi $sp,$sp,4
sw $s4, 0($sp)
#processing
li $t1, WHEREX
lw $s1, 0($t1) #s1 = x
li $t2, WHEREY
lw $s2, 0($t2) #s2 = y
la $s4, nowHeading
lw $s4, 0($s4) #s4 = now heading
la $t3, lengthPath
lw $s3, 0($t3) #$s3 = lengthPath (dv: byte)
la $t4, path
add $t4, $t4, $s3 #position to store
sw $s1, 0($t4) #store x
sw $s2, 4($t4) #store y
sw $s4, 8($t4) #store heading
addi $s3, $s3, 12 #update lengthPath
#12 = 3 (word) x 4 (bytes)
sw $s3, 0($t3)
#restore
lw $s4, 0($sp)
addi $sp,$sp,-4
lw $s3, 0($sp)
addi $sp,$sp,-4
lw $s2, 0($sp)
addi $sp,$sp,-4
lw $s1, 0($sp)
addi $sp,$sp,-4
lw $t4, 0($sp)
addi $sp,$sp,-4
lw $t3, 0($sp)
addi $sp,$sp,-4
lw $t2, 0($sp)
addi $sp,$sp,-4
lw $t1, 0($sp)
addi $sp,$sp,-4
jr $ra
nop
jr $ra
#-----------------------------------------------------------
# goBack procedure, control marsbot go back
# param[in] path array, lengthPath array
#-----------------------------------------------------------
goBack: la $s7, path
la $s5, lengthPath
lw $s5, 0($s5)
add $s7, $s7, $s5
begin: addi $s5, $s5, -12 #lui lai 1 structure
addi $s7, $s7, -12 #vi tri cua thong tin ve canh cuoi cung
lw $s6, 8($s7) #huong cua canh cuoi cung
addi $s6, $s6, 180 #nguoc lai huong cua canh cuoi cung
#sub $s6, $zero, $s6
la $t8, nowHeading #marsbot quay nguoc lai
sw $s6, 0($t8)
jal ROTATE
go_to_first_point_of_edge:
lw $t9, 0($s7) #toa do x cua diem dau tien cua canh
li $t8, WHEREX #toa do x hien tai
lw $t8, 0($t8)
bne $t8, $t9, go_to_first_point_of_edge
#addi $s4, $t9, 20
#bgt $t8, $s4, go_to_first_point_of_edge
#nop
#bgt $t8, $s4, go_to_first_point_of_edge
#addi $s4, $t9, -20
#blt $t8, $s4, go_to_first_point_of_edge
#nop
#blt $t8, $s4, go_to_first_point_of_edge
lw $t9, 4($s7) #toa do y cua diem dau tien cua canh
li $t8, WHEREY #toa do y hien tai
lw $t8, 0($t8)
bne $t8, $t9, go_to_first_point_of_edge
#addi $s4, $t9, 20
#bgt $t8, $s4, go_to_first_point_of_edge
#nop
#bgt $t8, $s4, go_to_first_point_of_edge
#addi $s4, $t9, -20
#blt $t8, $s4, go_to_first_point_of_edge
#nop
#blt $t8, $s4, go_to_first_point_of_edge
beq $s5, 0, finish
#nop
#beq $s5, 0, finish
j begin
#nop
#j goBack
finish: jal STOP
la $t8, nowHeading
add $s6, $zero, $zero
sw $s6, 0($t8) #update heading
la $t8, lengthPath
sw $s5, 0($t8) #update lengthPath = 0
jal ROTATE
j printControlCode
#-----------------------------------------------------------
# track procedure, control marsbot to track and print control code
# param[in] none
#-----------------------------------------------------------
track: jal TRACK
j printControlCode
#-----------------------------------------------------------
# untrack procedure, control marsbot to untrack and print control code
# param[in] none
#-----------------------------------------------------------
untrack: jal UNTRACK
j printControlCode
#-----------------------------------------------------------
# go procedure, control marsbot to go and print control code
# param[in] none
#-----------------------------------------------------------
go: jal GO
j printControlCode
#-----------------------------------------------------------
# stop procedure, control marsbot to stop and print control code
# param[in] none
#-----------------------------------------------------------
stop: jal STOP
j printControlCode
#-----------------------------------------------------------
# goRight procedure, control marsbot to go left and print control code
# param[in] none
#-----------------------------------------------------------
goRight:la $s5, nowHeading
lw $s6, 0($s5) #$s6 is heading at now
addi $s6, $s6, 90 #increase heading by 90*
sw $s6, 0($s5) # update nowHeading
jal storePath
jal ROTATE
j printControlCode
#-----------------------------------------------------------
# goLeft procedure, control marsbot to go left and print control code
# param[in] none
#-----------------------------------------------------------
goLeft: la $s5, nowHeading
lw $s6, 0($s5) #$s6 is heading at now
addi $s6, $s6, -90 #increase heading by 90*
sw $s6, 0($s5) # update nowHeading
jal storePath
jal ROTATE
j printControlCode
#-----------------------------------------------------------
# removeControlCode procedure, to remove inputControlCode string
# inputControlCode = ""
# param[in] none
#-----------------------------------------------------------
removeControlCode:
#backup
addi $sp,$sp,4
sw $t1, 0($sp)
addi $sp,$sp,4
sw $t2, 0($sp)
addi $sp,$sp,4
sw $s1, 0($sp)
addi $sp,$sp,4
sw $t3, 0($sp)
addi $sp,$sp,4
sw $s2, 0($sp)
#processing
la $s2, lengthControlCode
lw $t3, 0($s2) #$t3 = lengthControlCode
addi $t1, $zero, -1 #$t1 = -1 = i
addi $t2, $zero, 0 #$t2 = '\0'
la $s1, inputControlCode
addi $s1, $s1, -1
for_loop_to_remove: addi $t1, $t1, 1 #i++
add $s1, $s1, 1 #$s1 = inputControlCode + i
sb $t2, 0($s1) #inputControlCode[i] = '\0'
bne $t1, $t3, for_loop_to_remove #if $t1 <=3 continue loop
nop
bne $t1, $t3, for_loop_to_remove
add $t3, $zero, $zero
sw $t3, 0($s2) #lengthControlCode = 0
#restore
lw $s2, 0($sp)
addi $sp,$sp,-4
lw $t3, 0($sp)
addi $sp,$sp,-4
lw $s1, 0($sp)
addi $sp,$sp,-4
lw $t2, 0($sp)
addi $sp,$sp,-4
lw $t1, 0($sp)
addi $sp,$sp,-4
jr $ra
nop
jr $ra
#-----------------------------------------------------------
# isEqualString procedure, to check inputControlCode string
# is equal with string s (store in $s3 )
# Length of two string is the same
# param[in] $s3, store address of a string
# param[out] $t0, 1 if equal, 0 is not equal
#-----------------------------------------------------------
isEqualString:
#backup
addi $sp,$sp,4
sw $t1, 0($sp)
addi $sp,$sp,4
sw $s1, 0($sp)
addi $sp,$sp,4
sw $t2, 0($sp)
addi $sp,$sp,4
sw $t3, 0($sp)
#processing
addi $t1, $zero, -1 #$t1 = -1 = i
add $t0, $zero, $zero
la $s1, inputControlCode #$s1 = inputControlCode
for_loop_to_check_equal: addi $t1, $t1, 1 #i++
add $t2, $s1, $t1 #$t2 = inputControlCode + i
lb $t2, 0($t2) #$t2 = inputControlCode[i]
add $t3, $s3, $t1 #$t3 = s + i
lb $t3, 0($t3) #$t3 = s[i]
bne $t2, $t3, isNotEqual #if $t2 != $t3 -> not equal
bne $t1, 2, for_loop_to_check_equal #if $t1 <=2 continue loop
nop
bne $t1, 2, for_loop_to_check_equal
isEqual:
#restore
lw $t3, 0($sp)
addi $sp,$sp,-4
lw $t2, 0($sp)
addi $sp,$sp,-4
lw $s1, 0($sp)
addi $sp,$sp,-4
lw $t1, 0($sp)
addi $sp,$sp,-4
add $t0, $zero, 1 #update $t0
jr $ra
nop
jr $ra
isNotEqual:
#restore
lw $t3, 0($sp)
addi $sp,$sp,-4
lw $t2, 0($sp)
addi $sp,$sp,-4
lw $s1, 0($sp)
addi $sp,$sp,-4
lw $t1, 0($sp)
addi $sp,$sp,-4
add $t0, $zero, $zero #update $t0
jr $ra
nop
jr $ra
#-----------------------------------------------------------
# pushErrorMess procedure, to announce the inputed control code is wrong
# param[in] none
#-----------------------------------------------------------
pushErrorMess: li $v0, 4
la $a0, inputControlCode
syscall
nop
li $v0, 55
la $a0, WRONG_CODE
syscall
nop
nop
j continue
nop
j continue
#-----------------------------------------------------------
# GO procedure, to start running
# param[in] none
#-----------------------------------------------------------
GO: #backup
addi $sp,$sp,4
sw $at,0($sp)
addi $sp,$sp,4
sw $k0,0($sp)
#processing
li $at, MOVING # change MOVING port
addi $k0, $zero,1 # to logic 1,
sb $k0, 0($at) # to start running
#restore
lw $k0, 0($sp)
addi $sp,$sp,-4
lw $at, 0($sp)
addi $sp,$sp,-4
jr $ra
nop
jr $ra
#-----------------------------------------------------------
# STOP procedure, to stop running
# param[in] none
#-----------------------------------------------------------
STOP: #backup
addi $sp,$sp,4
sw $at,0($sp)
#processing
li $at, MOVING # change MOVING port to 0
sb $zero, 0($at) # to stop
#restore
lw $at, 0($sp)
addi $sp,$sp,-4
jr $ra
nop
jr $ra
#-----------------------------------------------------------
# TRACK procedure, to start drawing line
# param[in] none
#-----------------------------------------------------------
TRACK: #backup
addi $sp,$sp,4
sw $at,0($sp)
addi $sp,$sp,4
sw $k0,0($sp)
#processing
li $at, LEAVETRACK # change LEAVETRACK port
addi $k0, $zero,1 # to logic 1,
sb $k0, 0($at) # to start tracking
#restore
lw $k0, 0($sp)
addi $sp,$sp,-4
lw $at, 0($sp)
addi $sp,$sp,-4
jr $ra
nop
jr $ra
#-----------------------------------------------------------
# UNTRACK procedure, to stop drawing line
# param[in] none
#-----------------------------------------------------------
UNTRACK:#backup
addi $sp,$sp,4
sw $at,0($sp)
#processing
li $at, LEAVETRACK # change LEAVETRACK port to 0
sb $zero, 0($at) # to stop drawing tail
#restore
lw $at, 0($sp)
addi $sp,$sp,-4
jr $ra
nop
jr $ra
#-----------------------------------------------------------
# ROTATE_RIGHT procedure, to control robot to rotate
# param[in] nowHeading variable, store heading at present
#-----------------------------------------------------------
ROTATE:
#backup
addi $sp,$sp,4
sw $t1,0($sp)
addi $sp,$sp,4
sw $t2,0($sp)
addi $sp,$sp,4
sw $t3,0($sp)
#processing
li $t1, HEADING # change HEADING port
la $t2, nowHeading
lw $t3, 0($t2) #$t3 is heading at now
sw $t3, 0($t1) # to rotate robot
#restore
lw $t3, 0($sp)
addi $sp,$sp,-4
lw $t2, 0($sp)
addi $sp,$sp,-4
lw $t1, 0($sp)
addi $sp,$sp,-4
jr $ra
nop
jr $ra
#-----------------------------------------------------------
# ROTATE_LEFT procedure, to control robot go right
# param[in] nowHeading variable, store heading at present
#-----------------------------------------------------------
ROTATE_LEFT:
#backup
addi $sp,$sp,4
sw $t1,0($sp)
addi $sp,$sp,4
sw $t2,0($sp)
addi $sp,$sp,4
sw $t3,0($sp)
#processing
li $t1, HEADING # change HEADING port
la $t2, nowHeading
lw $t3, 0($t1) #$t2 is heading at now
addi $t3, $t3, -90 #increase heading by 90*
sw $t3, 0($t2) # update nowHeading
sw $t3, 0($t1) # to rotate robot
#restore
lw $t3, 0($sp)
addi $sp,$sp,-4
lw $t2, 0($sp)
addi $sp,$sp,-4
lw $t1, 0($sp)
addi $sp,$sp,-4
jr $ra
nop
jr $ra
#===============================================================================
# GENERAL INTERRUPT SERVED ROUTINE for all interrupts
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.ktext 0x80000180
#-------------------------------------------------------
# SAVE the current REG FILE to stack
#-------------------------------------------------------
backup:
addi $sp,$sp,4
sw $ra,0($sp)
addi $sp,$sp,4
sw $t1,0($sp)
addi $sp,$sp,4
sw $t2,0($sp)
addi $sp,$sp,4
sw $t3,0($sp)
addi $sp,$sp,4
sw $a0,0($sp)
addi $sp,$sp,4
sw $at,0($sp)
addi $sp,$sp,4
sw $s0,0($sp)
addi $sp,$sp,4
sw $s1,0($sp)
addi $sp,$sp,4
sw $s2,0($sp)
addi $sp,$sp,4
sw $t4,0($sp)
addi $sp,$sp,4
sw $s3,0($sp)
#--------------------------------------------------------
# Processing
#--------------------------------------------------------
get_cod:
li $t1, IN_ADRESS_HEXA_KEYBOARD
li $t2, OUT_ADRESS_HEXA_KEYBOARD
scan_row1:
li $t3, 0x81
sb $t3, 0($t1)
lbu $a0, 0($t2)
bnez $a0, get_code_in_char
scan_row2:
li $t3, 0x82
sb $t3, 0($t1)
lbu $a0, 0($t2)
bnez $a0, get_code_in_char
scan_row3:
li $t3, 0x84
sb $t3, 0($t1)
lbu $a0, 0($t2)
bnez $a0, get_code_in_char
scan_row4:
li $t3, 0x88
sb $t3, 0($t1)
lbu $a0, 0($t2)
bnez $a0, get_code_in_char
get_code_in_char:
beq $a0, KEY_0, case_0
beq $a0, KEY_1, case_1
beq $a0, KEY_2, case_2
beq $a0, KEY_3, case_3
beq $a0, KEY_4, case_4
beq $a0, KEY_5, case_5
beq $a0, KEY_6, case_6
beq $a0, KEY_7, case_7
beq $a0, KEY_8, case_8
beq $a0, KEY_9, case_9
beq $a0, KEY_a, case_a
beq $a0, KEY_b, case_b
beq $a0, KEY_c, case_c
beq $a0, KEY_d, case_d
beq $a0, KEY_e, case_e
beq $a0, KEY_f, case_f
#$s0 store code in char type
case_0: li $s0, '0'
j store_code
case_1: li $s0, '1'
j store_code
case_2: li $s0, '2'
j store_code
case_3: li $s0, '3'
j store_code
case_4: li $s0, '4'
j store_code
case_5: li $s0, '5'
j store_code
case_6: li $s0, '6'
j store_code
case_7: li $s0, '7'
j store_code
case_8: li $s0, '8'
j store_code
case_9: li $s0, '9'
j store_code
case_a: li $s0, 'a'
j store_code
case_b: li $s0, 'b'
j store_code
case_c: li $s0, 'c'
j store_code
case_d: li $s0, 'd'
j store_code
case_e: li $s0, 'e'
j store_code
case_f: li $s0, 'f'
j store_code
store_code:
la $s1, inputControlCode
la $s2, lengthControlCode
lw $s3, 0($s2) #$s3 = strlen(inputControlCode)
addi $t4, $t4, -1 #$t4 = i
for_loop_to_store_code:
addi $t4, $t4, 1
bne $t4, $s3, for_loop_to_store_code
add $s1, $s1, $t4 #$s1 = inputControlCode + i
sb $s0, 0($s1) #inputControlCode[i] = $s0
addi $s0, $zero, '\n' #add '\n' character to end of string
addi $s1, $s1, 1 #add '\n' character to end of string
sb $s0, 0($s1) #add '\n' character to end of string
addi $s3, $s3, 1
sw $s3, 0($s2) #update length of input control code
#--------------------------------------------------------
# Evaluate the return address of main routine
# epc <= epc + 4
#--------------------------------------------------------
next_pc:
mfc0 $at, $14 # $at <= Coproc0.$14 = Coproc0.epc
addi $at, $at, 4 # $at = $at + 4 (next instruction)
mtc0 $at, $14 # Coproc0.$14 = Coproc0.epc <= $at
#--------------------------------------------------------
# RESTORE the REG FILE from STACK
#--------------------------------------------------------
restore:
lw $s3, 0($sp)
addi $sp,$sp,-4
lw $t4, 0($sp)
addi $sp,$sp,-4
lw $s2, 0($sp)
addi $sp,$sp,-4
lw $s1, 0($sp)
addi $sp,$sp,-4
lw $s0, 0($sp)
addi $sp,$sp,-4
lw $at, 0($sp)
addi $sp,$sp,-4
lw $a0, 0($sp)
addi $sp,$sp,-4
lw $t3, 0($sp)
addi $sp,$sp,-4
lw $t2, 0($sp)
addi $sp,$sp,-4
lw $t1, 0($sp)
addi $sp,$sp,-4
lw $ra, 0($sp)
addi $sp,$sp,-4
return: eret # Return from exception