-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlab2_micro_custom.txt
781 lines (676 loc) · 21.8 KB
/
lab2_micro_custom.txt
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
begin
{
fetch: (T2, C0),
(TA, R, BW=11, M1=1, C1=1),
(M2, C2, T1, C3),
(A0, B=0, C=0)
}
#
# ALU
#
and reg1 reg2 reg3 {
co=000000,
cop=0000,
nwords=1,
reg1=reg(25,21),
reg2=reg(20,16),
reg3=reg(15,11),
{
(MC=1, MR=0, SELA=1011, SELB=10000, MA=0, MB=0, SELCOP=1, T6=1, SELC=10101, LC=1, SELP=11, M7, C7, A0=1, B=1, C=0)
}
}
or reg1 reg2 reg3 {
co=000000,
cop=0001,
nwords=1,
reg1=reg(25,21),
reg2=reg(20,16),
reg3=reg(15,11),
{
(MC=1, MR=0, SELA=1011, SELB=10000, MA=0, MB=0, SELCOP=10, T6=1, SELC=10101, LC=1, SELP=11, M7, C7, A0=1, B=1, C=0)
}
}
not reg {
co=000000,
cop=0010,
nwords=1,
reg=reg(25,21),
{
(MC=1, MR=0, SELA=10101, MA=0, SELCOP=11, T6=1, SELC=10101, LC=1, SELP=11, M7, C7, A0=1, B=1, C=0)
}
}
xor reg1 reg2 reg3 {
co=000000,
cop=0011,
nwords=1,
reg1=reg(25,21),
reg2=reg(20,16),
reg3=reg(15,11),
{
(MC=1, MR=0, SELA=1011, SELB=10000, MA=0, MB=0, SELCOP=100, T6=1, SELC=10101, LC=1, SELP=11, M7, C7, A0=1, B=1, C=0)
}
}
add reg1 reg2 reg3 {
co=000000,
cop=1001,
nwords=1,
reg1=reg(25,21),
reg2=reg(20,16),
reg3=reg(15,11),
{
(MC=1, MR=0, SELA=1011, SELB=10000, MA=0, MB=0, SELCOP=1010, T6=1, SELC=10101, LC=1, SELP=11, M7, C7, A0=1, B=1, C=0)
}
}
sub reg1 reg2 reg3 {
co=000000,
cop=1010,
nwords=1,
reg1=reg(25,21),
reg2=reg(20,16),
reg3=reg(15,11),
{
(MC=1, MR=0, SELB=1011, SELA=10000, MA=0, MB=0, SELCOP=1011, T6=1, SELC=10101, LC=1, SELP=11, M7, C7, A0=1, B=1, C=0)
}
}
mul reg1 reg2 reg3 {
co=000000,
cop=1011,
nwords=1,
reg1=reg(25,21),
reg2=reg(20,16),
reg3=reg(15,11),
{
(MC=1, MR=0, SELA=1011, SELB=10000, MA=0, MB=0, SELCOP=1100, T6=1, SELC=10101, LC=1, SELP=11, M7, C7, A0=1, B=1, C=0)
}
}
div reg1 reg2 reg3 {
co=000000,
cop=1100,
nwords=1,
reg1=reg(25,21),
reg2=reg(20,16),
reg3=reg(15,11),
{
(MC=1, MR=0, SELB=1011, SELA=10000, MA=0, MB=0, SELCOP=1101, T6=1, SELC=10101, LC=1, SELP=11, M7, C7, A0=1, B=1, C=0)
}
}
srl reg1 reg2 val {
co=010111,
nwords=1,
reg1=reg(25,21),
reg2=reg(20,16),
val=inm(5,0),
{
(SE=1, OFFSET=0, SIZE=110, T3=1, C4=1),
(MC=1, MR=0, SELA=10000, SELB=10000, MA=0, MB=0, SELCOP=1, T6=1, SELC=10101),
loop9: (A0=0, B=0, C=110, MADDR=bck2ftch),
(MC=1, MR=0, SELA=10101, SELB=10101, MA=0, MB=0, SELCOP=101, T6=1, LC=1, SELC=10101),
(MC=1, MR=0, MA=1, MB=11, SELCOP=1011, T6=1, C4=1, SELP=11, M7, C7),
(A0=0, B=1, C=0, MADDR=loop9),
bck9ftch: (A0=1, B=1, C=0)
}
}
#
# MV/L*
#
mv reg1 reg2 {
co=000001,
nwords=1,
reg1=reg(25,21),
reg2=reg(20,16),
{
(SELA=10000, T9, SELC=10101, LC, A0=1, B=1, C=0)
}
}
li reg val {
co=000010,
nwords=1,
reg=reg(25,21),
val=inm(15,0),
{
(SE=1, OFFSET=0, SIZE=10000, SE=1, T3=1, LC=1, MR=0, SELC=10101, A0=1, B=1, C=0)
}
}
liu reg val {
co=111100,
nwords=1,
reg=reg(25,21),
val=inm(15,0),
{
(SE=1, OFFSET=0, SIZE=10000, SE=0, T3=1, LC=1, MR=0, SELC=10101, A0=1, B=1, C=0)
}
}
la reg addr {
co=000011,
nwords=1,
reg=reg(25,21),
addr=address(15,0)abs,
{
(SE=0, OFFSET=0, SIZE=10000, T3=1, LC=1, MR=0, SELC=10101, A0=1, B=1, C=0)
}
}
la reg addr {
co=111111,
nwords=2,
reg=reg(25,21),
addr=address(63,32)abs,
{
(SE=0, OFFSET=0, SIZE=10000, T3=1, LC=1, MR=0, SELC=10101, A0=1, B=1, C=0)
}
}
lw reg addr {
co=000100,
nwords=1,
reg=reg(25,21),
addr=address(15,0)abs,
{
(SE=0, OFFSET=0, SIZE=10000, T3=1, C0=1),
(TA=1, R=1, BW=11, M1=1, C1=1),
(T1=1, LC=1, MR=0, SELC=10101, A0=1, B=1, C=0)
}
}
sw reg addr {
co=000101,
nwords=1,
reg=reg(25,21),
addr=address(15,0)abs,
{
(SE=0, OFFSET=0, SIZE=10000, T3=1, C0=1),
(MR=0, SELA=10101, T9=1, M1=0, C1=1),
(BW=11, TA=1, TD=1, W=1, A0=1, B=1, C=0)
}
}
lw reg1 (reg2) {
co=011010,
nwords=1,
reg1 = reg(25,21),
reg2 = reg(20,16),
{
(MR=0, SELA=10000, T9=1, C0),
(TA=1, R=1, BW=11, M1=1, C1=1),
(T1=1, LC=1, MR=0, SELC=10101, SE=1, A0=1, B=1, C=0)
}
}
sw reg1 (reg2) {
co=011011,
nwords=1,
reg1 = reg(25,21),
reg2 = reg(20,16),
{
(MR=0, SELA=10000, T9=1, C0),
(MR=0, SELA=10101, T9=1, M1=0, C1=1),
(BW=11, TA=1, TD=1, W=1, A0=1, B=1, C=0)
}
}
lb reg addr {
co=001000,
nwords=1,
reg=reg(25,21),
addr=address(15,0)abs,
{
(SE=0, OFFSET=0, SIZE=10000, T3=1, C0=1),
(TA=1, R=1, BW=00, SE=1, M1=1, C1=1),
(T1=1, LC=1, MR=0, SELC=10101, A0=1, B=1, C=0)
}
}
sb reg addr {
co=001001,
nwords=1,
reg=reg(25,21),
addr=address(15,0)abs,
{
(SE=0, OFFSET=0, SIZE=10000, T3=1, C0=1),
(MR=0, SELA=10101, T9=1, M1=0, C1=1),
(BW=0, TA=1, TD=1, W=1, A0=1, B=1, C=0)
}
}
#
# b*
#
b offset {
co=001100,
nwords=1,
offset=address(15,0)rel,
{
(T2, C4),
(SE=1, OFFSET=0, SIZE=10000, T3, C5),
(MA=1, MB=1, MC=1, SELCOP=1010, T6, C2, A0=1, B=1, C=0)
}
}
beq reg reg offset {
co=001101,
nwords=1,
reg=reg(25,21),
reg=reg(20,16),
offset=address(15,0)rel,
{
(T8, C5),
(SELA=10101, SELB=10000, MC=1, SELCOP=1011, SELP=11, M7, C7),
(A0=0, B=1, C=110, MADDR=bck2ftch),
(T5, M7=0, C7),
(T2, C4),
(SE=1, OFFSET=0, SIZE=10000, T3, C5),
(MA=1, MB=1, MC=1, SELCOP=1010, T6, C2, A0=1, B=1, C=0),
bck2ftch: (T5, M7=0, C7),
(A0=1, B=1, C=0)
}
}
bne reg reg offset {
co=001110,
nwords=1,
reg=reg(25,21),
reg=reg(20,16),
offset=address(15,0)rel,
{
(T8, C5),
(SELA=10101, SELB=10000, MC=1, SELCOP=1011, SELP=11, M7, C7),
(A0=0, B=0, C=110, MADDR=bck3ftch),
(T5, M7=0, C7),
(T2, C4),
(SE=1, OFFSET=0, SIZE=10000, T3, C5),
(MA=1, MB=1, MC=1, SELCOP=1010, T6, C2, A0=1, B=1, C=0),
bck3ftch: (T5, M7=0, C7),
(A0=1, B=1, C=0)
}
}
bge reg reg offset {
co=001111,
nwords=1,
reg=reg(25,21),
reg=reg(20,16),
offset=address(15,0)rel,
{
(T8, C5),
(SELA=10101, SELB=10000, MC=1, SELCOP=1011, SELP=11, M7, C7),
(A0=0, B=0, C=111, MADDR=bck4ftch),
(T5, M7=0, C7),
(T2, C4),
(SE=1, OFFSET=0, SIZE=10000, T3, C5),
(MA=1, MB=1, MC=1, SELCOP=1010, T6, C2, A0=1, B=1, C=0),
bck4ftch: (T5, M7=0, C7),
(A0=1, B=1, C=0)
}
}
blt reg reg offset {
co=010000,
nwords=1,
reg=reg(25,21),
reg=reg(20,16),
offset=address(15,0)rel,
{
(T8, C5),
(SELA=10101, SELB=10000, MC=1, SELCOP=1011, SELP=11, M7, C7),
(A0=0, B=1, C=111, MADDR=bck5ftch),
(T5, M7=0, C7),
(T2, C4),
(SE=1, OFFSET=0, SIZE=10000, T3, C5),
(MA=1, MB=1, MC=1, SELCOP=1010, T6, C2, A0=1, B=1, C=0),
bck5ftch: (T5, M7=0, C7),
(A0=1, B=1, C=0)
}
}
bgt reg reg offset {
co=010001,
nwords=1,
reg=reg(25,21),
reg=reg(20,16),
offset=address(15,0)rel,
{
(T8, C5),
(SELA=10101, SELB=10000, MC=1, SELCOP=1011, SELP=11, M7, C7),
(A0=0, B=0, C=111, MADDR=bck6ftch),
(A0=0, B=0, C=110, MADDR=bck6ftch),
(T5, M7=0, C7),
(T2, C4),
(SE=1, OFFSET=0, SIZE=10000, T3, C5),
(MA=1, MB=1, MC=1, SELCOP=1010, T6, C2, A0=1, B=1, C=0),
bck6ftch: (T5, M7=0, C7),
(A0=1, B=1, C=0)
}
}
ble reg reg offset {
co=010010,
nwords=1,
reg=reg(25,21),
reg=reg(20,16),
offset=address(15,0)rel,
{
(T8, C5),
(SELA=10101, SELB=10000, MC=1, SELCOP=1011, SELP=11, M7, C7),
(A0=0, B=0, C=111, MADDR=ble_ys),
(A0=0, B=0, C=110, MADDR=ble_ys),
(T5, M7=0, C7),
(A0=1, B=1, C=0),
ble_ys: (T5, M7=0, C7),
(T2, C4),
(SE=1, OFFSET=0, SIZE=10000, T3, C5),
(MA=1, MB=1, MC=1, SELCOP=1010, T6, C2, A0=1, B=1, C=0)
}
}
#
# j*
#
j addr {
co=010011,
nwords=1,
addr=address(15,0)abs,
{
(SE=0, OFFSET=0, SIZE=10000, T3=1, M2=0, C2=1, A0=1, B=1, C=0)
}
}
jal addr {
co=010100,
nwords=1,
addr=address(15,0)abs,
{
(T2, SELC=11111, MR=1, LC),
(SE=0, OFFSET=0, SIZE=10000, T3=1, M2=0, C2=1, A0=1, B=1, C=0)
}
}
jr reg1 {
co=010101,
nwords=1,
reg1=reg(25,21),
{
(SELA=10101, T9=1, C2=1, A0=1, B=1, C=0)
}
}
#
# IN/OUT
#
in reg val {
co=001010,
nwords=1,
reg=reg(25,21),
val=inm(15,0),
{
(SE=0, OFFSET=0, SIZE=10000, T3=1, C0=1),
(TA=1, IOR=1, M1=1, C1=1),
(T1=1, LC=1, MR=0, SELC=10101, A0=1, B=1, C=0)
}
}
out reg val {
co=001011,
nwords=1,
reg=reg(25,21),
val=inm(15,0),
{
(SE=0, OFFSET=0, SIZE=10000, T3=1, C0=1),
(MR=0, SELA=10101, T9=1, M1=0, C1=1),
(TA=1, TD=1, IOW=1, A0=1, B=1, C=0)
}
}
#
# Misc
#
nop {
co=010110,
nwords=1,
{
(A0=1, B=1, C=0)
}
}
#
# Register section
#
registers
{
0=$zero,
1=$at,
2=$v0,
3=$v1,
4=$a0,
5=$a1,
6=$a2,
7=$a3,
8=$t0,
9=$t1,
10=$t2,
11=$t3,
12=$t4,
13=$t5,
14=$t6,
15=$t7,
16=$s0,
17=$s1,
18=$s2,
19=$s3,
20=$s4,
21=$s5,
22=$s6,
23=$s7,
24=$t8,
25=$t9,
26=$k0,
27=$k1,
28=$gp,
29=$sp (stack_pointer),
30=$fp,
31=$ra
}
# -----------------------------------------------------------------------------
# vectorial_2_mc.txt
#
# Lab assignment 2: Microprogramming Lab
# Implementation of subroutines addv_2 and seqv_2.
#
# @author Guillermo Escobero & Raul Olmedo
# @date November 2016
# -----------------------------------------------------------------------------
# -----------------------------------------------------------------------------
# Adds two vectors with the same number of elements and stores the resulting
# vector in the memory.
#
# Returns -1 in the first register if the number of elements provided is not
# correct.
#
# @param Register with the memory address where will be stored the resulting vector
# @param Register with the memory address of the first vector
# @param Register with the memory address of the second vector
# @param Register with the number of elements of the vectors
# -----------------------------------------------------------------------------
addv_2 reg1 reg2 reg3 reg4 {
co=011000,
nwords=1,
reg1=reg(25,21), # R0
reg2=reg(20,16), # V0
reg3=reg(15,11), # V1
reg4=reg(10,6), # number of elements of the vectors
{
# To begin, we save the registers reg1, reg2 and reg3 into the stack to
# preserve the values once the microprogram has ended
# First step: subtract 4 to the stack pointer register ($sp)
(SELA=11101, MR=1, MA=0, MB=10, SELCOP=1011, MC=1, T6, SELC=11101, LC=1),
# Step 2: put into the address set by the stack pointer the value that must
# be preserved (reg1)
(SELA=11101, MR=1, T9, C0),
(SELB=10101, MR=0, T10, M1=0, C1),
(BW=11, TA=1, TD=1, W=1),
# Repeat step 1
(SELA=11101, MR=1, MA=0, MB=10, SELCOP=1011, MC=1, T6, SELC=11101, LC=1),
# Step2 (reg2)
(SELA=11101, MR=1, T9, C0),
(SELB=10000, MR=0, T10, M1=0, C1),
(BW=11, TA=1, TD=1, W=1),
# Repeat step 1
(SELA=11101, MR=1, MA=0, MB=10, SELCOP=1011, MC=1, T6, SELC=11101, LC=1),
# Step2 (reg3)
(SELA=11101, MR=1, T9, C0),
(SELB=01011, MR=0, T10, M1=0, C1),
(BW=11, TA=1, TD=1, W=1),
# We start the procedure comparing the number of elements(reg4), if it is
# negative, go to error1 label
(T8=1, C5=1),
(SELB=00000, MR=1, T10=1, C5),
(SELA=00110, MR=0, MA=0, MB=1, SELCOP=1011, MC=1, SELP=11, M7=1, C7=1),
(A0=0, B=0, C=0111, MADDR=error1),
# RT1 is set to 0 to start counting the number of iterations
(SELA=0000, MR=1, T9, C4),
# Compare the number in RT1 (where the counter is set) to the number of
# elements in reg4 (given by the user)
begin1:
(SELB=00110, MR=0, MB=0, MA=1, SELCOP=1011, MC=1, SELP=11, M7=1, C7=1),
(A0=0, B=0, C=0110, MADDR=restore1),
# Start loading the first word in the reg2
(MR=0, SELA=10000, T9=1, C0),
(TA=1, R=1, BW=11, M1=1, C1=1),
# We start retrieving the second word, in reg3
(MR=0, SELB=01011, T10=1, C0),
# Store the first word into RT2
(T1=1, C5, TA=1, R=1, BW=11, M1=1, C1=1),
# Move the value of RT1 into RT3
(SELB=00000, MR=1, SELCOP=1010, MC=1, MA=1, MB=0, C6),
# Store the second word into RT1
(T1=1, C4),
# We introduce the numbers in the ALU, operate them and then save the sum
# into RT2
(MA=1, MB=1, SELCOP=1010, MC=1, T6, C5),
# Move the value of RT3 to RT1 (to keep the value of the counter unchanged)
(T7, C4),
# We get the address of R0 (reg1) and store in it the result of the sum (RT2)
(MR=0, SELA=10101, T9=1, C0),
(T5=1, M1=0, C1=1),
(BW=11, TA=1, TD=1, W=1),
# Increment the memory address of reg1, reg2 and reg3 (+4)
(MC=1, MR=0, SELA=10101, MA=0, MB=10, SELCOP=1010, T6, SELC=10101, LC=1),
(MC=1, MR=0, SELA=10000, MA=0, MB=10, SELCOP=1010, T6, SELC=10000, LC=1),
(MC=1, MR=0, SELA=01011, MA=0, MB=10, SELCOP=1010, T6, SELC=01011, LC=1),
# Increment the counter by 1
(MA=1, MB=11, SELCOP=1010, MC=1, T6, C4),
# Go to the label begin1 and start again the process
(A0=0, B=1, C=0, MADDR=begin1),
# Label reached when the size of the arrays given in reg4 is negative, it
# stores a -1 in reg1 and goes to label restore1
error1:
(MC=1, RA=0, MA=0, MB=11, SELCOP=1011, T6, SELC=10101, LC=1),
(A0=0, B=1, C=0, MADDR=restore1),
restore1:
# Step 1: retrieve the last value saved in the stack pointer
(SELA=11101, MR=1, T9, C0),
(TA=1, R=1, BW=11, M1=1, C1),
(SELC=01011, MR=0, T1, LC),
# Step 2: Add 4 to the stack pointer to access the next value stored
(SELA=11101, MR=1, MA=0, MB=10, SELCOP=1010, MC=1, T6, SELC=11101, LC=1),
# Step1
(SELA=11101, MR=1, T9, C0),
(TA=1, R=1, BW=11, M1=1, C1),
(SELC=10000, MR=0, T1, LC),
# Step2
(SELA=11101, MR=1, MA=0, MB=10, SELCOP=1010, MC=1, T6, SELC=11101, LC=1),
# Step1
(SELA=11101, MR=1, T9, C0),
(TA=1, R=1, BW=11, M1=1, C1),
(SELC=10101, MR=0, T1, LC),
# Step2
(SELA=11101, MR=1, MA=0, MB=10, SELCOP=1010, MC=1, T6, SELC=11101, LC=1),
# Go to fetch to end the program
(A0=1, B=1, C=0)
}
}
# -----------------------------------------------------------------------------
# Compares two vectors with the same number of elements and returns 1 in the
# first register if the vectors are equal, or 0 if are different.
#
# Returns -1 in the first register if the number of elements provided is not
# correct.
#
# @param Register where will be stored the result (0 or 1)
# @param Register with the memory address of the first vector
# @param Register with the memory address of the second vector
# @param Register with the number of elements of the vectors
# -----------------------------------------------------------------------------
seqv_2 reg1 reg2 reg3 reg4 {
co=011001,
nwords=1,
reg1=reg(25,21), # R0
reg2=reg(20,16), # V0
reg3=reg(15,11), # V1
reg4=reg(10,6), # number of elements of the vectors
{
# To begin, we save the registers reg2 and reg3 into the stack to preserve
# the values once the microprogram has ended
# First step: subtract 4 to the stack pointer
(SELA=11101, MR=1, MA=0, MB=10, SELCOP=1011, MC=1, T6, SELC=11101, LC=1),
# Step 2: put into the address set by the stack pointer the value that must
# be preserved (reg2)
(SELA=11101, MR=1, T9, C0),
(SELB=10000, MR=0, T10, M1=0, C1),
(BW=11, TA=1, TD=1, W=1),
# Step1
(SELA=11101, MR=1, MA=0, MB=10, SELCOP=1011, MC=1, T6, SELC=11101, LC=1),
# Step2 (reg3)
(SELA=11101, MR=1, T9, C0),
(SELB=01011, MR=0, T10, M1=0, C1),
(BW=11, TA=1, TD=1, W=1),
# We start the procedure comparing the number of elements, if it is negative,
# go to error1 label
(T8=1, C5=1),
(SELB=00000, MR=1, T10=1, C5),
(SELA=00110, MR=0, MA=0, MB=1, SELCOP=1011, MC=1, SELP=11, M7=1, C7=1),
(A0=0, B=0, C=0111, MADDR=error2),
# RT1 is set to 0 to start counting the number of iterations
(SELA=0000, MR=1, T9, C4),
# Compare the number in RT1 (where the counter is set) to the number of
# elements in reg4 (given by the user)
begin2:
(SELB=00110, MR=0, MB=0, MA=1, SELCOP=1011, MC=1, SELP=11, M7=1, C7=1),
(A0=0, B=0, C=0110, MADDR=end2),
# Start loading the first word stored in the reg2
(MR=0, SELA=10000, T9=1, C0),
(TA=1, R=1, BW=11, M1=1, C1=1),
# We start retrieving the second word, in reg3
(MR=0, SELB=01011, T10=1, C0),
# Store the first word into RT2
(T1=1, C5, TA=1, R=1, BW=11, M1=1, C1=1),
# Move the value of RT1 into RT3 to avoid overriding the value of the
# counter set in RT1
(SELB=00000, MR=1, SELCOP=1010, MC=1, MA=1, MB=0, C6),
# Store the second word into RT1
(T1=1, C4),
# We introduce the values in the ALU, we operate using the XOR operation
# code, then it checks if it is 0 (if it is different it goes to label different)
(MA=1, MB=1, SELCOP=0100, MC=1, SELP=11, M7, C7),
(A0=0, B=1, C=0110, MADDR=different),
# Move the value of RT3 to RT1 (restore the value of the counter)
(T7, C4),
# Increment the memory address of reg1, reg2 and reg3 (+4)
(MC=1, MR=0, SELA=10101, MA=0, MB=10, SELCOP=1010, T6, SELC=10101, LC=1),
(MC=1, MR=0, SELA=10000, MA=0, MB=10, SELCOP=1010, T6, SELC=10000, LC=1),
(MC=1, MR=0, SELA=01011, MA=0, MB=10, SELCOP=1010, T6, SELC=01011, LC=1),
# Increment the counter by 1
(MA=1, MB=11, SELCOP=1010, MC=1, T6, C4),
# Go to the label begin2 and start again the process
(A0=0, B=1, C=0, MADDR=begin2),
# Label reached when the size of the arrays given in reg4 is negative, it
# stores a -1 in reg1 and goes to label end2
error2:
(MC=1, RA=0, MA=0, MB=11, SELCOP=1011, T6, SELC=10101, LC=1),
(A0=0, B=1, C=0, MADDR=end2),
# If during the process a different number is detected, this label is
# reached, setting reg1 to 0 and going to restore2 to end the microprogram
different:
(SELA=00000, MR=1, T9, C5),
(SELC=10101, MR=0, T5, LC),
(A0=0, B=1, C=0, MADDR=restore2),
# Sets reg1 to 1 (since all the elements are equal) and goes to restore2
end2:
(SELA=00000, MR=1, MA=0, MB=11, SELCOP=1010, MC=1, C6),
(SELC=10101, MR=0, T7, LC),
(A0=0, B=1, C=0, MADDR=restore2),
restore2:
# Step 1: retrieve the last value saved in the stack pointer (reg2)
(SELA=11101, MR=1, T9, C0),
(TA=1, R=1, BW=11, M1=1, C1),
(SELC=01011, MR=0, T1, LC),
# Step 2: add 4 to the stack pointer to access the next value stored
(SELA=11101, MR=1, MA=0, MB=10, SELCOP=1010, MC=1, T6, SELC=11101, LC=1),
# Step1
(SELA=11101, MR=1, T9, C0),
(TA=1, R=1, BW=11, M1=1, C1),
(SELC=10000, MR=0, T1, LC),
# Step2
(SELA=11101, MR=1, MA=0, MB=10, SELCOP=1010, MC=1, T6, SELC=11101, LC=1),
# Jump to fetch
(A0=1, B=1, C=0)
}
}