/
EasyRiders_Opcodes.X68
1380 lines (973 loc) · 62.1 KB
/
EasyRiders_Opcodes.X68
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
*------------------------------------------------------------------------------
* Title : 68K Disassember Final Project
* Written by : Thomas Dye and Ross Holzworth
* Date : 3/1/16
* Description: CSS 422 Final Project - University of Washington | Bothell
* Instructor : Dr. Yang Peng
*------------------------------------------------------------------------------
* Disassembler instruction opcode decoder
*------------------------------------------------------------------------------
* Add -------------------------------------------------------------------------
* Register list:
* A1: Trap #15 Input and Output (subject to frequent overwrites)
* A2: Current test opcode in use and sequence locator (read only)
* D0: Trap #15 task switch (subject to frequent overwrites)
* D7: Workspace for opcode evaluation
*---------------Opcode--Operands------------Comments---------------------------
OP_ADD LEA DISP_ADD,A1 ;Store the console message for output.
MOVE.B #14,D0 ;Will display from A1 without CR,LF.
TRAP #15 ;Display to console.
JSR SR_Eval7to6 ;Reads A2, Returns D7
* Print size
MOVE.B #5,TAB_LENGTH ;Print spaces between opcode name and EA
JSR SR_PrntSize2bit ;Reads D7, Returns void
BTST #8,(A2)
BEQ opAddDnMode ;Bit 8 = 0
BRA opAddEAMode ;Bit 8 = 1
* ADD <ea> + Dn --> Dn
opAddDnMode JSR SR_Eval5to3 ;Reads A2, Returns D7
MOVE.W D7,SRC_MODE ;Copy bits to decode src mode
JSR SR_Eval2to0 ;Reads A2, Returns D7
MOVE.W D7,SRC_REGISTER ;Copy bits to decode src register
MOVE.W #0,DEST_MODE ;Force Dn dest mode
JSR SR_Eval11to9 ;Reads A2, Returns D7
MOVE.W D7,DEST_REGISTER ;Copy bits to decode dest register
BRA opAddPrintEA
* ADD Dn + <ea> --> <ea>
opAddEAMode MOVE.W #0,SRC_MODE ;Force Dn src mode
JSR SR_Eval11to9 ;Reads A2, Returns D7
MOVE.W D7,SRC_REGISTER ;Copy bits to decode src register
JSR SR_Eval5to3 ;Reads A2, Returns D7
MOVE.W D7,DEST_MODE ;Copy bits to decode dest mode
JSR SR_Eval2to0 ;Reads A2, Returns D7
MOVE.W D7,DEST_REGISTER ;Copy bits to decode dest register
* Print source and destination EA
opAddPrintEA JSR SR_PrintEA ;Reads SRC/DEST MODE/REGISTER storage, Returns void
RTS
* Add Address -----------------------------------------------------------------
* Register list:
* A1: Trap #15 Input and Output (subject to frequent overwrites)
* D0: Trap #15 task switch (subject to frequent overwrites)
* D7: Workspace for opcode evaluation
*---------------Opcode--Operands------------Comments---------------------------
OP_ADDA LEA DISP_ADDA,A1 ;Store the console message for output.
MOVE.B #14,D0 ;Will display from A1 without CR,LF.
TRAP #15 ;Display to console.
JSR SR_Eval8to6 ;Reads A2, Returns D7
* Print size
MOVE.B #4,TAB_LENGTH ;Print spaces between opcode name and EA
JSR SR_PrntSize3bit ;Reads D7, Returns void
JSR SR_Eval5to3 ;Reads A2, Returns D7
MOVE.W D7,SRC_MODE ;Copy bits to decode src mode
JSR SR_Eval2to0 ;Reads A2, Returns D7
MOVE.W D7,SRC_REGISTER ;Copy bits to decode src register
MOVE.W #1,DEST_MODE ;Force An dest mode
JSR SR_Eval11to9 ;Reads A2, Returns D7
MOVE.W D7,DEST_REGISTER ;Copy bits to decode dest register
* Print source and destination EA
JSR SR_PrintEA ;Reads SRC/DEST MODE/REGISTER storage, Returns void
RTS
* Add Immediate ---------------------------------------------------------------
* Register list:
* A1: Trap #15 Input and Output (subject to frequent overwrites)
* D0: Trap #15 task switch (subject to frequent overwrites)
* D7: Workspace for opcode evaluation
*---------------Opcode--Operands------------Comments---------------------------
OP_ADDI LEA DISP_ADDI,A1 ;Store the console message for output.
MOVE.B #14,D0 ;Will display from A1 without CR,LF.
TRAP #15 ;Display to console.
JSR SR_Eval7to6 ;Reads A2, Returns D7
* Print size
MOVE.B #4,TAB_LENGTH ;Print spaces between opcode name and EA
JSR SR_PrntSize2bit ;Reads D7, Returns void
MOVE.W #7,SRC_MODE ;Force Absolute Short/Long/Immediate Data
MOVE.W #4,SRC_REGISTER ;Force Immediate Data selection
JSR SR_Eval5to3 ;Reads A2, Returns D7
MOVE.W D7,DEST_MODE ;Copy bits to decode dest mode
JSR SR_Eval2to0 ;Reads A2, Returns D7
MOVE.W D7,DEST_REGISTER ;Copy bits to decode dest register
* Print source and destination EA
JSR SR_PrintEA ;Reads SRC/DEST MODE/REGISTER storage, Returns void
RTS
* Add Quick -------------------------------------------------------------------
* Optional opcode that is not required by this assignment
*---------------Opcode--Operands------------Comments---------------------------
OP_ADDQ LEA DISP_ADDQ,A1 ;Store the console message for output.
MOVE.B #14,D0 ;Will display from A1 without CR,LF.
TRAP #15 ;Display to console.
* Print size
JSR SR_Eval7to6 ;Reads A2, Returns D7
MOVE.B #4,TAB_LENGTH ;Print spaces between opcode name and EA
JSR SR_PrntSize2bit ;Reads D7, Returns void
opAqCount LEA DISP_OCTOTHORPE,A1 ;Store the console message for output.
MOVE.B #14,D0 ;Will display from A1 without CR,LF.
TRAP #15 ;Display to console.
JSR SR_Eval11to9 ;Reads A2, Returns D7
CLR.L D1 ;Ensure output register is clear
MOVE.W D7,D1 ;Copy bits to D1 for console output.
CMP.B #0,D1
BEQ opAqIfZero ;#0 - value of zero represents a count of eight
opAqDispCnt MOVE.B #3,D0 ;Will display signed number from D1
TRAP #15 ;Display to console.
LEA DISP_COMMA,A1 ;Store the console message for output.
MOVE.B #14,D0 ;Will display from A1 without CR,LF.
TRAP #15 ;Display to console.
JSR SR_Eval5to3 ;Reads A2, Returns D7
MOVE.W D7,D2 ;Copy bits to decode dest mode
JSR SR_Eval2to0 ;Reads A2, Returns D7
MOVE.W D7,D3 ;Copy bits to decode dest register
JSR EA_Decode_EA ;Reads D2 and D3, Returns void
BRA opAqDone
* Count is 8 if value is 0
opAqIfZero MOVE.W #8,D1 ;#0 - value of zero represents a count of eight
BRA OpAqDispCnt
* Print memory address
opAqDone JSR SR_PrintCRLF ;Returns console output.
RTS
* AND Logical -----------------------------------------------------------------
* Register list:
* A1: Trap #15 Input and Output (subject to frequent overwrites)
* A2: Current test opcode in use and sequence locator (read only)
* D0: Trap #15 task switch (subject to frequent overwrites)
* D7: Workspace for opcode evaluation
*---------------Opcode--Operands------------Comments---------------------------
OP_AND LEA DISP_AND,A1 ;Store the console message for output.
MOVE.B #14,D0 ;Will display from A1 without CR,LF.
TRAP #15 ;Display to console.
JSR SR_Eval7to6 ;Reads A2, Returns D7
* Print size
MOVE.B #5,TAB_LENGTH ;Print spaces between opcode name and EA
JSR SR_PrntSize2bit ;Reads D7, Returns void
BTST #8,(A2)
BEQ opAndDnMode ;Bit 8 = 0
BRA opAndEAMode ;Bit 8 = 1
* AND <ea> + Dn --> Dn
opAndDnMode JSR SR_Eval5to3 ;Reads A2, Returns D7
MOVE.W D7,SRC_MODE ;Copy bits to decode src mode
JSR SR_Eval2to0 ;Reads A2, Returns D7
MOVE.W D7,SRC_REGISTER ;Copy bits to decode src register
MOVE.W #0,DEST_MODE ;Force Dn dest mode
JSR SR_Eval11to9 ;Reads A2, Returns D7
MOVE.W D7,DEST_REGISTER ;Copy bits to decode dest register
BRA opAndPrintEA
* AND Dn + <ea> --> <ea>
opAndEAMode MOVE.W #0,SRC_MODE ;Force Dn src mode
JSR SR_Eval11to9 ;Reads A2, Returns D7
MOVE.W D7,SRC_REGISTER ;Copy bits to decode src register
JSR SR_Eval5to3 ;Reads A2, Returns D7
MOVE.W D7,DEST_MODE ;Copy bits to decode dest mode
JSR SR_Eval2to0 ;Reads A2, Returns D7
MOVE.W D7,DEST_REGISTER ;Copy bits to decode dest register
* Print source and destination EA
opAndPrintEA JSR SR_PrintEA ;Reads SRC/DEST MODE/REGISTER storage, Returns void
RTS
* AND Immediate ---------------------------------------------------------------
* Optional opcode that is not required by this assignment
* Register list:
* A1: Trap #15 Input and Output (subject to frequent overwrites)
* D0: Trap #15 task switch (subject to frequent overwrites)
* D7: Workspace for opcode evaluation
*---------------Opcode--Operands------------Comments---------------------------
OP_ANDI LEA DISP_ANDI,A1 ;Store the console message for output.
MOVE.B #14,D0 ;Will display from A1 without CR,LF.
TRAP #15 ;Display to console.
JSR SR_Eval7to6 ;Reads A2, Returns D7
* Print size
MOVE.B #4,TAB_LENGTH ;Print spaces between opcode name and EA
JSR SR_PrntSize2bit ;Reads D7, Returns void
MOVE.W #7,SRC_MODE ;Force Absolute Short/Long/Immediate Data
MOVE.W #4,SRC_REGISTER ;Force Immediate Data selection
JSR SR_Eval5to3 ;Reads A2, Returns D7
MOVE.W D7,DEST_MODE ;Copy bits to decode dest mode
JSR SR_Eval2to0 ;Reads A2, Returns D7
MOVE.W D7,DEST_REGISTER ;Copy bits to decode dest register
* Print source and destination EA
JSR SR_PrintEA ;Reads SRC/DEST MODE/REGISTER storage, Returns void
RTS
* Arithmetic Shift Left -------------------------------------------------------
* Optional opcode that is not required by this assignment
*---------------Opcode--Operands------------Comments---------------------------
OP_ASL LEA DISP_ASL,A1 ;Store the console message for output.
MOVE.B #14,D0 ;Will display from A1 without CR,LF.
TRAP #15 ;Display to console.
BRA OP_ShiftRot ;Grouping for ASL/ASR/LSL/LSR/ROL/ROR
* Arithmetic Shift Right ------------------------------------------------------
*---------------Opcode--Operands------------Comments---------------------------
OP_ASR LEA DISP_ASR,A1 ;Store the console message for output.
MOVE.B #14,D0 ;Will display from A1 without CR,LF.
TRAP #15 ;Display to console.
BRA OP_ShiftRot ;Grouping for ASL/ASR/LSL/LSR/ROL/ROR
* Branch Conditionally - Carry Clear ------------------------------------------
*---------------Opcode--Operands------------Comments---------------------------
OP_BCC LEA DISP_BCC,A1 ;Store the console message for output.
MOVE.B #14,D0 ;Will display from A1 without CR,LF.
TRAP #15 ;Display to console.
BRA OP_BccGroup ;Grouping for BCC/BGT/BLE
* Grouping for BCC/BGT/BLE ----------------------------------------------------
*---------------Opcode--Operands------------Comments---------------------------
OP_BccGroup MOVE.W (A2),D7 ;Reload full opcode for evaluation
CMP.B #$00,D7
BEQ bg16bit ;Evaluate as 16-bit Displacement
CMP.B #$FF,D7
BEQ bg32bit ;Evaluate as 32-bit Displacement
* Evaluate as 8-bit Displacement
LEA DISP_SIZE_B,A1 ;Store the console message for output.
MOVE.B #14,D0 ;Will display from A1 without CR,LF.
TRAP #15 ;Display to console.
MOVE.B #5,TAB_LENGTH ;Print spaces between opcode name and EA
JSR SR_PrintTab ;Reads TAB_LENGTH, Returns console output.
MOVEA.L A2,A3 ;Copy the current opcode location
ADDA.W #2,A3 ;Advance to end of opcode to calculate displacement
JSR SR_Eval7to0 ;Reads A2, Returns D7
CMP.B $80,D7 ;Check if the number is a negative 2's complement byte
BLT bgSub8bit ;If so, handle it appropriately.
ADDA.W D7,A3 ;Apply displacement to address pointer to get branch location
bgReturn MOVE.L A3,D7 ;Copy the branch location to D7 for SR_PrintHex
MOVE.L #8,D6 ;Number of characters to display.
JSR SR_PrintHex ;Reads D6 and D7, Returns console output.
bgFinish JSR SR_PrintCRLF
RTS
bgSub8bit MULS #-1,D7 ;Find the absolute value of the negative number
CLR.L D5
MOVE.B D7,D5 ;Isolate the last byte as the displacement
SUBA.W D5,A3 ;Apply displacement to address pointer to get branch location
BRA bgReturn
bg16bit MOVE.B #7,TAB_LENGTH ;Print spaces between opcode name and EA
JSR SR_PrintTab ;Reads TAB_LENGTH, Returns console output.
MOVEA.L A2,A3 ;Copy the current instruction pointer location
ADDA.W #2,A3 ;The next word contains the absolute data.
MOVE.W (A3),D7 ;Copy the absolute data to calculate displacement
ADDA.W D7,A3 ;Apply displacement to address pointer to get branch location
MOVE.L A3,D7 ;Copy the branch location to D7 for SR_PrintHex
MOVE.L #8,D6 ;Number of characters to display
JSR SR_PrintHex ;Reads D6 and D7, Returns console output.
ADDA.W #2,A2 ;Advance the instruction pointer.
BRA bgFinish
bg32bit MOVE.B #7,TAB_LENGTH ;Print spaces between opcode name and EA
JSR SR_PrintTab ;Reads TAB_LENGTH, Returns console output.
MOVEA.L A2,A3 ;Copy the current instruction pointer location
ADDA.W #2,A3 ;The next word contains the absolute data.
MOVE.W (A3),D7 ;Copy the absolute data to calculate displacement
ADDA.W D7,A3 ;Apply displacement to address pointer to get branch location
MOVE.L A3,D7 ;Copy the branch location to D7 for SR_PrintHex
MOVE.L #8,D6 ;Number of characters to display
JSR SR_PrintHex ;Reads D6 and D7, Returns console output.
ADDA.W #4,A2 ;Advance the instruction pointer.
BRA bgFinish
* Branch Conditionally - Greater Than -----------------------------------------
*---------------Opcode--Operands------------Comments---------------------------
OP_BGT LEA DISP_BGT,A1 ;Store the console message for output.
MOVE.B #14,D0 ;Will display from A1 without CR,LF.
TRAP #15 ;Display to console.
BRA OP_BccGroup ;Grouping for BCC/BGT/BLE
* Branch Conditionally - Less or Equal ----------------------------------------
*---------------Opcode--Operands------------Comments---------------------------
OP_BLE LEA DISP_BLE,A1 ;Store the console message for output.
MOVE.B #14,D0 ;Will display from A1 without CR,LF.
TRAP #15 ;Display to console.
BRA OP_BccGroup ;Grouping for BCC/BGT/BLE
* Clear an Operand ------------------------------------------------------------
*---------------Opcode--Operands------------Comments---------------------------
OP_CLR LEA DISP_CLR,A1 ;Store the console message for output.
MOVE.B #14,D0 ;Will display from A1 without CR,LF.
TRAP #15 ;Display to console.
JSR SR_Eval7to6 ;Reads A2, Returns D7
MOVE.B D7,D4 ;Store size for EA decoding
* Print size
MOVE.B #5,TAB_LENGTH ;Print spaces between opcode name and EA
JSR SR_PrntSize2bit ;Reads D7, Returns void
JSR SR_Eval5to3 ;Returns op mode in D7
MOVE.B D7,D2
JSR SR_Eval2to0 ;Returns op register in D7
MOVE.B D7,D3
JSR EA_Decode_EA ;Prints EA information
JSR SR_PrintCRLF
RTS
* Compare ---------------------------------------------------------------------
*---------------Opcode--Operands------------Comments---------------------------
OP_CMP LEA DISP_CMP,A1 ;Store the console message for output.
MOVE.B #14,D0 ;Will display from A1 without CR,LF.
TRAP #15 ;Display to console.
JSR SR_Eval7to6 ;Reads A2, Returns D7
MOVE.B D7,D4 ;Store size for EA decoding
MOVE.B #5,TAB_LENGTH ;Print spaces between opcode name and EA
JSR SR_PrntSize2bit
JSR SR_Eval5to3 ;Reads A2, Returns D7
MOVE.W D7,SRC_MODE ;Copy bits to decode src mode
JSR SR_Eval2to0 ;Reads A2, Returns D7
MOVE.W D7,SRC_REGISTER ;Copy bits to decode src register
MOVE.W #0,DEST_MODE ;Force Dn dest mode
JSR SR_Eval11to9 ;Reads A2, Returns D7
MOVE.W D7,DEST_REGISTER ;Copy bits to decode dest register
JSR SR_PrintEA ;Reads SRC/DEST MODE/REGISTER storage, Returns void
RTS
* Compare Immediate -----------------------------------------------------------
* Optional opcode that is not required by this assignment
*---------------Opcode--Operands------------Comments---------------------------
OP_CMPI LEA DISP_CMPI,A1 ;Store the console message for output.
MOVE.B #14,D0 ;Will display from A1 without CR,LF.
TRAP #15 ;Display to console.
JSR SR_Eval7to6 ;Reads A2, Returns D7
* Print size
MOVE.B #4,TAB_LENGTH ;Print spaces between opcode name and EA
JSR SR_PrntSize2bit ;Reads D7, Returns void
MOVE.W #7,SRC_MODE ;Force Absolute Short/Long/Immediate Data
MOVE.W #4,SRC_REGISTER ;Force Immediate Data selection
JSR SR_Eval5to3 ;Reads A2, Returns D7
MOVE.W D7,DEST_MODE ;Copy bits to decode dest mode
JSR SR_Eval2to0 ;Reads A2, Returns D7
MOVE.W D7,DEST_REGISTER ;Copy bits to decode dest register
* Print source and destination EA
JSR SR_PrintEA ;Reads SRC/DEST MODE/REGISTER storage, Returns void
RTS
* Signed Divide ---------------------------------------------------------------
* Optional opcode that is not required by this assignment
*---------------Opcode--Operands------------Comments---------------------------
OP_DIVS LEA DISP_DIVS,A1 ;Store the console message for output.
MOVE.B #14,D0 ;Will display from A1 without CR,LF.
TRAP #15 ;Display to console.
MOVE.B #1,OP_SIZE ;Store the size of the EA as word.
MOVE.B #6,TAB_LENGTH ;Print spaces between opcode name and EA
JSR SR_PrintTab ;Reads TAB_LENGTH, Returns console output.
JSR SR_Eval5to3 ;Reads A2, Returns D7
MOVE.W D7,SRC_MODE ;Copy bits to src dest mode
JSR SR_Eval2to0 ;Reads A2, Returns D7
MOVE.W D7,SRC_REGISTER ;Copy bits to src dest register
JSR SR_Eval11to9 ;Reads A2, Returns D7
MOVE.W #0,DEST_MODE ;Force Dn dest mode
MOVE.W D7,DEST_REGISTER ;Copy bits to decode dest register
* Print source and destination EA
JSR SR_PrintEA ;Reads SRC/DEST MODE/REGISTER storage, Returns void
RTS
* Unsigned Divide ---------------------------------------------------------------
*---------------Opcode--Operands------------Comments---------------------------
OP_DIVU LEA DISP_DIVU,A1 ;Store the console message for output.
MOVE.B #14,D0 ;Will display from A1 without CR,LF.
TRAP #15 ;Display to console.
MOVE.B #1,OP_SIZE ;Store the size of the EA as word.
MOVE.B #6,TAB_LENGTH ;Print spaces between opcode name and EA
JSR SR_PrintTab ;Reads TAB_LENGTH, Returns console output.
JSR SR_Eval5to3 ;Reads A2, Returns D7
MOVE.W D7,SRC_MODE ;Copy bits to src dest mode
JSR SR_Eval2to0 ;Reads A2, Returns D7
MOVE.W D7,SRC_REGISTER ;Copy bits to src dest register
JSR SR_Eval11to9 ;Reads A2, Returns D7
MOVE.W #0,DEST_MODE ;Force Dn dest mode
MOVE.W D7,DEST_REGISTER ;Copy bits to decode dest register
* Print source and destination EA
JSR SR_PrintEA ;Reads SRC/DEST MODE/REGISTER storage, Returns void
RTS
* Disassembler does not support provided opcode -------------------------------
* Display ADDR DATA $WXYZ where WXYZ is the unsupported opcode.
*---------------Opcode--Operands------------Comments---------------------------
OP_INVALID LEA DISP_INVALID,A1 ;Store the console message for output.
MOVE.B #14,D0 ;Will display from A1 without CR,LF.
TRAP #15 ;Display to console.
MOVE.B #6,TAB_LENGTH ;Print spaces between opcode name and EA
JSR SR_PrintTab ;Reads TAB_LENGTH, Returns console output.
LEA DISP_DOLLAR,A1 ;Store the console message for output.
MOVE.B #14,D0 ;Will display from A1 without CR,LF.
TRAP #15 ;Display to console.
MOVE.W (A2),D7 ;Reload full opcode for evaluation
MOVE.L #4,D6 ;Number of characters to display
JSR SR_PrintHex ;Reads D6 and D7, Returns console output.
JSR SR_PrintCRLF ;Returns console output.
RTS
* Jump to Subroutine ----------------------------------------------------------
*---------------Opcode--Operands------------Comments---------------------------
OP_JSR LEA DISP_JSR,A1
MOVE.B #14,D0
TRAP #15
MOVE.B #7,TAB_LENGTH ;Print spaces between opcode name and EA
JSR SR_PrintTab
JSR SR_Eval5to3
MOVE.B D7,D2
JSR SR_Eval2to0
MOVE.B D7,D3
MOVE.B #28,D4
JSR EA_Decode_EA
JSR SR_PrintCRLF
RTS
* Load Effective Address ------------------------------------------------------
*---------------Opcode--Operands------------Comments---------------------------
OP_LEA LEA DISP_LEA,A1 ;Store the console message for output.
MOVE.B #14,D0 ;Will display from A1 without CR,LF.
TRAP #15 ;Display to console.
MOVE.B #7,TAB_LENGTH ;Print spaces between opcode name and EA
JSR SR_PrintTab ;Reads TAB_LENGTH, Returns console output.
JSR SR_Eval5to3 ;Reads A2, Returns D7
MOVE.W D7,SRC_MODE ;Copy bits to src dest mode
JSR SR_Eval2to0 ;Reads A2, Returns D7
MOVE.W D7,SRC_REGISTER ;Copy bits to src dest register
JSR SR_Eval11to9 ;Reads A2, Returns D7
MOVE.W #1,DEST_MODE ;Force An dest mode
MOVE.W D7,DEST_REGISTER ;Copy bits to decode dest register
* Print source and destination EA
JSR SR_PrintEA ;Reads SRC/DEST MODE/REGISTER storage, Returns void
RTS
* Logical Shift Left ----------------------------------------------------------
*---------------Opcode--Operands------------Comments---------------------------
OP_LSL LEA DISP_LSL,A1 ;Store the console message for output.
MOVE.B #14,D0 ;Will display from A1 without CR,LF.
TRAP #15 ;Display to console.
BRA OP_ShiftRot ;Grouping for ASL/ASR/LSL/LSR/ROL/ROR
* Logical Shift Right ---------------------------------------------------------
* Optional opcode that is not required by this assignment
*---------------Opcode--Operands------------Comments---------------------------
OP_LSR LEA DISP_LSR,A1 ;Store the console message for output.
MOVE.B #14,D0 ;Will display from A1 without CR,LF.
TRAP #15 ;Display to console.
BRA OP_ShiftRot ;Grouping for ASL/ASR/LSL/LSR/ROL/ROR
* Move Data from Source to Destination - Byte ---------------------------------
*---------------Opcode--Operands------------Comments---------------------------
OP_MOVE_B LEA DISP_MOVE,A1 ;
MOVE.B #14,D0 ;
TRAP #15
LEA DISP_SIZE_B,A1
MOVE.B #14,D0
TRAP #15
MOVE.B #0,OP_SIZE *Store size for EA decode
MOVE.B #4,TAB_LENGTH ;Print spaces between opcode name and EA
JSR SR_PrintTab
BRA MOVE_Basic
* Move Data from Source to Destination - Long ---------------------------------
*---------------Opcode--Operands------------Comments---------------------------
OP_MOVE_L LEA DISP_MOVE,A1
MOVE.B #14,D0
TRAP #15
MOVE.B #4,TAB_LENGTH ;Print spaces between opcode name and EA
JSR SR_Eval8to6 ;Reads A2, Returns D7
CMP #%001,D7
BEQ mlMOVEA ;%001
mlReturn LEA DISP_SIZE_L,A1
MOVE.B #14,D0
TRAP #15
MOVE.B #2,OP_SIZE *Store size for EA decode
JSR SR_PrintTab
BRA MOVE_Basic
* Add 'A' for MOVEA opcode
mlMOVEA LEA DISP_MOVE_A,A1 ;Store the console message for output.
MOVE.B #14,D0 ;Will display from A1 without CR,LF.
TRAP #15 ;Display to console.
MOVE.B #3,TAB_LENGTH ;Print spaces between opcode name and EA
BRA mlReturn
* Move Data from Source to Destination - Word ---------------------------------
*---------------Opcode--Operands------------Comments---------------------------
OP_MOVE_W LEA DISP_MOVE,A1
MOVE.B #14,D0
TRAP #15
MOVE.B #4,TAB_LENGTH ;Print spaces between opcode name and EA
JSR SR_Eval8to6 ;Reads A2, Returns D7
CMP #%001,D7
mwReturn BEQ mwMOVEA ;%001
LEA DISP_SIZE_W,A1
MOVE.B #14,D0
TRAP #15
MOVE.B #1,OP_SIZE *Store size for EA decode
JSR SR_PrintTab
BRA MOVE_Basic
* Add 'A' for MOVEA opcode
mwMOVEA LEA DISP_MOVE_A,A1 ;Store the console message for output.
MOVE.B #14,D0 ;Will display from A1 without CR,LF.
TRAP #15 ;Display to console.
MOVE.B #3,TAB_LENGTH ;Print spaces between opcode name and EA
BRA mwReturn
*MOVE_Basic - all of the code that MOVE.B, MOVE.W, and MOVE.L share in common
*---------------Opcode--Operands------------Comments---------------------------
MOVE_Basic MOVE.W (A2),CURRENT_OP
MOVE.B #13,D4
MOVE.W CURRENT_OP,D2
MOVE.B #10,D5
LSL.W D5,D2
LSR.W D4,D2
MOVE.W CURRENT_OP,D3
MOVE.B #13,D5
LSL.W D5,D3
LSR.W D4,D3
JSR EA_Decode_EA
MOVE.B #13,D4
LEA DISP_COMMA,A1
MOVE.B #14,D0
TRAP #15
MOVE.W CURRENT_OP,D2
MOVE.B #7,D5
LSL.W D5,D2
LSR.W D4,D2
MOVE.W CURRENT_OP,D3
MOVE.B #4,D5
LSL.W D5,D3
LSR.W D4,D3
JSR EA_Decode_EA
JSR SR_PrintCRLF
CLR.L D2 ;Clean up
CLR.L D3
CLR.L D4
CLR.L D5
CLR.L D6
CLR.L D7
RTS
* Move Multiple Registers -----------------------------------------------------
*---------------Opcode--Operands------------Comments---------------------------
OP_MOVEM LEA TABLE_HEXCHAR,A4
LEA DISP_MOVEM,A1
MOVE.B #14,D0
TRAP #15
*Determine EA mode
JSR SR_Eval5to3
MOVE.B D7,DEST_MODE
*Determine EA reg
JSR SR_Eval2to0
MOVE.B D7,DEST_REGISTER
MOVEA.L A2,A3 ;Store current address in a safer register
MOVE.W (A3),D3 ;Store opword in data register for testing
MOVE.W D3,CURRENT_OP ;Store opword safely for later
*Check and print size
BTST #6,D3
BEQ OpMovemWord
OpMovemLong LEA DISP_SIZE_L,A1
MOVE.B #14,D0
TRAP #15
MOVE.B #2,OP_SIZE
BRA MovemDirCheck
OpMovemWord LEA DISP_SIZE_W,A1
MOVE.B #14,D0
TRAP #15
MOVE.B #1,OP_SIZE
MovemDirCheck BTST #10,D3
BEQ OpMovemMask
MOVE.B #5,D7
JSR SR_PrintTab
CLR.L D2
CLR.L D3
CLR.L D4
MOVE.B DEST_MODE,D2
MOVE.B DEST_REGISTER,D3
MOVE.B OP_SIZE,D4
ADDA.W #2,A2 ;Trick EA decoder into skipping over register mask
JSR EA_Decode_EA
SUBA.W #2,A2 ;Restore A2
MOVEA.L A2,A3 ;bugfix
LEA DISP_COMMA,A1
MOVE.B #14,D0
TRAP #15
BRA MovemTabSkip
OpMovemMask MOVE.B #5,D7 ;Print tab after op size
JSR SR_PrintTab
MovemTabSkip *Grab register list mask for processing
ADDA.L #2,A3
CLR.L D6
MOVE.W (A3),D6
CLR.L D7
OpMovemNewLoop
MOVE.B #15,D7 ;Prepare a counter for looping through register list
MOVE.B #17,MOVEM_FIRST ;Set MOVEM_FIRST outside of possible range
MOVE.B #17,MOVEM_LAST
MOVE.B #0,MOVEM_PRINTED ;Clear printed before starting the loop
OpMovemLoop BTST D7,D6
BNE OpMovemLoopSkip
CMP.B #17,MOVEM_FIRST
BEQ OpMovemLoopEnd
JSR OpMovemPrint ;Current bit is 0. Move to print routine.
BRA OpMovemLoopEnd ;Move to next iteration of loop after printing
OpMovemLoopSkip CMP.B #7,D7
BNE MovemLoopSkip2
CMP.B #17,MOVEM_FIRST
BEQ MovemLoopSkip2
JSR OpMovemPrint
MovemLoopSkip2 MOVE.B D7,MOVEM_LAST ;Current bit is 1, save number as last of the list
CMP.B #17,MOVEM_FIRST
BNE OpMovemLoopEnd
MOVE.B D7,MOVEM_FIRST ;If first has not been set, set current bit as first
BRA OpMovemLoopEnd
OpMovemLoopEnd SUB.B #1,D7 ;Decrement loop counter
CMP.B #0,D7 ;Exit loop if counter < 0
BGE OpMovemLoop
CMP.B #17,MOVEM_FIRST ;Check if final chunk of register list has been printed
BEQ OpMovemEA
JSR OpMovemPrint
OpMovemEA MOVE.W CURRENT_OP,D3
BTST #10,D3
BNE MovemEASkip
CLR.L D2
CLR.L D3
CLR.L D4
MOVE.B DEST_REGISTER,D3
MOVE.B OP_SIZE,D4
MOVE.B DEST_MODE,D2
LEA DISP_COMMA,A1 ;Print a comma after register list
MOVE.B #14,D0
TRAP #15
ADDA.W #2,A2 ;Trick EA decoder into skipping over register mask
JSR EA_Decode_EA
SUBA.W #2,A2 ;Restore A2
MovemEASkip JSR SR_PrintCRLF
ADDA.L #2,A2 ;Skip over register list mask
RTS
OpMovemPrint MOVE.B MOVEM_PRINTED,D5
CMP.B #1,D5
BLT OpMovemStart
LEA DISP_SLASH,A1 ;Print a slash before anything else if this is not the first chunk of registers from the list
MOVE.B #14,D0
TRAP #15
OpMovemStart
MOVE.B DEST_MODE,D0
CMP.B #4,D0
BEQ OpMovemPrintPre ;Printing will be different for pre decrement mode
MOVE.B MOVEM_FIRST,D5
CMP.B #7,D5
BGT OpMovemA
JSR OpMovemPrintD
BRA OpMovemNext
OpMovemA JSR OpMovemPrintA
OpMovemNext MOVE.B MOVEM_LAST,D0
CMP.B MOVEM_FIRST,D0
BEQ OpMovemPrintEnd
LEA DISP_MINUS,A1
MOVE.B #14,D0
TRAP #15
MOVE.B MOVEM_LAST,D5
CMP.B #7,D5
BGT OpMovemA2
JSR OpMovemPrintD
BRA OpMovemPrintEnd
OpMovemA2 JSR OpMovemPrintA
OpMovemPrintEnd MOVE.B #17,MOVEM_FIRST
MOVE.B #17,MOVEM_LAST
MOVE.B #1,MOVEM_PRINTED
RTS
OpMovemPrintPre
MOVE.B MOVEM_FIRST,D5
CMP.B #7,D5
BGT OpMovemDPre
JSR MovemMirror
JSR OpMovemPrintA
BRA OpMovemNextPre
OpMovemDPre SUB.B #8,D5
JSR MovemMirror
JSR OpMovemPrintD
OpMovemNextPre MOVE.B MOVEM_LAST,D0
CMP.B MOVEM_FIRST,D0
BEQ OpMovemPrintEnd
LEA DISP_MINUS,A1
MOVE.B #14,D0
TRAP #15
MOVE.B MOVEM_LAST,D5
CMP.B #7,D5
BGT OpMovemD2Pre
JSR MovemMirror
JSR OpMovemPrintA
BRA OpMovemPrintEnd
OpMovemD2Pre SUB.B #8,D5
JSR MovemMirror
JSR OpMovemPrintD
BRA OpMovemPrintEnd
OpMovemPrintD MOVE.L #26,D0
LEA.L 0(A4,D0),A1 ;Print D
MOVE.B #14,D0
TRAP #15
BRA OpMovemPrintReg
OpMovemPrintA MOVE.L #20,D0
LEA.L 0(A4,D0),A1 ;Print A
MOVE.B #14,D0
TRAP #15
BRA OpMovemPrintReg
OpMovemPrintReg CMP.B #8,D5
BLT OpMovemSkip
SUB.B #8,D5
OpMovemSkip MOVE.L D5,D1
MOVE.B #3,D0
TRAP #15
RTS
MovemMirror CMP.B #0,D5
BNE Mirror1
MOVE.B #7,D5
RTS
Mirror1 CMP.B #1,D5
BNE Mirror2
MOVE.B #6,D5
RTS
Mirror2 CMP.B #2,D5
BNE Mirror3
MOVE.B #5,D5
RTS
Mirror3 CMP.B #3,D5
BNE Mirror4
MOVE.B #4,D5
RTS
Mirror4 CMP.B #4,D5
BNE Mirror5
MOVE.B #3,D5
RTS
Mirror5 CMP.B #5,D5
BNE Mirror6
MOVE.B #2,D5
RTS
Mirror6 CMP.B #6,D5
BNE Mirror7
MOVE.B #1,D5
RTS
Mirror7 MOVE.B #0,D5
RTS
* Move Quick ------------------------------------------------------------------
*---------------Opcode--Operands------------Comments---------------------------
OP_MOVEQ LEA DISP_MOVEQ,A1 ;Store the console message for output.
MOVE.B #14,D0 ;Will display from A1 without CR,LF.
TRAP #15 ;Display to console.
MOVE.B #5,TAB_LENGTH ;Print spaces between opcode name and EA
JSR SR_PrintTab ;Reads TAB_LENGTH, Returns console output.
* Print 8-bit immediate data
LEA DISP_OCTOTHORPE,A1 ;Store the console message for output.
MOVE.B #14,D0 ;Will display from A1 without CR,LF.
TRAP #15 ;Display to console.