@@ -16,54 +16,54 @@ PageOfOutput EQU 20 * how many lines of disassembled code is printin
16
16
START: * first instruction of program
17
17
******************** Start*****************************************************
18
18
LEA Stack,SP * load stack pointer value (A7 is stack pointer)
19
-
19
+
20
20
LEA Welcome,A1 * print welcome message
21
21
MOVE.B #14 ,D0
22
22
TRAP #15
23
-
23
+
24
24
restart LEA PromptStartAddr,A1 * load prompt to print, asking user for starting address
25
25
MOVE.B #14 ,D0 * print string at A1 to console
26
26
TRAP #15
27
-
27
+
28
28
LEA StoreInputStartAddr,A1 * load address to store user input
29
29
MOVE.B #2 ,D0 * read string from keyboard into (A1)
30
30
TRAP #15 * length of string is stored at D1
31
31
MOVE.B D1 ,D7 * store starting address length at D7 for now
32
-
32
+
33
33
JSR ValidAddressChars * check if starting address is valid
34
-
34
+
35
35
LEA StoreInputStartAddr,A4 * now convert input into hex address
36
36
JSR TranslateInputToAddrReg
37
-
38
- MOVE.L A6 ,D6 * move the returned address into a data register to perform a bit test
37
+
38
+ MOVE.L A6 ,D6 * move the returned address into a data register to perform a bit test
39
39
BTST.L #0 ,D6 * check that the address is on a word boundary
40
40
BNE ThrowInputError
41
41
MOVEA.L A6 ,A0 * put the starting address (returned into A6) into A0
42
-
42
+
43
43
LEA PromptEndAdder,A1 * load prompt to print, asking user for ending address
44
44
MOVE.B #14 ,D0 * print string at A1 to console
45
45
TRAP #15
46
-
47
- LEA StoreInputEndAddr,A1
46
+
47
+ LEA StoreInputEndAddr,A1
48
48
MOVE.B #2 ,D0 * read string from keyboard into (A1)
49
49
TRAP #15 * length of string input is stored at D1
50
-
50
+
51
51
JSR ValidAddressChars * check if ending address is valid
52
-
52
+
53
53
LEA StoreInputEndAddr,A4 * now convert input into hex address
54
54
JSR TranslateInputToAddrReg
55
-
55
+
56
56
MOVE.L A6 ,D6 * move the returned address into a data register to perform a bit test
57
57
BTST.L #0 ,D6 * check that the address is on a word boundary
58
- BNE ThrowInputError
58
+ BNE ThrowInputError
59
59
MOVEA.L A6 ,A3 * put the ending address at A3
60
-
60
+
61
61
* pointer to next opcode is in A0
62
62
* ending address is at A3
63
-
63
+
64
64
CMPA.L A3 ,A0 * check that startAddress <= endAddress
65
65
BGT endProg * exit program if start > end
66
-
66
+
67
67
* clear some registers
68
68
CLR.L D0
69
69
CLR.L D4
@@ -73,55 +73,55 @@ restart LEA PromptStartAddr,A1 * load prompt to print, asking u
73
73
MOVE.L #0 ,A4
74
74
MOVE.L #0 ,A5
75
75
MOVE.L #0 ,A6
76
-
76
+
77
77
LEA PromptToPressENTER,A1 * prompt user to press ENTER for next page of data
78
78
MOVE.B #14 ,D0
79
79
TRAP #15
80
80
81
- **************************************** printing out disassembled code ********************************************
81
+ **************************************** printing out disassembled code ********************************************
82
82
waitForENTER LEA OutputBuffer,A1
83
83
MOVE.L #0 ,D2 * reset linesOutputted to 0
84
84
MOVE.B #2 ,D0 * trap task for reading input
85
85
TRAP #15 * read input, expecting ENTER from user to proceed disassembling
86
-
86
+
87
87
loopPrintLines CMP.L A3 ,A0 * while pointerToNextOpcode <= ending address
88
88
BGT endProg
89
-
89
+
90
90
CMP.L #PageOfOutput,D2 * stop printing when linesOutputted == linesInAPage
91
91
BEQ waitForENTER * go back to waiting for ENTER from user
92
92
ADD.B #1 ,D2 * increment linesOutputted
93
-
93
+
94
94
* prepare to call opcodes
95
- LEA OutputBuffer,A2 * set output buffer to A2
95
+ LEA OutputBuffer,A2 * set output buffer to A2
96
96
MOVEA.L A0 ,A6 * track current pointerToNextOpcode in case bad flag is set
97
97
98
98
JSR AddCurrAddressToBuffer * put current address into the output buffer
99
-
99
+
100
100
MOVEM .L D1 -D7 /A1 /A3 -A6 ,-(SP ) * save all registers except A0 (pointerToNextOpcode),
101
101
* A2 (output buffer pointer),
102
102
* D0 (bad flag)
103
103
MOVE.B #0 ,D0 * clear bad flag
104
-
104
+
105
105
JSR OP_START * call opcodes
106
-
106
+
107
107
MOVEM .L (SP )+,D1 -D7 /A1 /A3 -A6 * restore all registers except A0,A2,D0
108
-
108
+
109
109
CMP.B #0 ,D0 * bad flag set?
110
110
BEQ noFlagSet
111
111
JSR HandleBadFlag * handle bag flag if it was set
112
-
112
+
113
113
noFlagSet MOVE.B #0 ,(A2 )+ * null terminate the string stored at (A2)
114
-
114
+
115
115
JSR OutputTheBuffer
116
-
117
- BRA loopPrintLines * go back to process and print another line
118
-
116
+
117
+ BRA loopPrintLines * go back to process and print another line
118
+
119
119
*******************************************************************************
120
- ******************** FIN ******************************************************
120
+ ******************** FIN ******************************************************
121
121
endProg LEA EOF,A1 * print end of file message
122
122
MOVE.B #14 ,D0
123
123
TRAP #15
124
-
124
+
125
125
STOP #3000 * end program
126
126
127
127
*******************************************************************************
@@ -130,7 +130,7 @@ ThrowInputError LEA InvalidInputError,A1 * load address that holds error st
130
130
MOVE.B #0 ,D0 * print the string
131
131
MOVE.B #155 ,D1
132
132
TRAP #15
133
-
133
+
134
134
CLR.L D0
135
135
CLR.L D1
136
136
CLR.L D2
@@ -141,25 +141,25 @@ ThrowInputError LEA InvalidInputError,A1 * load address that holds error st
141
141
MOVE.L #0 ,A4
142
142
MOVE.L #0 ,A5
143
143
MOVE.L #0 ,A6
144
-
144
+
145
145
MOVE.B #CR,(A1 )+
146
146
MOVE.B #LF,(A1 )+
147
147
MOVE.B #0 ,D0 * print the string
148
148
MOVE.B #0 ,D1
149
149
TRAP #15
150
-
151
- BRA restart
150
+
151
+ BRA restart
152
152
153
153
*******************************************************************************
154
154
******************** Method ***************************************************
155
155
156
156
* load the string you want to check for validity into A1 before calling the method
157
157
* load the length of the string into D1
158
- ValidAddressChars CMP.B #1 ,D1 * must have b/t 1 and 8 characters in address
158
+ ValidAddressChars CMP.B #1 ,D1 * must have b/t 1 and 8 characters in address
159
159
BLT ThrowInputError * error if less than 1
160
- CMP.B #8 ,D1
160
+ CMP.B #8 ,D1
161
161
BGT ThrowInputError * error if greater than 8
162
-
162
+
163
163
VACloop CMP.B D1 ,D3 * D3 is loop counter
164
164
BEQ endMethodVAC
165
165
MOVE.B (A1 )+,D2 * D2 holds current byte to check
@@ -171,9 +171,9 @@ VACloop CMP.B D1,D3 * D3 is loop counter
171
171
BEQ ThrowInputError
172
172
ADDQ #1 ,D3 * increment counter
173
173
BRA VACloop
174
-
174
+
175
175
endMethodVAC MOVE.L #0 ,D3 * clear out counter data reg
176
- RTS
176
+ RTS
177
177
178
178
179
179
* translate the address into register A0
@@ -183,27 +183,27 @@ TranslateInputToAddrReg CLR.L D7
183
183
MOVEA.L A4 ,A5 * remember the start address
184
184
MOVE.B D1 ,D4 * remember the char count
185
185
TITARloop1 CMP.B D1 ,D3 * while loop counter < address length in chars
186
- BEQ endTITARloop1
186
+ BEQ endTITARloop1
187
187
CMP.B #$40 ,(A4 ) * greater than $40? translate A-F
188
- BGT handleAThroughF
188
+ BGT handleAThroughF
189
189
SUB.B #$30 ,(A4 ) * subtract $30 from the 0-9 char in ASCII
190
190
BRA digitBt0And9 * handle characters between 0 and 9
191
191
handleAThroughF SUB.B #$37 ,(A4 ) * subtract $37 from the A-F char in ASCII
192
192
digitBt0And9 ADD.B (A4 ),D7 * add the translated byte into D7
193
193
ADDA.L #1 ,A4 * increment A4
194
194
SUB.B #1 ,D1 * decrement counter
195
195
CMP.B D1 ,D3 * do not shift when we reach the last char in the address
196
- BEQ doNotShiftThisTime
196
+ BEQ doNotShiftThisTime
197
197
LSL.L #$04 ,D7 * shift the translated part of the address four bits to the left
198
198
doNotShiftThisTime BRA TITARloop1 * shifting allows adding the next nibble of the translated address to D7
199
-
199
+
200
200
endTITARloop1 CMP.B #4 ,D4
201
201
BGT moveLongAddress * if the address is >4 hex chars long move it into an address reg as a long
202
202
MOVEA.W D7 ,A6 * if the address is <=4 hex chars move it as a word (supports sign extension)
203
- BRA endMethodTITAR
203
+ BRA endMethodTITAR
204
204
moveLongAddress MOVEA.L D7 ,A6 * move the translated address into an address register
205
205
endMethodTITAR RTS
206
-
206
+
207
207
* each disassembled line needs the address of the instruction in memory
208
208
* printed on the left side, this method loads the address into the output buffer
209
209
* current address is stored at A0
@@ -216,31 +216,31 @@ loopACATB CMP.B #8,D3 * while not all 8 char
216
216
MOVE.B D4 ,D5 * move the first byte of D4 into D5
217
217
AND #%00001111 ,D5 * bit mask the second nibble out of the byte
218
218
MOVEA D5 ,A5 * move the nibble in question into A5
219
- MOVE.B (NumbersToASCII,A5 ),(A2 )+ * displace the nibble value into the string hashtable and put
219
+ MOVE.B (NumbersToASCII,A5 ),(A2 )+ * displace the nibble value into the string hashtable and put
220
220
BRA loopACATB * the hash result into the output buffer
221
221
* do this for all characters in the address
222
-
222
+
223
223
*Tab, put a full tab into the output buffer for output formatting
224
224
endMethodACATB MOVE.B #$20 ,(A2 )+
225
225
MOVE.B #$20 ,(A2 )+
226
226
MOVE.B #$20 ,(A2 )+
227
227
MOVE.B #$20 ,(A2 )+
228
228
RTS
229
-
229
+
230
230
* handles problems encountered by opcodes and effective addressing for the output buffer
231
- * the bad flag is stored at D0
231
+ * the bad flag is stored at D0
232
232
HandleBadFlag LEA OutputBuffer,A2 * reset the output buffer to overwrite any bad data
233
233
ADDA #12 ,A2 * don't overwrite the address location which is already in there
234
234
235
235
* reset the flag
236
236
MOVE.B #0 ,D0
237
-
237
+
238
238
* put 'DATA' into the output buffer
239
239
MOVE.B #$44 ,(A2 )+
240
240
MOVE.B #$41 ,(A2 )+
241
241
MOVE.B #$54 ,(A2 )+
242
242
MOVE.B #$41 ,(A2 )+
243
-
243
+
244
244
* put space formatting into the output buffer
245
245
MOVE.B #$20 ,(A2 )+
246
246
MOVE.B #$20 ,(A2 )+
@@ -249,15 +249,15 @@ HandleBadFlag LEA OutputBuffer,A2 * reset the output buf
249
249
MOVE.B #$20 ,(A2 )+
250
250
MOVE.B #$20 ,(A2 )+
251
251
MOVE.B #$20 ,(A2 )+
252
-
252
+
253
253
* add the $ to the buffer to show the hex value
254
254
MOVE.B #$24 ,(A2 )+
255
-
255
+
256
256
* get the instruction word that could not be disassembled
257
257
MOVE.W (A6 ),D1 * A6 stores the saved pointerToNextOpcode before opcodes was called
258
258
LSL.L #$08 ,D1 * shift the value left a word
259
259
LSL.L #$08 ,D1
260
-
260
+
261
261
* put the bad instruction word into the output buffer
262
262
MOVE.B #0 ,D3 * reset loop counter
263
263
loopHBF CMP.B #4 ,D3 * loop for each hex character in the word
@@ -269,36 +269,36 @@ loopHBF CMP.B #4,D3 * loop for each hex ch
269
269
MOVEA D4 ,A5 * move the single hex char into A5
270
270
MOVE.B (NumbersToASCII,A5 ),(A2 )+ * displace the hex value into the string hashtable and load the result
271
271
BRA loopHBF * into the output buffer
272
-
272
+
273
273
endMethodHBF RTS
274
-
275
- * print a disassembled instructions to the user
274
+
275
+ * print a disassembled instructions to the user
276
276
OutputTheBuffer MOVE.B #0 ,D0 * load trap task for printing a string at A1
277
277
LEA OutputBuffer,A1 * load output buffer into A1
278
278
MOVEA.L A2 ,A5 * get the current pointer spot in the output buffer
279
279
SUBA OutputBuffer,A5 * subtract the address of the beginning of the output buffer
280
280
* from the address of the current pointer in the output buffer
281
281
MOVE.W A5 ,D1 * this results in the number of characters in the buffer to print out
282
282
TRAP #15 * which is stored in D1, telling TRAP how much to print
283
-
283
+
284
284
RTS
285
285
286
286
287
-
287
+
288
288
*******************************************************************************
289
289
******************** variables and constants **********************************
290
- * string hashtable
290
+ * string hashtable
291
291
NumbersToASCII DC.B $30 ,$31 ,$32 ,$33 ,$34 ,$35 ,$36 ,$37 ,$38 ,$39 ,$41 ,$42 ,$43 ,$44 ,$45 ,$46
292
292
* prompts to user
293
- PromptStartAddr DC.B 'Enter starting address of file, then press ENTER: ',0
293
+ PromptStartAddr DC.B 'Enter starting address of file, then press ENTER: ',0
294
294
PromptEndAdder DC.B 'Enter ending address of file, then press ENTER: ',0
295
295
PromptToPressENTER DC.B 'Press ENTER to get the next page of disassembled code.',0
296
296
Welcome DC.B 'Welcome to our disassembler!',CR,LF,'Created by Sexy8k: [Natalia Gilbertson][Thomas Kercheval][Saam Amiri]',CR,LF,'Please load your file into memory.',CR,LF,CR,LF,0
297
297
EOF DC.B '~ End of file ~',0
298
298
* error message
299
- InvalidInputError DC.B 'ERROR: Invalid input address. Addresses must be between 1 and 8 characters long, ',CR,LF,'at a word boundary, and containing only digits 0-9 and characters A-F.',0
299
+ InvalidInputError DC.B 'ERROR: Invalid input address. Addresses must be between 1 and 8 characters long, ',CR,LF,'at a word boundary, and containing only digits 0-9 and characters A-F.',0
300
300
301
- StoreInputStartAddr DC.L 0 * each address needs 8 bytes to be read into memory
301
+ StoreInputStartAddr DC.L 0 * each address needs 8 bytes to be read into memory
302
302
StoreInputStartAddr2 DC.L 0 * so more space is built in
303
303
StoreInputEndAddr DC.L 0
304
304
StoreInputEndAddr2 DC.L 0
0 commit comments