-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdisassembler_sub.X68
815 lines (620 loc) · 19.9 KB
/
disassembler_sub.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
*-----------------------------------------------------------
* Title :
* Written by :
* Date :
* Description:
*-----------------------------------------------------------
addr1 EQU $7000
bit1 EQU $FF0
bit2 EQU $FF1
bit3 EQU $FF2
bit4 EQU $FF3
ORG $1000
START: ; first instruction of program
* this stores some test EA into memory
LEA addr1,A1
*MOVE.W #$9361,(A1)+ *917C
MOVE.W #$917C,(A1)+ *917C
MOVE.L #$5555A7FF,(A1)+
MOVE.W #$9078,(A1)+
MOVE.W #$5555,(A1)+
MOVE.L #$0,A1 This clears the memory at A1, not sure why i didn't it but its probably important
MOVEA.L #addr1,A6 Moves starting addr into A6 register
******************************************** displays address location***********************************************
MOVE.L A6,D7 Loads memory to data register
MOVE.B #2,D6 D7 is a counter, used to know loop back once
MOVE.L D7,D2 Copies opcode saved in D2 to D7
SWAP D2
BRA DISPADDR2 Skips the second part to do later
DISPADDR1
MOVE.W D7,D2
DISPADDR2
MOVE.W D2,D1 Copies data at D2 to D3
MOVE.W D2,D3
MOVE.W D2,D4
MOVE.W D2,D5
LSR.W #8,D1
LSR.W #4,D1
LSL.W #4,D3
LSR.W #8,D3
LSR.W #4,D3
LSL.W #8,D4
LSR.W #8,D4
LSR.W #4,D4
LSL.W #8,D5
LSL.W #4,D5
LSR.W #8,D5
LSR.W #4,D5
LEA DISPADDR3,A3 Place address of TENS into A3 to continue from there after conversion
CMP.B #9,D1 Compares digit to 9
BGT CONV Print out letter representation if greater than 9
MOVE.B #3,D0 Displays digit if it is less than A
TRAP #15
DISPADDR3
MOVE.B D3,D1 Displays digit in 1's place second
* converts digits 10+ into letters
LEA DISPADDR4,A3 Places address of NEXT into A3 to continue from there after conversion
CMP.B #9,D1 Compares digit to 9
BGT CONV Print out letter representation if greater than 9
MOVE.B #3,D0 Displays digit if it is less than A
TRAP #15
DISPADDR4
MOVE.B D4,D1 Displays digit in 1's place second
* converts digits 10+ into letters
LEA DISPADDR5,A3 Places address of NEXT into A3 to continue from there after conversion
CMP.B #9,D1 Compares digit to 9
BGT CONV Print out letter representation if greater than 9
MOVE.B #3,D0 Displays digit if it is less than A
TRAP #15
DISPADDR5
MOVE.B D5,D1 Displays digit in 1's place second
* converts digits 10+ into letters
LEA DISPADDR6,A3 Places address of NEXT into A3 to continue from there after conversion
CMP.B #9,D1 Compares digit to 9
BGT CONV Print out letter representation if greater than 9
MOVE.B #3,D0 Displays digit if it is less than A
TRAP #15
DISPADDR6
* Display counter -- creates new line every 8 bytes
* D6 is used as counter
SUB.B #1,D6
CMP.B #0,D6
BNE DISPADDR1
LEA TAB,A1
MOVE.B #14,D0
TRAP #15
*********************************************************************************************************************
MOVE.B (A6)+,D2 Moves data at current address to D1, then increments
MOVE.B D2,D7
LSL.W #8,D7
MOVE.B D2,D3 Copies data at D2 to D3
* this gets digit in 10's place
LSR.B #4,D3 Shifts right to get rid of 1's place
* this gets digit in 1's place
LSL.B #4,D2 Shifts left to get rid of 10's place
LSR.B #4,D2 Shifts back right into 1's place
* D3 holds digit in 10's place
* D2 holds digit in 1's place
* Moves second nibble to D5 to be used later
MOVE.B D2,D5
BRA CODE
* This is where the table goes to detirmine which op-code to use
CODE CMP.B #$9,D3 Goes to sub section
BEQ SUB
* Grabs next two nibbles
SUB MOVE.B (A6)+,D2
ADD.B D2,D7
MOVE.B D2,D3 Copies data at D2 to D3
* this gets digit in 10's place
LSR.B #4,D3 Shifts right to get rid of 1's place
* this gets digit in 1's place
LSL.B #4,D2 Shifts left to get rid of 10's place
LSR.B #4,D2 Shifts back right into 1's place
* D3 holds digit in 10's place
* D2 holds digit in 1's place
* Converts nibble into 3-bit parts
LSR.B #1,D3
BCC SUB2
ADD.B #$2,D4
SUB2 LSR.B #1,D3
BCC SUB3
ADD.B #$4,D4
SUB3 MOVE.B D5,D1
LSR.B #1,D1
BCC SUB4
ADD.B #$4,D3
SUB4 CMP.B #$7,D2
BLT SUB1
ADD.B #$1,D4
SUB.B #$8,D2
* Stores them into addr
SUB1 MOVE.B D1,bit1
MOVE.B D3,bit2
MOVE.B D4,bit3
MOVE.B D2,bit4
* do this later
CLR D1
MOVE.L #0,D2
MOVE.L #0,D3
MOVE.L #0,D4
MOVE.L #0,D5
MOVE.L #0,D6
*** sub display ***
* This will display SUBA instead check this later
CMP.B #$3,bit2
BEQ SUBA
CMP.B #$7,bit2
BEQ SUBA
* This will find the size and stuff
CMP.B #$0,bit2
BEQ SUBSIZE1
CMP.B #$1,bit2
BEQ SUBSIZE2
CMP.B #$2,bit2
BEQ SUBSIZE3
CMP.B #$4,bit2
BEQ SUBSIZE4
CMP.B #$5,bit2
BEQ SUBSIZE5
CMP.B #$6,bit2
BEQ SUBSIZE6
* Displays size, then does operation order
* 000 byte EA,DN
SUBSIZE1
LEA MBYTE,A1
MOVE.B #14,D0
TRAP #15
LEA TAB,A1
MOVE.B #14,D0
TRAP #15
LEA SUBSIZE11,A2
BRA SUBEA
SUBSIZE11
LEA SUBSIZE12,A2
LEA COMMA,A1
MOVE.B #14,D0
TRAP #15
BRA SUBDN
SUBSIZE12
BRA EXIT
* 001 word EA,DN
SUBSIZE2
LEA MWORD,A1
MOVE.B #14,D0
TRAP #15
LEA TAB,A1
MOVE.B #14,D0
TRAP #15
LEA SUBSIZE21,A2
BRA SUBEA
SUBSIZE21
LEA SUBSIZE22,A2
LEA COMMA,A1
MOVE.B #14,D0
TRAP #15
BRA SUBDN
SUBSIZE22
BRA EXIT
* 010 long EA,DN
SUBSIZE3
LEA MLONG,A1
MOVE.B #14,D0
TRAP #15
LEA TAB,A1
MOVE.B #14,D0
TRAP #15
LEA SUBSIZE31,A2
BRA SUBEA
SUBSIZE31
LEA SUBSIZE32,A2
LEA COMMA,A1
MOVE.B #14,D0
TRAP #15
BRA SUBDN
SUBSIZE32
BRA EXIT
* 100 byte DN,EA
SUBSIZE4
LEA MBYTE,A1
MOVE.B #14,D0
TRAP #15
LEA TAB,A1
MOVE.B #14,D0
TRAP #15
BSR SUBERRORTEST1
LEA SUBSIZE41,A2
BRA SUBDN
SUBSIZE41
LEA SUBSIZE42,A2
LEA COMMA,A1
MOVE.B #14,D0
TRAP #15
BRA SUBEA
SUBSIZE42
BRA EXIT
* 101 word DN,EA
SUBSIZE5
BSR SUBERRORTEST1 * This does error testing
BSR SUBPRINT * Prints out 'SUB.'
LEA MWORD,A1
MOVE.B #14,D0
TRAP #15
LEA TAB,A1
MOVE.B #14,D0
TRAP #15
LEA SUBSIZE51,A2
BRA SUBDN
SUBSIZE51
LEA SUBSIZE52,A2
LEA COMMA,A1
MOVE.B #14,D0
TRAP #15
BRA SUBEA
SUBSIZE52
BRA EXIT
* 110 long DN,EA
SUBSIZE6
LEA MLONG,A1
MOVE.B #14,D0
TRAP #15
LEA TAB,A1
MOVE.B #14,D0
TRAP #15
BSR SUBERRORTEST1
LEA SUBSIZE61,A2
BRA SUBDN
SUBSIZE61
LEA SUBSIZE62,A2
LEA COMMA,A1
MOVE.B #14,D0
TRAP #15
BRA SUBEA
SUBSIZE62
BRA EXIT
SUBA
LEA MSUBA,A1 Displays 'SUBA.'
MOVE.B #14,D0
TRAP #15
* Does the rest of SUBA
CMP.B #$3,bit2
BEQ SUBSIZE7
CMP.B #$7,bit2
BEQ SUBSIZE8
SUBSIZE7
LEA MWORD,A1
MOVE.B #14,D0
TRAP #15
LEA TAB,A1
MOVE.B #14,D0
TRAP #15
LEA SUBSIZE71,A2
BRA SUBEA
SUBSIZE71
LEA SUBSIZE72,A2
LEA COMMA,A1
MOVE.B #14,D0
TRAP #15
BRA SUBAN2
SUBSIZE72
BRA EXIT
SUBSIZE8
LEA MLONG,A1
MOVE.B #14,D0
TRAP #15
LEA TAB,A1
MOVE.B #14,D0
TRAP #15
LEA SUBSIZE71,A2
BRA SUBEA
SUBSIZE81
LEA SUBSIZE72,A2
LEA COMMA,A1
MOVE.B #14,D0
TRAP #15
BRA SUBAN2
SUBSIZE82
BRA EXIT
SUBJMPA2
JMP (A2)
SUBPRINT
* Displays 'SUB.'
LEA MSUB,A1
MOVE.B #14,D0
TRAP #15
RTS
SUBERRORTEST1
* test for DN or AN register, branches to invalid op code if true
CMP.B #0,bit3
BEQ INVOP
CMP.B #1,bit3
BEQ INVOP
* check if destination is immediate data
CMP.B #7,bit3
BNE SUBERRORTEST11
CMP.B #0,bit4
BEQ SUBERRORTEST11
CMP.B #1,bit4
BEQ SUBERRORTEST11
BRA INVOP
SUBERRORTEST11
RTS
INVOP
LEA MDATA,A1
MOVE.B #14,D0
TRAP #15
LEA TAB,A1
MOVE.B #14,D0
TRAP #15
MOVE.B #2,D6 D6 is a counter, used to know loop back once
MOVE.W D7,D2 Copies opcode saved in D2 to D7
LSR.W #8,D2 Shifts D2 right 8 spaces to get the first byte of the word
BRA INVOP2 Skips the second part to do later
INVOP1
MOVE.B D7,D2
INVOP2
MOVE.B D2,D3 Copies data at D2 to D3
* this gets digit in 10's place
LSR.B #4,D3 Shifts right to get rid of 1's place
* this gets digit in 1's place
LSL.B #4,D2 Shifts left to get rid of 10's place
LSR.B #4,D2 Shifts back right into 1's place
* D3 holds digit in 10's place
* D2 holds digit in 1's place
MOVE.B D3,D1 Displays digit in 10's place first
* converts digits 10+ into letters
LEA INVOP3,A3 Place address of TENS into A3 to continue from there after conversion
CMP.B #9,D1 Compares digit to 9
BGT CONV Print out letter representation if greater than 9
MOVE.B #3,D0 Displays digit if it is less than A
TRAP #15
INVOP3
MOVE.B D2,D1 Displays digit in 1's place second
* converts digits 10+ into letters
LEA INVOP4,A3 Places address of NEXT into A3 to continue from there after conversion
CMP.B #9,D1 Compares digit to 9
BGT CONV Print out letter representation if greater than 9
MOVE.B #3,D0 Displays digit if it is less than A
TRAP #15
INVOP4
* Display counter -- creates new line every 8 bytes
* D6 is used as counter
SUB.B #1,D6
CMP.B #0,D6
BEQ EXIT
BRA INVOP1 Loops back to display next address
* Displays data register
SUBDN
LEA MDN,A1
MOVE.B #14,D0
TRAP #15
MOVE.B bit1,D1
MOVE.B #3,D0
TRAP #15
BRA SUBJMPA2
* Displays data register
* This is for Dn -> Dn cases. Source Dn uses bit4 as register instead of bit1
SUBDN2
LEA MDN,A1
MOVE.B #14,D0
TRAP #15
MOVE.B bit4,D1
MOVE.B #3,D0
TRAP #15
BRA SUBJMPA2
* Displays address register
SUBAN
LEA MAN,A1
MOVE.B #14,D0
TRAP #15
MOVE.B bit4,D1
MOVE.B #3,D0
TRAP #15
BRA SUBJMPA2
* Displays address register
* This is for SUBA, SUBA puts An into bit1
SUBAN2
LEA MAN,A1
MOVE.B #14,D0
TRAP #15
MOVE.B bit1,D1
MOVE.B #3,D0
TRAP #15
BRA SUBJMPA2
* Displays indirect address register
SUBANID
LEA OPENBRA,A1
MOVE.B #14,D0
TRAP #15
LEA MAN,A1
MOVE.B #14,D0
TRAP #15
MOVE.B bit4,D1
MOVE.B #3,D0
TRAP #15
LEA CLOSEBRA,A1
MOVE.B #14,D0
TRAP #15
BRA SUBJMPA2
* Displays indirect address register with post increment
SUBANIDPOS
LEA OPENBRA,A1
MOVE.B #14,D0
TRAP #15
LEA MAN,A1
MOVE.B #14,D0
TRAP #15
MOVE.B bit4,D1
MOVE.B #3,D0
TRAP #15
LEA CLOSEBRA,A1
MOVE.B #14,D0
TRAP #15
LEA POS,A1
MOVE.B #14,D0
TRAP #15
BRA SUBJMPA2
* Displays indirect address register with pre decrement
SUBANIDNEG
LEA NEG,A1
MOVE.B #14,D0
TRAP #15
LEA OPENBRA,A1
MOVE.B #14,D0
TRAP #15
LEA MAN,A1
MOVE.B #14,D0
TRAP #15
MOVE.B bit4,D1
MOVE.B #3,D0
TRAP #15
LEA CLOSEBRA,A1
MOVE.B #14,D0
TRAP #15
BRA SUBJMPA2
* Code to display EA
SUBEA
* This finds which mode to use
CMP.B #$0,bit3
BEQ SUBDN2
CMP.B #$1,bit3 BYTE SIZED OPERATIONS ARE NOT ALLOWED FOR An
BEQ SUBAN
CMP.B #$2,bit3
BEQ SUBANID
CMP.B #$3,bit3
BEQ SUBANIDPOS
CMP.B #$4,bit3
BEQ SUBANIDNEG
CMP.B #$5,bit3
BEQ EXIT
CMP.B #$6,bit3
BEQ EXIT
CMP.B #$7,bit3
BEQ SUBEAHEX
SUBEAHEX
CMP.B #$4,bit4 Branches to immediate data section of bit4 is 4
BEQ SUBEAID
* Else it will assume it is absolute addressing mode
LEA MHEX,A1
MOVE.B #14,D0
TRAP #15
CMP.B #$0,bit4
BEQ SUBEAHEX1
CMP.B #$1,bit4
BEQ SUBEAHEX2
* write immediate data code here
LEA HASH,A1
MOVE.B #14,D0
TRAP #15
CMP.B #$1,bit2
BEQ SUBEAHEX1
CMP.B #$5,bit2
BEQ SUBEAHEX1
CMP.B #$2,bit2
BEQ SUBEAHEX2
CMP.B #$6,bit2
BEQ SUBEAHEX2
SUBEAID
BRA EXIT
SUBEAHEX1
*absolute address word
MOVE.B #2,D7
BRA SUBEAHEX3
SUBEAHEX2 *absolute address long
MOVE.B #4,D7
BRA SUBEAHEX3
SUBEAHEX3
CMP.B #0,D7 Compares current addr to ending addr
BEQ SUBJMPA2 Branches to done if they are equal
MOVE.B (A6)+,D2 Moves data at current address to D1, then increments
MOVE.B D2,D3 Copies data at D2 to D3
* this gets digit in 10's place
LSR.B #4,D3 Shifts right to get rid of 1's place
* this gets digit in 1's place
LSL.B #4,D2 Shifts left to get rid of 10's place
LSR.B #4,D2 Shifts back right into 1's place
* D3 holds digit in 10's place
* D2 holds digit in 1's place
MOVE.B D3,D1 Displays digit in 10's place first
* converts digits 10+ into letters
LEA SUBEAHEX4,A3 Place address of TENS into A3 to continue from there after conversion
CMP.B #9,D1 Compares digit to 9
BGT CONV Print out letter representation if greater than 9
MOVE.B #3,D0 Displays digit if it is less than A
TRAP #15
SUBEAHEX4
MOVE.B D2,D1 Displays digit in 1's place second
* converts digits 10+ into letters
LEA SUBEAHEX5,A3 Places address of NEXT into A3 to continue from there after conversion
CMP.B #9,D1 Compares digit to 9
BGT CONV Print out letter representation if greater than 9
MOVE.B #3,D0 Displays digit if it is less than A
TRAP #15
SUBEAHEX5
* Display counter -- creates new line every 8 bytes
* D7 is used as counter
SUB.B #1,D7
BRA SUBEAHEX3 Loops back to display next address
*** display EA ends here
* converts number 10-15 to A-F
CONV CMP.B #10,D1 Displays 10 as A
BEQ HEXA
CMP.B #11,D1 Displays 11 as B
BEQ HEXB
CMP.B #12,D1 Displays 12 as C
BEQ HEXC
CMP.B #13,D1 Displays 13 as D
BEQ HEXD
CMP.B #14,D1 Displays 14 as E
BEQ HEXE
CMP.B #15,D1 Displays 15 as F
BEQ HEXF
HEXA LEA DISPA,A1 Loads A character
BRA PRINT
HEXB LEA DISPB,A1 Loads B character
BRA PRINT
HEXC LEA DISPC,A1 Loads C character
BRA PRINT
HEXD LEA DISPD,A1 Loads D character
BRA PRINT
HEXE LEA DISPE,A1 Loads E character
BRA PRINT
HEXF LEA DISPF,A1 Loads F character
BRA PRINT
PRINT MOVE.B #14,D0 Sets trap task to #14
TRAP #15 Prints out message in A1
JMP (A3)
EXIT MOVE.B #9,D0
TRAP #15
************************************ Output stuff **************************************
CR EQU $0D
LF EQU $0A
SPACE DC.B ' ',0
LINE DC.B '',CR,LF,0
TAB DC.B ' ',0
COMMA DC.B ',',0
OPENBRA DC.B '(',0
CLOSEBRA DC.B ')',0
POS DC.B '+',0
NEG DC.B '-',0
HASH DC.B '#',0
DISPA DC.B 'A',0
DISPB DC.B 'B',0
DISPC DC.B 'C',0
DISPD DC.B 'D',0
DISPE DC.B 'E',0
DISPF DC.B 'F',0
MHEX DC.B '$',0
MBYTE DC.B 'B ',0
MWORD DC.B 'W ',0
MLONG DC.B 'L ',0
MDN DC.B 'D',0
MAN DC.B 'A',0
MDATA DC.B 'DATA',0
MSUB DC.B 'SUB.',0
MSUBA DC.B 'SUBA.',0
MERROR DC.B 'ERROR',0
END START ; last line of source
*~Font name~Courier New~
*~Font size~10~
*~Tab type~1~
*~Tab size~4~