forked from bhristov96/p68k
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaddressing.X68
1053 lines (834 loc) · 43 KB
/
addressing.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 : Addressing Mode Detect
* Description: Detects the addressing mode and prints it to screen
*-----------------------------------------------------------
*-----------------------------------------------------------
* //// Given a 6 bit op string it directs it to the correct printer. DOES NOT PRINT MOVEM.
* parameters:
* d7 - 6 bit binary string that holds the SOURCE op mode/register
* d6 - 6 bit binary string that holds the DESTINATION op mode/register
* d5 - set to 1 if destination ea exists, set to 0 otherwise
* d4 - instruction size: 0 for byte, 1 for word, 2 for long
* a0 - address of the opcode we are looking at
* return:
* prints the EA to screen as: [space] SOURCE, [space] DESTINATION
rl_printer reg a1-a6/d0-d7 * every reg except parameters/return
printer move.w sr, -(sp) * save CCR to stack
movem.l rl_printer, -(sp) * save current regs to stack
* ---- subroutine code:
start_printer
clr d3 *clear everything in the temp register
*print space
bsr print_space
*since the original value is untouched, whatever subroutine we call gets the original param
move.l d7, d3 *move the parameter into temp register
and.l #%111000, d3 *mask the temp register to get addressing mode
*start comparisons
is_data cmp.l #%000000, d3 *data register
bne is_addr *if not equal, try next
bsr data_reg
bra printer_x
is_addr cmp.l #%001000, d3 *address register
bne is_ind_addr *if not equal, try next
bsr addr_reg
bra printer_x
is_ind_addr cmp.l #%010000, d3 *indirect address register
bne is_incrmnt *if not equal, try next
bsr ind_addr_reg
bra printer_x
is_incrmnt cmp.l #%011000, d3 *post increment address register
bne is_decrmnt *if not equal, try next
bsr inc_addr_reg
bra printer_x
is_decrmnt cmp.l #%100000, d3 *pre decrement address register
bne is_immdte *if not equal, try next
bsr dec_addr_reg
bra printer_x
is_immdte *Use entire 6 bits for absolute and immediate since we need last 3 bits
move.l d7, d3 *reset the temp variable with original value
cmp.b #%111100, d3 *immediate
bne is_abs_w *if not equal, try next
bsr immdte
bra printer_x
is_abs_w cmp.b #%111000, d3 *absolute word
bne is_abs_l *if not equal, try next
bsr abs
bra printer_x
is_abs_l cmp.b #%111001, d3 *absolute long
bne invalid_ea
bsr abs
bra printer_x
invalid_ea
bsr font_red
lea invalid, a1 *load message for invalid
move.b #14, d0
trap #15 *print to screen
bsr font_white
bra printer_x
printer_loop *Check if we have second EA to print
clr d5 *clear d5 to prevent infinite loop
move.l d6, d7 *move the destination ea to the ea the subroutine looks at
bsr print_comma
bra start_printer *print second ea
* ---- exit
printer_x
cmpi #1, d5 *if d5 is 1 we have another ea to print
beq printer_loop
movem.l (sp)+, rl_printer *restore old registers
rtr * restore CCR, exit subroutine
*-----------------------------------------------------------
*-----------------------------------------------------------
* //// print MOVEM register list
* parameters:
* a2 - address of MOVEM instruction
* return:
* none
*
rl_pr_reglist reg a0-a6/d0-d7
print_reglist move.w sr, -(sp)
movem.l rl_pr_reglist, -(sp)
* ---- subroutine code:
move.w (a2), d7 * movem opword
addq.l #2, a2 * next word in memory
move.w (a2), d2 * movem reglist
andi.b #%111000, d7 * keep EA mode bits
cmpi.b #%100000, d7 * check if mode is -(An)
bne revw_skip * if not -(An), don't reverse reglist
* loop to reverse reglist
clr.b d6 * loop counter
revw_loop cmpi.b #16, d6
bge revw_loop_end
roxr.w #1, d2
roxl.w #1, d3
addq.b #1, d6
bra revw_loop
revw_loop_end move.w d3, d2
revw_skip ror.w #8, d2 * swap An and Dn order in reglist
move.b #6, d0 * print char in d1.b
move.b #'/', d1
clr.l d6 * loop counter
clr.b d4 * flag for printing slashes
* loop to print out register list
regl_loop cmpi.b #16, d6
bge regl_loop_end
btst.l d6, d2 * test bit number [d6] in d2
beq regl_skip2 * if bit is 0, don't print reg
tas d4 * if N = 0, don't print slash
bpl regl_skip1
trap #15
regl_skip1 bsr regl_reg * print an or dn
regl_skip2 addq.b #1, d6
bra regl_loop
regl_loop_end
* ---- exit
print_reglist_x movem.l (sp)+, rl_pr_reglist
rtr
*-----------------------------------------------------------
* //// print register for movem reglist printing: an or dn
* parameters:
* d6 - reglist loop counter, 0 to 15
* 0-7 prints 'an', 8-15 prints 'dn'
* return:
* none
*
rl_regl_r reg a0-a6/d0-d7
regl_reg move.w sr, -(sp)
movem.l rl_regl_r, -(sp)
* ---- subroutine code:
move.b #6, d0 * print char in d1.b
cmpi.b #7, d6
bgt regl_print_d
move.b #'a', d1
bra regl_r_trap1
regl_print_d move.b #'d', d1
regl_r_trap1 trap #15
move.b #3, d0 * print signed num in d1.l
* prints 0-7 for counter values 8-15 too
clr.l d1
move.b d6, d1
cmpi.b #8, d1
blt regl_r_trap2
subi.b #8, d1
regl_r_trap2 trap #15 * print the remainder in d1.l
* ---- exit
regl_reg_x movem.l (sp)+, rl_regl_r
rtr
*-----------------------------------------------------------
* //// Prints MOVEQ EA
* parameters:
* d7 - 6 bit data register mode and register number (must always be Data Register)
* a0 - address of instruction
* return:
* prints to screen the hex value
rl_moveq_printer reg a1-a6/d0-d6 * every reg except parameters/return
moveq_printer move.w sr, -(sp) * save CCR to stack
movem.l rl_moveq_printer, -(sp) * save current regs to stack
* ---- subroutine code:
lea pound_sign, a1 *load the pound sign to print
move.b #14, d0 *set trap
trap #15 *print to screen
lea dollar_sign, a1 *print hex dollar sign
move.b #14, d0
trap #15
clr d1
move.w (a0), d1 *move instruction into register
andi #%0000000011111111, d1
bsr print_hex_w *print value as hex word
bsr print_comma
bsr print_space
*print data register
bsr data_reg
* ---- exit
moveq_printer_x movem.l (sp)+, rl_moveq_printer *restore old registers
rtr * restore CCR, exit subroutine
*-----------------------------------------------------------
*-----------------------------------------------------------
* //// Prints ADDQ EA
* parameters:
* d7 - 6 bit data register mode and register number
* a0 - address of instruction
* return:
* prints to screen the decimal value of the hex value
rl_addq_printer reg a1-a6/d0-d6 * every reg except parameters/return
addq_printer move.w sr, -(sp) * save CCR to stack
movem.l rl_addq_printer, -(sp) * save current regs to stack
* ---- subroutine code:
lea pound_sign, a1 *load the pound sign to print
move.b #14, d0 *set trap
trap #15 *print to screen
clr d1
clr d6
move.w (a0), d1 *move instruction into register
andi #%0000111000000000, d1
rol #7, d1 *rotate to get value at end
*If 0 we print 8
cmpi #000, d1
bne print_addq
*print 8 as decimal
move.l #8, d1
print_addq
move.b #15, d0
move.b #10, d2 *base 10
trap #15
bsr print_comma
*print destination EA
clr d5 *prevent printing source and destination
bsr printer
* ---- exit
addq_printer_x movem.l (sp)+, rl_addq_printer *restore old registers
rtr * restore CCR, exit subroutine
*-----------------------------------------------------------
*-----------------------------------------------------------
* //// BCC Printer
* parameters:
* a0 - opcode address
* return:
* a0 - address of next opcode, skips the extension word if any
* prints the destination of the BCC
*
rl_bcc_printer reg a1-a6/d0-d7 * every reg except parameters/return
bcc_printer move.w sr, -(sp) * save CCR to stack
movem.l rl_bcc_printer, -(sp) * save current regs to stack
* ---- subroutine code:
bsr print_space
move.b #6, d0 * print char in d1.b
move.b #'$', d1
trap #15
clr.l d7 *holds opcode
clr.l d6 *holds displacement value
clr.l d1 *holds final destination address
move.l a0, d1 * get current address
addq.l #2, d1 * add 2 for PC
*to print the EA we have to check if displacement is 0.
*if true, we need to print word after as well
move.w (a0), d7
move.b d7, d6 *get displacement
cmpi.b #%00000000, d6 *check if displacement is 0
bne bcc_not_zero *if NOT 0, go to branch
*since displacement is 0 we need additonal word
addq.l #$2, a0 * step ahead to extension word
move.w (a0), d6
ext.l d6 * cast signed word to signed long
add.l d6, d1 * sum is branch destination address
bra bcc_print
bcc_not_zero ext.w d6 * signed byte to signed word
ext.l d6 * signed word to signed long
add.l d6, d1 * sum is branch destination address
bcc_print cmpi.l #$0000FFFF, d1
bhi bcc_print_l * if more than 5 address digits
bsr print_hex_w
bra bcc_printer_x
bcc_print_l bsr print_hex_l * print 8 address digits, not 4
* ---- exit
bcc_printer_x movem.l (sp)+, rl_bcc_printer * restore old registers
rtr * restore CCR, exit subroutine
*-----------------------------------------------------------
*-----------------------------------------------------------
* //// Shift/Rotate Printer
* parameters:
* a0 - opcode address
* return:
* prints the destination of the BCC
*
rl_shift_rotate_printer reg a1-a6/d0-d7 * every reg except parameters/return
shift_rotate_printer move.w sr, -(sp) * save CCR to stack
movem.l rl_shift_rotate_printer , -(sp) * save current regs to stack
* ---- subroutine code:
*if bits 3 and 4 hold 1 and 0, respectively, we are shifting immediate
clr d7 *print param
clr d5 *print param
clr d1 *temp
move.w (a0), d1
*if bits 7-6 = 11 then we are only printing 1 EA
andi.b #%11000000, d1
cmpi.b #%11000000, d1
beq one_bit_shift
*if not printing shift by 1, go to printer subroutine to handle printing
bra reg_shift
one_bit_shift *print only 1 EA since shifting by 1 bit
move.w (a0), d7
andi.b #%00111111, d7 *only get last 6 bits
bsr printer
bra shift_rotate_printer_x
reg_shift *shifting/rotating by register; not immediate
clr d1 *reset temp
move.w (a0), d1
*if bit 5 = 0 print immediate, if 1 print register
cmpi.b #%00100000, d1
beq sr_reg *print data reg, else print immediate
bsr print_space
lea pound_sign, a1 *load the pound sign to print
move.b #14, d0 *set trap
trap #15 *print to screen
*prepare printing immediate parameters
move.b #15, d0
move.b #10, d2 *base 10
*get source that is immediate
andi.w #%0000111000000000, d1
rol.w #7, d1 *rotate left to get bits at end
cmpi.b #%00000000, d1 *if 0 we are printing 8
bne sr_imm *if not 0 go to print 1-7
*print 8 as decimal
move.l #8, d1
trap #15
*go to print destination
bra sr_dest
sr_reg *get source that is register
clr d7
move.w (a0), d7
andi.w #%0000111000000000, d7
*rotateleft to get reg at end
rol.w #7, d7
bsr printer
bra sr_dest
sr_imm *print immediate data between 1 and 7
*printing parameters were handled earlier, just execute print
trap #15
sr_dest *print destination
*prepare print parameters
clr d7
bsr print_comma
move.w (a0), d7
andi.w #%0000000000000111, d7 *get destination data reg
bsr printer
* ---- exit
shift_rotate_printer_x
bsr print_nl
movem.l (sp)+, rl_shift_rotate_printer * restore old registers
rtr * restore CCR, exit subroutine
*-----------------------------------------------------------
*-----------------------------------------------------------
* //// Read data register addressing mode
* parameters:
* d7 - 6 bit binary string that holds the data mode and data register
*
rl_data_reg reg a0-a6/d0-d7 * every reg except parameters/return
data_reg move.w sr, -(sp) * save CCR to stack
movem.l rl_data_reg, -(sp) * save current regs to stack
* ---- subroutine code:
move.l d7, d1 *Save the contents of original val in a temp registry
and.b #%111000, d7 *if the first 3 bits is 000 it will save 000000
cmpi.b #%0, d7 *if 0 then we have a data register addressing mode
bne data_reg_x *if first 3 bits not 000, exit subroutine
print_d0 cmpi.b #%000000, d1 *compare to see if d0
bne print_d1 *if not d0 try d1
lea direct_data_0, a1 *load the message for d0
move.b #14, d0 *set trap
trap #15 *print to screen
bra data_reg_x *exit the subroutine
print_d1 cmpi.b #%000001, d1 *compare to see if d1
bne print_d2 *if not, try next
lea direct_data_1, a1 *load the message
move.b #14, d0 *set trap
trap #15 *print to screen
bra data_reg_x *exit the subroutine
print_d2 cmpi.b #%000010, d1 *compare to see if d2
bne print_d3 *if not, try next
lea direct_data_2, a1 *load the message
move.b #14, d0 *set trap
trap #15 *print to screen
bra data_reg_x *exit the subroutine
print_d3 cmpi.b #%000011, d1 *compare to see if d3
bne print_d4 *if not, try next
lea direct_data_3, a1 *load the message
move.b #14, d0 *set trap
trap #15 *print to screen
bra data_reg_x *exit the subroutine
print_d4 cmpi.b #%000100, d1 *compare to see if d4
bne print_d5 *if not, try next
lea direct_data_4, a1 *load the message
move.b #14, d0 *set trap
trap #15 *print to screen
bra data_reg_x *exit the subroutine
print_d5 cmpi.b #%000101, d1 *compare to see if d5
bne print_d6 *if not, try next
lea direct_data_5, a1 *load the message
move.b #14, d0 *set trap
trap #15 *print to screen
bra data_reg_x *exit the subroutine
print_d6 cmpi.b #%000110, d1 *compare to see if d6
bne print_d7 *if not, try next
lea direct_data_6, a1 *load the message
move.b #14, d0 *set trap
trap #15 *print to screen
bra data_reg_x *exit the subroutine
print_d7 cmpi.b #%000111, d1 *compare to see if d7
bne data_reg_x *if not, try next
lea direct_data_7, a1 *load the message
move.b #14, d0 *set trap
trap #15 *print to screen
* ---- exit
data_reg_x movem.l (sp)+, rl_data_reg *restore old registers
rtr * restore CCR, exit subroutine
*-----------------------------------------------------------
*-----------------------------------------------------------
* //// Read address register addressing mode
* parameters:
* d7 - 6 bit binary string that holds the address mode and address register
*
rl_addr_reg reg a0-a6/d0-d7 * every reg except parameters/return
addr_reg move.w sr, -(sp) * save CCR to stack
movem.l rl_addr_reg, -(sp) * save current regs to stack
* ---- subroutine code:
move.l d7, d1 *Save the contents in a temp registry
and.b #%111000, d7 *mask opmode to expected opmode
cmpi.b #%001000, d7 *check mask result to make its expected
bne addr_reg_x *if not expected, exit subroutine
print_a0 cmpi.b #%001000, d1 *compare to see if d0
bne print_a1 *if not d0 try d1
lea direct_addr_0, a1 *load the message for d0
move.b #14, d0 *set trap
trap #15 *print to screen
bra addr_reg_x *exit the subroutine
print_a1 cmpi.b #%001001, d1 *compare to see if d1
bne print_a2 *if not, try next
lea direct_addr_1, a1 *load the message
move.b #14, d0 *set trap
trap #15 *print to screen
bra addr_reg_x *exit the subroutine
print_a2 cmpi.b #%001010, d1 *compare to see if d2
bne print_a3 *if not, try next
lea direct_addr_2, a1 *load the message
move.b #14, d0 *set trap
trap #15 *print to screen
bra addr_reg_x *exit the subroutine
print_a3 cmpi.b #%001011, d1 *compare to see if d3
bne print_a4 *if not, try next
lea direct_addr_3, a1 *load the message
move.b #14, d0 *set trap
trap #15 *print to screen
bra addr_reg_x *exit the subroutine
print_a4 cmpi.b #%001100, d1 *compare to see if d4
bne print_a5 *if not, try next
lea direct_addr_4, a1 *load the message
move.b #14, d0 *set trap
trap #15 *print to screen
bra addr_reg_x *exit the subroutine
print_a5 cmpi.b #%001101, d1 *compare to see if d5
bne print_a6 *if not, try next
lea direct_addr_5, a1 *load the message
move.b #14, d0 *set trap
trap #15 *print to screen
bra addr_reg_x *exit the subroutine
print_a6 cmpi.b #%001110, d1 *compare to see if d6
bne print_a7 *if not, try next
lea direct_addr_6, a1 *load the message
move.b #14, d0 *set trap
trap #15 *print to screen
bra addr_reg_x *exit the subroutine
print_a7 cmpi.b #%001111, d1 *compare to see if d7
bne addr_reg_x *if not, try next
lea direct_addr_7, a1 *load the message
move.b #14, d0 *set trap
trap #15 *print to screen
* ---- exit
addr_reg_x movem.l (sp)+, rl_addr_reg *restore old registers
rtr * restore CCR, exit subroutine
*-----------------------------------------------------------
*-----------------------------------------------------------
* //// Read INDIRECT address register addressing mode
* parameters:
* d7 - 6 bit binary string that holds the address mode and address register
*
rl_ind_addr_reg reg a0-a6/d0-d7 * every reg except parameters/return
ind_addr_reg move.w sr, -(sp) * save CCR to stack
movem.l rl_ind_addr_reg, -(sp) * save current regs to stack
* ---- subroutine code:
move.l d7, d1 *Save the contents of d0 in a temp registry
and.b #%00111000, d7 *mask opmode to expected opmode
cmpi.b #%00010000, d7 *check mask result to make its expected
bne ind_addr_reg_x *if not expected, exit subroutine
print_ind_a0 cmpi.b #%010000, d1 *compare to see if d0
bne print_ind_a1 *if not d0 try d1
lea indirect_addr_0, a1 *load the message for d0
move.b #14, d0 *set trap
trap #15 *print to screen
bra ind_addr_reg_x *exit the subroutine
print_ind_a1 cmpi.b #%010001, d1 *compare to see if d1
bne print_ind_a2 *if not, try next
lea indirect_addr_1, a1 *load the message
move.b #14, d0 *set trap
trap #15 *print to screen
bra ind_addr_reg_x *exit the subroutine
print_ind_a2 cmpi.b #%010010, d1 *compare to see if d2
bne print_ind_a3 *if not, try next
lea indirect_addr_2, a1 *load the message
move.b #14, d0 *set trap
trap #15 *print to screen
bra ind_addr_reg_x *exit the subroutine
print_ind_a3 cmpi.b #%010011, d1 *compare to see if d3
bne print_ind_a4 *if not, try next
lea indirect_addr_3, a1 *load the message
move.b #14, d0 *set trap
trap #15 *print to screen
bra ind_addr_reg_x *exit the subroutine
print_ind_a4 cmpi.b #%010100, d1 *compare to see if d4
bne print_ind_a5 *if not, try next
lea indirect_addr_4, a1 *load the message
move.b #14, d0 *set trap
trap #15 *print to screen
bra ind_addr_reg_x *exit the subroutine
print_ind_a5 cmpi.b #%010101, d1 *compare to see if d5
bne print_ind_a6 *if not, try next
lea indirect_addr_5, a1 *load the message
move.b #14, d0 *set trap
trap #15 *print to screen
bra ind_addr_reg_x *exit the subroutine
print_ind_a6 cmpi.b #%010110, d1 *compare to see if d6
bne print_ind_a7 *if not, try next
lea indirect_addr_6, a1 *load the message
move.b #14, d0 *set trap
trap #15 *print to screen
bra ind_addr_reg_x *exit the subroutine
print_ind_a7 cmpi.b #%010111, d1 *compare to see if d7
bne ind_addr_reg_x *if not, try next
lea indirect_addr_7, a1 *load the message
move.b #14, d0 *set trap
trap #15 *print to screen
* ---- exit
ind_addr_reg_x movem.l (sp)+, rl_ind_addr_reg *restore old registers
rtr * restore CCR, exit subroutine
*-----------------------------------------------------------
*-----------------------------------------------------------
* //// Read post-increment address register addressing mode
* parameters:
* d7 - 6 bit binary string that holds the address mode and address register
*
rl_inc_addr_reg reg a0-a6/d0-d7 * every reg except parameters/return
inc_addr_reg move.w sr, -(sp) * save CCR to stack
movem.l rl_inc_addr_reg, -(sp) * save current regs to stack
* ---- subroutine code:
move.l d7, d1 *Save the contents of d0 in a temp registry
and.b #%111000, d7 *mask opmode to expected opmode
cmpi.b #%011000, d7 *check mask result to make its expected
bne inc_addr_reg_x *if not expected, exit subroutine
print_inc_a0 cmpi.b #%011000, d1 *compare to see if d0
bne print_inc_a1 *if not d0 try d1
lea incrmnt_addr_0, a1 *load the message for d0
move.b #14, d0 *set trap
trap #15 *print to screen
bra inc_addr_reg_x *exit the subroutine
print_inc_a1 cmpi.b #%011001, d1 *compare to see if d1
bne print_inc_a2 *if not, try next
lea incrmnt_addr_1, a1 *load the message
move.b #14, d0 *set trap
trap #15 *print to screen
bra inc_addr_reg_x *exit the subroutine
print_inc_a2 cmpi.b #%011010, d1 *compare to see if d2
bne print_inc_a3 *if not, try next
lea incrmnt_addr_2, a1 *load the message
move.b #14, d0 *set trap
trap #15 *print to screen
bra inc_addr_reg_x *exit the subroutine
print_inc_a3 cmpi.b #%011011, d1 *compare to see if d3
bne print_inc_a4 *if not, try next
lea incrmnt_addr_3, a1 *load the message
move.b #14, d0 *set trap
trap #15 *print to screen
bra inc_addr_reg_x *exit the subroutine
print_inc_a4 cmpi.b #%011100, d1 *compare to see if d4
bne print_inc_a5 *if not, try next
lea incrmnt_addr_4, a1 *load the message
move.b #14, d0 *set trap
trap #15 *print to screen
bra ind_addr_reg_x *exit the subroutine
print_inc_a5 cmpi.b #%011101, d1 *compare to see if d5
bne print_inc_a6 *if not, try next
lea incrmnt_addr_5, a1 *load the message
move.b #14, d0 *set trap
trap #15 *print to screen
bra ind_addr_reg_x *exit the subroutine
print_inc_a6 cmpi.b #%011110, d1 *compare to see if d6
bne print_inc_a7 *if not, try next
lea incrmnt_addr_6, a1 *load the message
move.b #14, d0 *set trap
trap #15 *print to screen
bra ind_addr_reg_x *exit the subroutine
print_inc_a7 cmpi.b #%011111, d1 *compare to see if d7
bne inc_addr_reg_x *if not, try next
lea incrmnt_addr_7, a1 *load the message
move.b #14, d0 *set trap
trap #15 *print to screen
* ---- exit
inc_addr_reg_x movem.l (sp)+, rl_inc_addr_reg *restore old registers
rtr * restore CCR, exit subroutine
*-----------------------------------------------------------
*-----------------------------------------------------------
* //// Read pre-decrement address register addressing mode
* parameters:
* d7 - 6 bit binary string that holds the address mode and address register
*
rl_dec_addr_reg reg a0-a6/d0-d7 * every reg except parameters/return
dec_addr_reg move.w sr, -(sp) * save CCR to stack
movem.l rl_dec_addr_reg, -(sp) * save current regs to stack
* ---- subroutine code:
move.l d7, d1 *Save the contents of d0 in a temp registry
and.b #%111000, d7 *mask opmode to expected opmode
cmpi.b #%100000, d7 *check mask result to make its expected
bne dec_addr_reg_x *if not expected, exit subroutine
print_dec_a0 cmpi.b #%100000, d1 *compare to see if d0
bne print_dec_a1 *if not d0 try d1
lea decrmnt_addr_0, a1 *load the message for d0
move.b #14, d0 *set trap
trap #15 *print to screen
bra dec_addr_reg_x *exit the subroutine
print_dec_a1 cmpi.b #%100001, d1 *compare to see if d1
bne print_dec_a2 *if not, try next
lea decrmnt_addr_1, a1 *load the message
move.b #14, d0 *set trap
trap #15 *print to screen
bra inc_addr_reg_x *exit the subroutine
print_dec_a2 cmpi.b #%100010, d1 *compare to see if d2
bne print_dec_a3 *if not, try next
lea decrmnt_addr_2, a1 *load the message
move.b #14, d0 *set trap
trap #15 *print to screen
bra dec_addr_reg_x *exit the subroutine
print_dec_a3 cmpi.b #%100011, d1 *compare to see if d3
bne print_dec_a4 *if not, try next
lea decrmnt_addr_3, a1 *load the message
move.b #14, d0 *set trap
trap #15 *print to screen
bra dec_addr_reg_x *exit the subroutine
print_dec_a4 cmpi.b #%100100, d1 *compare to see if d4
bne print_dec_a5 *if not, try next
lea decrmnt_addr_4, a1 *load the message
move.b #14, d0 *set trap
trap #15 *print to screen
bra dec_addr_reg_x *exit the subroutine
print_dec_a5 cmpi.b #%100101, d1 *compare to see if d5
bne print_dec_a6 *if not, try next
lea decrmnt_addr_5, a1 *load the message
move.b #14, d0 *set trap
trap #15 *print to screen
bra dec_addr_reg_x *exit the subroutine
print_dec_a6 cmpi.b #%100110, d1 *compare to see if d6
bne print_dec_a7 *if not, try next
lea decrmnt_addr_6, a1 *load the message
move.b #14, d0 *set trap
trap #15 *print to screen
bra dec_addr_reg_x *exit the subroutine
print_dec_a7 cmpi.b #%100111, d1 *compare to see if d7
bne dec_addr_reg_x *if not, try next
lea decrmnt_addr_7, a1 *load the message
move.b #14, d0 *set trap
trap #15 *print to screen
* ---- exit
dec_addr_reg_x movem.l (sp)+, rl_dec_addr_reg *restore old registers
rtr * restore CCR, exit subroutine
*-----------------------------------------------------------
*-----------------------------------------------------------
* //// Prints immediate data as hex
* parameters:
* d7 - op mode and op register
* d4 - instruction size: 0 for byte, 1 for word, 2 for long
* a0 - address of additional data to print
* return:
* prints to screen the immediate data hex value
* a0 - last word address of immediate data
rl_immdte reg a1-a6/d0-d7 * every reg except parameters/return
immdte move.w sr, -(sp) * save CCR to stack
movem.l rl_immdte, -(sp) * save current regs to stack
* ---- subroutine code:
cmpi.b #%111100, d7 *check op to ensure its expected
bne immdte_x *if not expected, exit subroutine
lea pound_sign, a1 *load the pound sign to print
move.b #14, d0 *set trap
trap #15 *print to screen
lea dollar_sign, a1 *print hex dollar sign
move.b #14, d0
trap #15
*Since we print source then destination, if we are printing source A0 is the opcode
*...if we are printing destination, A0 is the source. So by adding 2 (word size)
*...we get the next additional data in memory
*Read the additional data at A0 (the opcode) + 2 (the next word)
addq.l #$2, a0
move.w (a0), d1
bsr print_hex_w *print value as hex word
* check if the instruction is long, meaning long imm data
btst.l #1, d4 * test bit 1: if %1, it's long
beq immdte_x * bit 1 is %0, not long, exit
addq.l #$2, a0 * go to next word containing imm data
move.w (a0), d1
bsr print_hex_w * print data again
* ---- exit
immdte_x movem.l (sp)+, rl_immdte *restore old registers
rtr * restore CCR, exit subroutine
*-----------------------------------------------------------
*-----------------------------------------------------------
* //// Prints absolute value of the data as ASCII
* parameters:
* d7 - op mode and op register
* a0 - address of opcode
* return:
* prints to screen the decimal value of the absolute value
rl_abs reg a1-a6/d0-d7 * every reg except parameters/return
abs move.w sr, -(sp) * save CCR to stack
movem.l rl_abs, -(sp) * save current regs to stack
* ---- subroutine code:
cmpi.b #%111000, d7 *check op to see if abs short
beq abs_short
cmpi.b #%111001, d7 *check op to see if abs long
bne abs_x *if not, exit
abs_long
lea dollar_sign, a1 *load the pound sign to print
move.b #14, d0 *set trap
trap #15 *print to screen
*Since we print source then destination, if we are printing source A0 is the opcode
*...if we are printing destination, A0 is the source. So by adding 2 (word size)
*...we get the next additional data in memory
*Read the additional data at A0 (the opcode) + 2, then move forward by 2
addq #2, a0
move.l (a0), d1
bsr print_hex_l
*Since we printed long we need to move forward 4 bytes...
*...the next time we call this function it moves forward 2 bytes, so we add 2 here.
addq #2, a0
bra abs_x
abs_short
lea dollar_sign, a1 *load the pound sign to print
move.b #14, d0 *set trap
trap #15 *print to screen
*Read the additional data at A0 (the opcode) + 2 (the next word)
addq #2, a0
move.W (a0), d1
bsr print_hex_w
* ---- exit
abs_x movem.l (sp)+, rl_abs *restore old registers
rtr * restore CCR, exit subroutine
*-----------------------------------------------------------
*-----------------------------------------------------------
* //// print comma
* parameters:
* none
* return:
* prints comma to screen
*
rl_print_comma reg d0
print_comma move.w sr, -(sp)
movem.l rl_print_comma, -(sp)
* ---- subroutine code:
*print comma
lea comma, a1 *load the message for d0
move.b #14, d0 *set trap
trap #15 *print to screen
* ---- exit
print_comma_x movem.l (sp)+, rl_print_comma
rtr
*-----------------------------------------------------------
*-----------------------------------------------------------
* //// print slash
* parameters:
* none
* return:
* prints slash to screen
*
rl_print_slash reg d0
print_slash move.w sr, -(sp)
movem.l rl_print_slash, -(sp)
* ---- subroutine code:
*print slash
lea slash, a1 *load the message for d0
move.b #14, d0 *set trap
trap #15 *print to screen
* ---- exit
print_slash_x movem.l (sp)+, rl_print_slash
rtr
*-----------------------------------------------------------
invalid dc.b '[invalid EA]', 0
*direct data registers print
direct_data_0 dc.b 'd0', 0
direct_data_1 dc.b 'd1', 0
direct_data_2 dc.b 'd2', 0
direct_data_3 dc.b 'd3', 0
direct_data_4 dc.b 'd4', 0
direct_data_5 dc.b 'd5', 0
direct_data_6 dc.b 'd6', 0
direct_data_7 dc.b 'd7', 0
*direct address registers print
direct_addr_0 dc.b 'a0', 0
direct_addr_1 dc.b 'a1', 0
direct_addr_2 dc.b 'a2', 0
direct_addr_3 dc.b 'a3', 0
direct_addr_4 dc.b 'a4', 0
direct_addr_5 dc.b 'a5', 0
direct_addr_6 dc.b 'a6', 0
direct_addr_7 dc.b 'a7', 0
*INDIRECT address registers print
indirect_addr_0 dc.b '(a0)', 0
indirect_addr_1 dc.b '(a1)', 0
indirect_addr_2 dc.b '(a2)', 0
indirect_addr_3 dc.b '(a3)', 0
indirect_addr_4 dc.b '(a4)', 0
indirect_addr_5 dc.b '(a5)', 0
indirect_addr_6 dc.b '(a6)', 0
indirect_addr_7 dc.b '(a7)', 0
*INCREMENT address registers print
incrmnt_addr_0 dc.b '(a0)+', 0
incrmnt_addr_1 dc.b '(a1)+', 0
incrmnt_addr_2 dc.b '(a2)+', 0
incrmnt_addr_3 dc.b '(a3)+', 0
incrmnt_addr_4 dc.b '(a4)+', 0
incrmnt_addr_5 dc.b '(a5)+', 0
incrmnt_addr_6 dc.b '(a6)+', 0
incrmnt_addr_7 dc.b '(a7)+', 0
*DECREMENT address registers print
decrmnt_addr_0 dc.b '-(a0)', 0
decrmnt_addr_1 dc.b '-(a1)', 0
decrmnt_addr_2 dc.b '-(a2)', 0
decrmnt_addr_3 dc.b '-(a3)', 0
decrmnt_addr_4 dc.b '-(a4)', 0
decrmnt_addr_5 dc.b '-(a5)', 0
decrmnt_addr_6 dc.b '-(a6)', 0
decrmnt_addr_7 dc.b '-(a7)', 0
*Immediate values prints
pound_sign dc.b '#', 0
dollar_sign dc.b '$', 0