forked from peterstanton/TeamAwesome-project
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelpers.X68
142 lines (114 loc) · 6.95 KB
/
helpers.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
*-----------------------------------------------------------
* Title : Disassembler Final Project
* Written by : Team Awesome (Olga Rocheeva, Dwina Solihin, Peter Stanton)
* Date : April 15, 2017
* Description: CSS 422 Final Project
*-----------------------------------------------------------
*-----------------------------------------------------------
*Below are helper subroutines that will be used throughout
*this final project.
*-----------------------------------------------------------
*ASCII to Hexadecimal conversion Loop helper
sub_AsToHeLoop MOVE.B (A1)+,D0 *gets first byte
JSR sub_breakDownAs *breaks down ASCII code
ADD.L D0,D1 *load that char into D1
CMPI.B #$0,(A1) *checks if more needs to be broken down
BEQ athEndLoop *if no more is needed to be worked on, exits
LSL.L #$4,D1 *else, shift remaining char in D1 for next char
BRA sub_AsToHeLoop *loops through again
athEndLoop MOVE.L D1,D7 *broken down hex number in D7
RTS
*-----------------------------------------------------------
*Breaks down ASCII code from digits 0-9, a-f or A-F
*Makes the assumption that D0 holds $30-$39, $41-$46
*-----------------------------------------------------------
sub_breakDownAs CMP.B #$39,D0 *$30-$39 is a digit (0-9)
BGT as_smallLetter
CMP.B #$46,D0
BGT as_bigLetter
SUB.B #$30,D0
RTS
as_smallLetter SUB.B #$30,D0 *for letters a-f
RTS
as_bigLetter SUB.B #$37,D0 *for leters A-F
RTS
*-----------------------------------------------------------
*start reading data helper method
*check the data start address
sub_StartReadingData MOVE.L location_startData,D1
BTST #0,D0 *checks if LSB is 1,
BNE srdFailAddrOddB *if 1, then address is odd and invalid
MOVE.L #0,D7 *if D7 equals 0, then address is valid
srdFinish RTS
srdFailAddrOddB LEA addr_oddBit_msg,A1
MOVE.B #14,D0
TRAP #15
MOVE.L #1,D7 *if D7 equals 1, then address is invalid
BRA srdFinish
*-----------------------------------------------------------
*end reading data helper method
*check the data end address
sub_EndReadingData MOVE.L D1,A2
MOVE.L location_endData,A3
BTST #0,D0 *checks if LSB is 1,
BNE erdFailAddrOddB *if 1, then address is odd and invalid
CMP.L D0,D1 *end address must be greater than start address
erdFinish RTS
erdFailAddrOrder LEA addr_order_check,A4
MOVE.B #14,D0
TRAP #15
MOVE.L #1,D7
BRA erdFinish
erdFailAddrOddB LEA addr_oddBit_msg,A1
MOVE.B #14,D0
TRAP #15
MOVE.L #1,D7 *if D7 equals 1, then address is invalid
BRA erdFinish
*-----------------------------------------------------------
*Prints Table
sub_PrintTable CLR.L D7
MOVE.B table_length,D7 *moves data to D7 as decreasing counter
PrintTableLoopS CMP.B #0,D7 *checks of counter is 0
BEQ PrintTableLoopE *will end loop
LEA space,A1 *if not, print single space in consold
MOVE.B #14,D0
TRAP #15
SUBQ.B #1,D7 *decrease loop counter by 1
BRA PrintTableLoopS
PrintTableLoopE RTS
*-----------------------------------------------------------
*Prints a CR,LF at end of printed string
sub_PrintCRLF LEA linebreak,A1
MOVE.B #14,D0
TRAP #15
RTS
*-----------------------------------------------------------
*Converts Hex values to ASCII and displays in console
sub_PrintHexa MOVEM.L D3-D6,-(SP) *Store registers in stack
LEA hexatable,A5
MULU.W #4,D6 *Convert number of digits to total bits (4 bits per char)
MOVE.L #32,D3 *Set the total number of bits
SUB.L D6,D3 *Set the bit displacement for nibbles left to right
MOVE.L #28,D4 *Bit displacement to truncate all but one nibble
PrintHexaLoop MOVE.L D7,D5 *Load/reload hex output into D6 for work.
LSL.L D3,D5 *For each loop, isolate the next nibble using displacement
LSR.L D4,D5 *Truncate everything else except the nibble
MULU #2,D5 *Multiply nibble by two, find character in char_table
LEA 0(A5,D5),A1 *Store the character for output
MOVE.B #14,D0
TRAP #15
ADD.B #4,D3 *Add another 4 bits to displacement to get next nibble
CMP.B #32,D3 *If displacement = 32, we're done.
BNE PrintHexaLoop
MOVEM.L (SP)+,D3-D6 *Replace registers from stack
RTS
*-----------------------------------------------------------
*Prints the hex Address stored in A2, where it is jumping to
sub_PrintAddress CLR.L D7
MOVE.L A3,D7 *puts the contents of A3 (start Address) in D7 now
MOVE.L #8,D6
JSR sub_PrintHexa
MOVE.B #3,table_length
JSR sub_PrintTable
RTS
*-----------------------------------------------------------