-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontrol.v
1085 lines (940 loc) · 31.9 KB
/
control.v
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
/*
* Copyright (c) 2006, Peter M. Chen. All rights reserved. This software is
* supplied as is without expressed or implied warranties of any kind.
*/
module control(
input wire clock,
input wire clock_valid,
input wire reset,
input wire [31:0] opcode_out,
input wire equal_out,
input wire lt_out,
output reg pc_write, // write the PC
output reg pc_drive, // drive PC onto bus
output reg plus1_drive, // drive result of plus1 onto bus
output reg op1_write, // write op1
output reg op2_write, // write op2
output reg add_drive, // drive result of add onto bus
output reg sub_drive, // drive result of sub onto bus
output reg mult_drive, // drive result of mult onto bus
output reg div_drive, // drive result of div onto bus
output reg bit_and_drive, // drive result of bit_and onto bus
output reg bit_or_drive, // drive result of bit_or onto bus
output reg bit_not_drive, // drive result of bit_not onto bus
output reg sl_drive, // drive result of sl onto bus
output reg sr_drive, // drive result of sr onto bus
output reg opcode_write, // write opcode
output reg arg1_write, // write arg1
output reg arg1_drive, // drive arg1 onto bus
output reg arg2_write, // write arg2
output reg arg2_drive, // drive arg2 onto bus
output reg arg3_write, // write arg2
output reg arg3_drive, // drive arg2 onto bus
output reg address_write, // write memory's address register
output reg memory_write, // write memory with data from bus
output reg memory_drive); // read memory; drive onto bus
parameter state_reset = 8'h0;
parameter state_fetch1 = 8'h1;
parameter state_fetch2 = 8'h2;
parameter state_fetch3 = 8'h3;
parameter state_fetch4 = 8'h4;
parameter state_fetch5 = 8'h5;
parameter state_fetch6 = 8'h6;
parameter state_fetch7 = 8'h7;
parameter state_fetch8 = 8'h8;
parameter state_decode = 8'h9;
parameter state_halt = 8'ha;
parameter state_add1 = 8'hb;
parameter state_add2 = 8'hc;
parameter state_add3 = 8'hd;
parameter state_add4 = 8'he;
parameter state_add5 = 8'hf;
parameter state_add6 = 8'h10;
parameter state_sub1 = 8'h11;
parameter state_sub2 = 8'h12;
parameter state_sub3 = 8'h13;
parameter state_sub4 = 8'h14;
parameter state_sub5 = 8'h15;
parameter state_sub6 = 8'h16;
parameter state_mult1 = 8'h17;
parameter state_mult2 = 8'h18;
parameter state_mult3 = 8'h19;
parameter state_mult4 = 8'h1a;
parameter state_mult5 = 8'h1b;
parameter state_mult6 = 8'h1c;
parameter state_mult7 = 8'h1d;
parameter state_div1 = 8'h1e;
parameter state_div2 = 8'h1f;
parameter state_div3 = 8'h20;
parameter state_div4 = 8'h21;
parameter state_div5 = 8'h22;
parameter state_div6 = 8'h23;
parameter state_div7 = 8'h24;
parameter state_div8 = 8'h25;
parameter state_div9 = 8'h26;
parameter state_div10 = 8'h27;
parameter state_div11 = 8'h28;
parameter state_div12 = 8'h29;
parameter state_div13 = 8'h2a;
parameter state_div14 = 8'h2b;
parameter state_div15 = 8'h2c;
parameter state_div16 = 8'h2d;
parameter state_div17 = 8'h2e;
parameter state_div18 = 8'h2f;
parameter state_cp1 = 8'h30;
parameter state_cp2 = 8'h31;
parameter state_cp3 = 8'h32;
parameter state_cp4 = 8'h33;
parameter state_and1 = 8'h34;
parameter state_and2 = 8'h35;
parameter state_and3 = 8'h36;
parameter state_and4 = 8'h37;
parameter state_and5 = 8'h38;
parameter state_and6 = 8'h39;
parameter state_or1 = 8'h3a;
parameter state_or2 = 8'h3b;
parameter state_or3 = 8'h3c;
parameter state_or4 = 8'h3d;
parameter state_or5 = 8'h3e;
parameter state_or6 = 8'h3f;
parameter state_not1 = 8'h40;
parameter state_not2 = 8'h41;
parameter state_not3 = 8'h42;
parameter state_not4 = 8'h43;
parameter state_sl1 = 8'h44;
parameter state_sl2 = 8'h45;
parameter state_sl3 = 8'h46;
parameter state_sl4 = 8'h47;
parameter state_sl5 = 8'h48;
parameter state_sl6 = 8'h49;
parameter state_sr1 = 8'h4a;
parameter state_sr2 = 8'h4b;
parameter state_sr3 = 8'h4c;
parameter state_sr4 = 8'h4d;
parameter state_sr5 = 8'h4e;
parameter state_sr6 = 8'h4f;
parameter state_be1 = 8'h50;
parameter state_be2 = 8'h51;
parameter state_be3 = 8'h52;
parameter state_be4 = 8'h53;
parameter state_be5 = 8'h54;
parameter state_be6 = 8'h55;
parameter state_bne1 = 8'h56;
parameter state_bne2 = 8'h57;
parameter state_bne3 = 8'h58;
parameter state_bne4 = 8'h59;
parameter state_bne5 = 8'h5a;
parameter state_bne6 = 8'h5b;
parameter state_blt1 = 8'h5c;
parameter state_blt2 = 8'h5d;
parameter state_blt3 = 8'h5e;
parameter state_blt4 = 8'h5f;
parameter state_blt5 = 8'h60;
parameter state_blt6 = 8'h61;
//Call
parameter state_call1 = 8'h62;
parameter state_call2 = 8'h63;
parameter state_call3 = 8'h64;
//cpfa
parameter state_cpfa1 = 8'h65;
parameter state_cpfa2 = 8'h66;
parameter state_cpfa3 = 8'h67;
parameter state_cpfa4 = 8'h68;
parameter state_cpfa5 = 8'h69;
parameter state_cpfa6 = 8'h6a;
parameter state_cpfa7 = 8'h6b;
parameter state_cpfa8 = 8'h6c;
//cpta
parameter state_cpta1 = 8'h6d;
parameter state_cpta2 = 8'h6e;
parameter state_cpta3 = 8'h6f;
parameter state_cpta4 = 8'h70;
parameter state_cpta5 = 8'h71;
parameter state_cpta6 = 8'h72;
parameter state_cpta7 = 8'h73;
parameter state_cpta8 = 8'h74;
//ret
parameter state_ret1 = 8'h75;
parameter state_ret2 = 8'h76;
parameter E100_HALT = 32'h0000;
parameter E100_ADD = 32'h0001;
parameter E100_SUB = 32'h0002;
parameter E100_MULT = 32'h0003;
parameter E100_DIV = 32'h0004;
parameter E100_CP = 32'h0005;
parameter E100_AND = 32'h0006;
parameter E100_OR = 32'h0007;
parameter E100_NOT = 32'h0008;
parameter E100_SL = 32'h0009;
parameter E100_SR = 32'h000a;
parameter E100_CPFA = 32'h000b;
parameter E100_CPTA = 32'h000c;
parameter E100_BE = 32'h000d;
parameter E100_BNE = 32'h000e;
parameter E100_BLT = 32'h000f;
parameter E100_CALL = 32'h0010;
parameter E100_RET = 32'h0011;
reg [7:0] state;
reg [7:0] next_state;
always @* begin
// default values for control signals
pc_write = 1'b0;
pc_drive = 1'b0;
op1_write = 1'b0;
op2_write = 1'b0;
add_drive = 1'b0;
sub_drive = 1'b0;
bit_and_drive = 1'b0;
bit_or_drive = 1'b0;
bit_not_drive = 1'b0;
sl_drive = 1'b0;
sr_drive = 1'b0;
mult_drive = 1'b0;
div_drive = 1'b0;
plus1_drive = 1'b0;
opcode_write = 1'b0;
arg1_write = 1'b0;
arg1_drive = 1'b0;
arg2_write = 1'b0;
arg2_drive = 1'b0;
arg3_write = 1'b0;
arg3_drive = 1'b0;
address_write = 1'b0;
memory_write = 1'b0;
memory_drive = 1'b0;
next_state = state_reset;
case (state)
state_reset: begin
next_state = state_fetch1;
end
// fetch the current instruction
state_fetch1: begin
// copy pc to address
pc_drive = 1'b1;
address_write = 1'b1;
next_state = state_fetch2;
end
state_fetch2: begin
// read opcode from memory
memory_drive = 1'b1;
opcode_write = 1'b1;
next_state = state_fetch3;
end
state_fetch3: begin
// increment pc; copy new value to address
plus1_drive = 1'b1;
pc_write = 1'b1;
address_write = 1'b1;
next_state = state_fetch4;
end
state_fetch4: begin
// read arg1 from memory
memory_drive = 1'b1;
arg1_write = 1'b1;
next_state = state_fetch5;
end
state_fetch5: begin
// increment pc; copy new value to address
plus1_drive = 1'b1;
pc_write = 1'b1;
address_write = 1'b1;
next_state = state_fetch6;
end
state_fetch6: begin
// read arg2 from memory
memory_drive = 1'b1;
arg2_write = 1'b1;
next_state = state_fetch7;
end
state_fetch7: begin
// increment pc; copy new value to address
plus1_drive = 1'b1;
pc_write = 1'b1;
address_write = 1'b1;
next_state = state_fetch8;
end
state_fetch8: begin
// read arg3 from memory
memory_drive = 1'b1;
arg3_write = 1'b1;
next_state = state_decode;
end
// decode the current instruction
state_decode: begin
// transfer address of (probable) next instruction to pc
plus1_drive = 1'b1;
pc_write = 1'b1;
// choose next state, based on opcode
if (opcode_out == E100_HALT) begin
next_state = state_halt;
end else if (opcode_out == E100_ADD) begin
next_state = state_add1;
end else if (opcode_out == E100_SUB) begin
next_state = state_sub1;
end else if (opcode_out == E100_MULT) begin
next_state = state_mult1;
end else if (opcode_out == E100_DIV) begin
next_state = state_div1;
end else if (opcode_out == E100_CP) begin
next_state = state_cp1;
end else if (opcode_out == E100_AND) begin
next_state = state_and1;
end else if (opcode_out == E100_OR) begin
next_state = state_or1;
end else if (opcode_out == E100_NOT) begin
next_state = state_not1;
end else if (opcode_out == E100_SL) begin
next_state = state_sl1;
end else if (opcode_out == E100_SR) begin
next_state = state_sr1;
end else if (opcode_out == E100_BE) begin
next_state = state_be1;
end else if (opcode_out == E100_BNE) begin
next_state = state_bne1;
end else if (opcode_out == E100_BLT) begin
next_state = state_blt1;
end else if (opcode_out == E100_CALL) begin
next_state = state_call1;
end else if (opcode_out == E100_CPFA) begin
next_state = state_cpfa1;
end else if (opcode_out == E100_CPTA) begin
next_state = state_cpta1;
end else if (opcode_out == E100_RET) begin
next_state = state_ret1;
end
end
// execute halt instruction
state_halt: begin
next_state = state_halt;
end
// execute add instruction
state_add1: begin
// transfer arg2 to address
arg2_drive = 1'b1;
address_write = 1'b1;
next_state = state_add2;
end
state_add2: begin
// transfer mem[arg2] to op1
memory_drive = 1'b1;
op1_write = 1'b1;
next_state = state_add3;
end
state_add3: begin
// transfer arg3 to address
arg3_drive = 1'b1;
address_write = 1'b1;
next_state = state_add4;
end
state_add4: begin
// transfer mem[arg3] to op2
memory_drive = 1'b1;
op2_write = 1'b1;
next_state = state_add5;
end
state_add5: begin
// transfer arg1 to address
arg1_drive = 1'b1;
address_write = 1'b1;
next_state = state_add6;
end
state_add6: begin
// write op1 + op2 to mem[arg1]
add_drive = 1'b1;
memory_write = 1'b1;
next_state = state_fetch1;
end
// execute sub instruction
state_sub1: begin
// transfer arg2 to address
arg2_drive = 1'b1;
address_write = 1'b1;
next_state = state_sub2;
end
state_sub2: begin
// transfer mem[arg2] to op1
memory_drive = 1'b1;
op1_write = 1'b1;
next_state = state_sub3;
end
state_sub3: begin
// transfer arg3 to address
arg3_drive = 1'b1;
address_write = 1'b1;
next_state = state_sub4;
end
state_sub4: begin
// transfer mem[arg3] to op2
memory_drive = 1'b1;
op2_write = 1'b1;
next_state = state_sub5;
end
state_sub5: begin
// transfer arg1 to address
arg1_drive = 1'b1;
address_write = 1'b1;
next_state = state_sub6;
end
state_sub6: begin
// write op1 - op2 to mem[arg1]
sub_drive = 1'b1;
memory_write = 1'b1;
next_state = state_fetch1;
end
// execute mult instruction
state_mult1: begin
// transfer arg2 to address
arg2_drive = 1'b1;
address_write = 1'b1;
next_state = state_mult2;
end
state_mult2: begin
// transfer mem[arg2] to op1
memory_drive = 1'b1;
op1_write = 1'b1;
next_state = state_mult3;
end
state_mult3: begin
// transfer arg3 to address
arg3_drive = 1'b1;
address_write = 1'b1;
next_state = state_mult4;
end
state_mult4: begin
// transfer mem[arg3] to op2
memory_drive = 1'b1;
op2_write = 1'b1;
next_state = state_mult5;
end
state_mult5: begin
// transfer arg1 to address
arg1_drive = 1'b1;
address_write = 1'b1;
next_state = state_mult6;
end
// give time for mult to compute multiplication
state_mult6: begin
next_state = state_mult7;
end
state_mult7: begin
// write op1 * op2 to mem[arg1]
mult_drive = 1'b1;
memory_write = 1'b1;
next_state = state_fetch1;
end
// execute div instruction
state_div1: begin
// transfer arg2 to address
arg2_drive = 1'b1;
address_write = 1'b1;
next_state = state_div2;
end
state_div2: begin
// transfer mem[arg2] to op1
memory_drive = 1'b1;
op1_write = 1'b1;
next_state = state_div3;
end
state_div3: begin
// transfer arg3 to address
arg3_drive = 1'b1;
address_write = 1'b1;
next_state = state_div4;
end
state_div4: begin
// transfer mem[arg3] to op2
memory_drive = 1'b1;
op2_write = 1'b1;
next_state = state_div5;
end
state_div5: begin
// transfer arg1 to address
arg1_drive = 1'b1;
address_write = 1'b1;
next_state = state_div6;
end
// give time for div to compute division
state_div6: begin
next_state = state_div7;
end
state_div7: begin
next_state = state_div8;
end
state_div8: begin
next_state = state_div9;
end
state_div9: begin
next_state = state_div10;
end
state_div10: begin
next_state = state_div11;
end
state_div11: begin
next_state = state_div12;
end
state_div12: begin
next_state = state_div13;
end
state_div13: begin
next_state = state_div14;
end
state_div14: begin
next_state = state_div15;
end
state_div15: begin
next_state = state_div16;
end
state_div16: begin
next_state = state_div17;
end
state_div17: begin
next_state = state_div18;
end
state_div18: begin
// write op1 / op2 to mem[arg1]
div_drive = 1'b1;
memory_write = 1'b1;
next_state = state_fetch1;
end
// execute cp instruction
state_cp1: begin
// transfer arg2 to address
arg2_drive = 1'b1;
address_write = 1'b1;
next_state = state_cp2;
end
state_cp2: begin
// transfer mem[arg2] to arg3 (any spare register will do)
memory_drive = 1'b1;
arg3_write = 1'b1;
next_state = state_cp3;
end
state_cp3: begin
// transfer arg1 to address
arg1_drive = 1'b1;
address_write = 1'b1;
next_state = state_cp4;
end
state_cp4: begin
// write mem[arg2] to mem[arg1]
arg3_drive = 1'b1;
memory_write = 1'b1;
next_state = state_fetch1;
end
// execute and instruction
state_and1: begin
// transfer arg2 to address
arg2_drive = 1'b1;
address_write = 1'b1;
next_state = state_and2;
end
state_and2: begin
// transfer mem[arg2] to op1
memory_drive = 1'b1;
op1_write = 1'b1;
next_state = state_and3;
end
state_and3: begin
// transfer arg3 to address
arg3_drive = 1'b1;
address_write = 1'b1;
next_state = state_and4;
end
state_and4: begin
// transfer mem[arg3] to op2
memory_drive = 1'b1;
op2_write = 1'b1;
next_state = state_and5;
end
state_and5: begin
// transfer arg1 to address
arg1_drive = 1'b1;
address_write = 1'b1;
next_state = state_and6;
end
state_and6: begin
// write op1 & op2 to mem[arg1]
bit_and_drive = 1'b1;
memory_write = 1'b1;
next_state = state_fetch1;
end
// execute or instruction
state_or1: begin
// transfer arg2 to address
arg2_drive = 1'b1;
address_write = 1'b1;
next_state = state_or2;
end
state_or2: begin
// transfer mem[arg2] to op1
memory_drive = 1'b1;
op1_write = 1'b1;
next_state = state_or3;
end
state_or3: begin
// transfer arg3 to address
arg3_drive = 1'b1;
address_write = 1'b1;
next_state = state_or4;
end
state_or4: begin
// transfer mem[arg3] to op2
memory_drive = 1'b1;
op2_write = 1'b1;
next_state = state_or5;
end
state_or5: begin
// transfer arg1 to address
arg1_drive = 1'b1;
address_write = 1'b1;
next_state = state_or6;
end
state_or6: begin
// write op1 | op2 to mem[arg1]
bit_or_drive = 1'b1;
memory_write = 1'b1;
next_state = state_fetch1;
end
// execute not instruction
state_not1: begin
// transfer arg2 to address
arg2_drive = 1'b1;
address_write = 1'b1;
next_state = state_not2;
end
state_not2: begin
// transfer mem[arg2] to op1
memory_drive = 1'b1;
op1_write = 1'b1;
next_state = state_not3;
end
state_not3: begin
// transfer arg1 to address
arg1_drive = 1'b1;
address_write = 1'b1;
next_state = state_not4;
end
state_not4: begin
// write ~op1 to mem[arg1]
bit_not_drive = 1'b1;
memory_write = 1'b1;
next_state = state_fetch1;
end
// execute sl instruction
state_sl1: begin
// transfer arg2 to address
arg2_drive = 1'b1;
address_write = 1'b1;
next_state = state_sl2;
end
state_sl2: begin
// transfer mem[arg2] to op1
memory_drive = 1'b1;
op1_write = 1'b1;
next_state = state_sl3;
end
state_sl3: begin
// transfer arg3 to address
arg3_drive = 1'b1;
address_write = 1'b1;
next_state = state_sl4;
end
state_sl4: begin
// transfer mem[arg3] to op2
memory_drive = 1'b1;
op2_write = 1'b1;
next_state = state_sl5;
end
state_sl5: begin
// transfer arg1 to address
arg1_drive = 1'b1;
address_write = 1'b1;
next_state = state_sl6;
end
state_sl6: begin
// write op1 << op2 to mem[arg1]
sl_drive = 1'b1;
memory_write = 1'b1;
next_state = state_fetch1;
end
// execute sr instruction
state_sr1: begin
// transfer arg2 to address
arg2_drive = 1'b1;
address_write = 1'b1;
next_state = state_sr2;
end
state_sr2: begin
// transfer mem[arg2] to op1
memory_drive = 1'b1;
op1_write = 1'b1;
next_state = state_sr3;
end
state_sr3: begin
// transfer arg3 to address
arg3_drive = 1'b1;
address_write = 1'b1;
next_state = state_sr4;
end
state_sr4: begin
// transfer mem[arg3] to op2
memory_drive = 1'b1;
op2_write = 1'b1;
next_state = state_sr5;
end
state_sr5: begin
// transfer arg1 to address
arg1_drive = 1'b1;
address_write = 1'b1;
next_state = state_sr6;
end
state_sr6: begin
// write op1 >> op2 to mem[arg1]
sr_drive = 1'b1;
memory_write = 1'b1;
next_state = state_fetch1;
end
// execute be instruction
state_be1: begin
// transfer arg2 to address
arg2_drive = 1'b1;
address_write = 1'b1;
next_state = state_be2;
end
state_be2: begin
// transfer mem[arg2] to op1
memory_drive = 1'b1;
op1_write = 1'b1;
next_state = state_be3;
end
state_be3: begin
// transfer arg3 to address
arg3_drive = 1'b1;
address_write = 1'b1;
next_state = state_be4;
end
state_be4: begin
// transfer mem[arg3] to op2
memory_drive = 1'b1;
op2_write = 1'b1;
next_state = state_be5;
end
state_be5: begin
// if (op1 == op2) take branch
if (equal_out == 1'b1) begin
next_state = state_be6;
end else begin
next_state = state_fetch1;
end
end
state_be6: begin
// transfer arg1 to pc
arg1_drive = 1'b1;
pc_write = 1'b1;
next_state = state_fetch1;
end
// execute bne instruction
state_bne1: begin
// transfer arg2 to address
arg2_drive = 1'b1;
address_write = 1'b1;
next_state = state_bne2;
end
state_bne2: begin
// transfer mem[arg2] to op1
memory_drive = 1'b1;
op1_write = 1'b1;
next_state = state_bne3;
end
state_bne3: begin
// transfer arg3 to address
arg3_drive = 1'b1;
address_write = 1'b1;
next_state = state_bne4;
end
state_bne4: begin
// transfer mem[arg3] to op2
memory_drive = 1'b1;
op2_write = 1'b1;
next_state = state_bne5;
end
state_bne5: begin
// if (op1 != op2) take branch
if (equal_out == 1'b0) begin
next_state = state_bne6;
end else begin
next_state = state_fetch1;
end
end
state_bne6: begin
// transfer arg1 to pc
arg1_drive = 1'b1;
pc_write = 1'b1;
next_state = state_fetch1;
end
// execute blt instruction
state_blt1: begin
// transfer arg2 to address
arg2_drive = 1'b1;
address_write = 1'b1;
next_state = state_blt2;
end
state_blt2: begin
// transfer mem[arg2] to op1
memory_drive = 1'b1;
op1_write = 1'b1;
next_state = state_blt3;
end
state_blt3: begin
// transfer arg3 to address
arg3_drive = 1'b1;
address_write = 1'b1;
next_state = state_blt4;
end
state_blt4: begin
// transfer mem[arg3] to op2
memory_drive = 1'b1;
op2_write = 1'b1;
next_state = state_blt5;
end
state_blt5: begin
// if (op1 < op2) take branch
if (lt_out == 1'b1) begin
next_state = state_blt6;
end else begin
next_state = state_fetch1;
end
end
state_blt6: begin
// transfer arg1 to pc
arg1_drive = 1'b1;
pc_write = 1'b1;
next_state = state_fetch1;
end
//call
state_call1: begin
//Transfer mem[arg2] to address
arg2_drive = 1'b1;
address_write = 1'b1;
next_state = state_call2;
end
state_call2: begin
//Transfer PC to mem[arg2]
pc_drive = 1'b1;
memory_write = 1'b1;
next_state = state_call3;
end
state_call3: begin
//Transfer arg1 to PC
arg1_drive = 1'b1;
pc_write = 1'b1;
next_state = state_fetch1;
end
//cpfa
state_cpfa1: begin
//transfer arg2 to opcode1
arg2_drive = 1'b1;
op1_write = 1'b1;
next_state = state_cpfa2;
end
state_cpfa2: begin
//transfer arg3 to memory address register
arg3_drive = 1'b1;
address_write = 1'b1;
next_state = state_cpfa3;
end
state_cpfa3: begin
//transfer whats in memory of arg3 to opcode2
memory_drive = 1'b1;
op2_write = 1'b1;
next_state = state_cpfa4;
end
state_cpfa4: begin
//put the sum of opcodes into mar
add_drive = 1'b1;
address_write = 1'b1;
next_state = state_cpfa5;
end
state_cpfa5: begin
//takes whats in memory and puts it in arg2
memory_drive = 1'b1;
arg2_write = 1'b1;
next_state = state_cpfa6;
end
state_cpfa6: begin
//transfer arg1 to memory address register
arg1_drive = 1'b1;
address_write = 1'b1;