"Fossies" - the Fresh Open Source Software Archive 
Member "fasm/tools/listing.inc" (21 Feb 2022, 12405 Bytes) of package /linux/misc/fasm-1.73.30.tgz:
As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) fasm source code syntax highlighting (style:
standard) with prefixed line numbers.
Alternatively you can here
view or
download the uninterpreted source code file.
1
2 listing:
3 mov edx,[input_file]
4 call open
5 jc input_not_found
6 call load_file
7 mov [input],eax
8 cmp ecx,38h
9 jb invalid_input
10 cmp dword [eax],1A736166h
11 jne invalid_input
12 cmp dword [eax+44],0
13 je incomplete_input
14 add [eax+16],eax
15 add [eax+24],eax
16 add [eax+32],eax
17 add [eax+40],eax
18 add [eax+48],eax
19 mov edx,[eax+16]
20 add [eax+8],edx
21 add [eax+12],edx
22 mov edx,[eax+12]
23 call open
24 jc code_not_found
25 call load_file
26 mov [assembled_code],eax
27 mov [assembled_code_length],ecx
28 call close
29 mov [maximum_address_length],0
30 mov ebx,[input]
31 mov esi,[ebx+40]
32 lea ebp,[esi-4]
33 add ebp,[ebx+44]
34 get_offsets_for_lines:
35 cmp esi,ebp
36 je offsets_prepared
37 mov edx,[esi+4]
38 add edx,[ebx+32]
39 find_line_loaded_from_source:
40 test byte [edx+7],1 shl 7
41 jz store_offset_in_line
42 mov edx,[edx+8]
43 add edx,[ebx+32]
44 jmp find_line_loaded_from_source
45 store_offset_in_line:
46 cmp dword [edx+12],0
47 jne get_next_offset
48 mov [edx+12],esi
49 movzx ecx,byte [esi+27]
50 and cl,1
51 mov edi,[esi+20]
52 test edi,edi
53 jz base_name_length_ok
54 xor ecx,ecx
55 btr edi,31
56 jc count_base_name_characters
57 dec edi
58 shl edi,2
59 add edi,[ebx+48]
60 mov edi,[edi]
61 count_base_name_characters:
62 mov ecx,[ebx+20]
63 sub ecx,edi
64 add edi,[ebx+16]
65 mov edx,edi
66 xor al,al
67 repne scasb
68 mov ecx,edi
69 sub ecx,edx
70 base_name_length_ok:
71 cmp byte [esi+18],1
72 jb first_register_length_ok
73 ja first_register_with_scale
74 add ecx,5
75 jmp first_register_length_ok
76 first_register_with_scale:
77 add ecx,5+3
78 first_register_length_ok:
79 cmp byte [esi+19],1
80 jb second_register_length_ok
81 ja second_register_with_scale
82 add ecx,5
83 jmp second_register_length_ok
84 second_register_with_scale:
85 add ecx,5+3
86 second_register_length_ok:
87 cmp ecx,[maximum_address_length]
88 jb get_next_offset
89 mov [maximum_address_length],ecx
90 get_next_offset:
91 add esi,28
92 jmp get_offsets_for_lines
93 offsets_prepared:
94 mov eax,[esi]
95 mov [code_end],eax
96 add [maximum_address_length],19
97 mov edi,characters
98 xor al,al
99 make_characters_table:
100 stosb
101 inc al
102 jnz make_characters_table
103 mov edi,characters
104 mov esi,symbol_characters+1
105 movzx ecx,byte [esi-1]
106 xor eax,eax
107 mark_symbol_characters:
108 lodsb
109 mov byte [edi+eax],0
110 loop mark_symbol_characters
111 mov eax,[code_bytes_per_line]
112 imul eax,3
113 add eax,[maximum_address_length]
114 add eax,18
115 call alloc
116 jc not_enough_memory
117 mov [output_buffer],eax
118 mov esi,[ebx+32]
119 mov ebp,esi
120 add ebp,[ebx+36]
121 mov edx,[output_file]
122 call create
123 jc writing_error
124 mov [output_handle],ebx
125 xor eax,eax
126 mov [current_source_file],eax
127 mov [last_listed_address],eax
128 mov [code_length],eax
129 generate_listing:
130 cmp esi,ebp
131 jae listing_done
132 mov edi,[output_buffer]
133 test byte [esi+7],1 shl 7
134 jnz next_line
135 mov ebx,[esi+12]
136 test ebx,ebx
137 jz no_code_listing
138 test byte [ebx+26],11b
139 jnz no_code_listing
140 push esi
141 mov edx,[esi]
142 mov ecx,[esi+4]
143 find_next_code_point:
144 add esi,16
145 call skip_preprocessed_line
146 cmp esi,ebp
147 je last_code_point
148 cmp edx,[esi]
149 jne next_line_ok
150 cmp ecx,[esi+4]
151 je find_next_code_point
152 next_line_ok:
153 test byte [esi+7],1 shl 7
154 jnz find_next_code_point
155 mov eax,[esi+12]
156 test eax,eax
157 jz find_next_code_point
158 test byte [eax+26],11b
159 jnz find_next_code_point
160 mov eax,[eax]
161 jmp calculate_code_length
162 last_code_point:
163 mov eax,[code_end]
164 calculate_code_length:
165 pop esi
166 mov edx,[ebx]
167 sub eax,edx
168 jz no_code_listing
169 mov [code_length],eax
170 mov [code_offset],edx
171 add eax,edx
172 cmp eax,[assembled_code_length]
173 jbe write_file_offset
174 mov [code_length],0
175 write_file_offset:
176 call write_hex_dword
177 mov ax,': '
178 stosw
179 call list_address
180 call list_code
181 jmp code_listing_ok
182 no_code_listing:
183 mov al,20h
184 mov ecx,8+2
185 rep stosb
186 call list_address
187 mov ecx,[code_bytes_per_line]
188 imul ecx,3
189 mov al,20h
190 rep stosb
191 code_listing_ok:
192 call write_listing_data
193 mov eax,[input]
194 mov edx,[esi]
195 test edx,edx
196 jz main_source_file
197 add edx,[eax+32]
198 jmp source_name_ok
199 main_source_file:
200 mov edx,[eax+8]
201 source_name_ok:
202 cmp edx,[current_source_file]
203 je source_loaded
204 push ebx
205 push edx
206 call open
207 jc source_not_found
208 pop eax
209 xchg eax,[current_source_file]
210 test eax,eax
211 jz load_source
212 mov eax,[source]
213 call free
214 load_source:
215 call load_file
216 mov [source],eax
217 mov [source_length],ecx
218 call close
219 pop ebx
220 source_loaded:
221 mov eax,[source]
222 add eax,[esi+8]
223 mov [current_source_line],eax
224 push esi ebp
225 call write_source_line
226 pop ebp esi
227 write_supplemental_rows:
228 mov eax,[code_length]
229 or eax,[current_source_line]
230 jz next_line
231 mov edi,[output_buffer]
232 mov ecx,8+2
233 movzx eax,[show_addresses]
234 imul eax,[maximum_address_length]
235 add ecx,eax
236 mov al,20h
237 rep stosb
238 call list_code
239 call write_listing_data
240 push esi ebp
241 call write_source_line
242 pop ebp esi
243 jmp write_supplemental_rows
244 next_line:
245 mov edx,[esi]
246 mov ecx,[esi+4]
247 find_next_line:
248 add esi,16
249 call skip_preprocessed_line
250 cmp edx,[esi]
251 jne generate_listing
252 cmp ecx,[esi+4]
253 jne generate_listing
254 jmp find_next_line
255 list_address:
256 cmp [show_addresses],0
257 je address_ok
258 mov [address_start],edi
259 mov eax,[esi+12]
260 test eax,eax
261 jz address_finished
262 cmp [last_listed_address],0
263 je make_address
264 push esi edi
265 lea esi,[eax+8]
266 mov edi,[last_listed_address]
267 mov ecx,17
268 repe cmpsb
269 pop edi esi
270 je address_finished
271 make_address:
272 mov ebx,[esi+12]
273 lea eax,[ebx+8]
274 mov [last_listed_address],eax
275 mov al,'['
276 stosb
277 mov edx,[ebx+20]
278 test edx,edx
279 jz write_main_address
280 push esi
281 mov esi,edx
282 mov eax,[input]
283 btr esi,31
284 jc base_name_ready
285 dec esi
286 shl esi,2
287 add esi,[eax+48]
288 mov esi,[esi]
289 base_name_ready:
290 add esi,[eax+16]
291 copy_section_name:
292 lodsb
293 test al,al
294 jz section_name_ok
295 stosb
296 jmp copy_section_name
297 section_name_ok:
298 pop esi
299 mov al,':'
300 test edx,80000000h
301 jz address_separator_ok
302 cmp byte [ebx+27],0
303 jne address_separator_ok
304 mov al,'+'
305 address_separator_ok:
306 stosb
307 write_main_address:
308 cmp byte [ebx+27],0
309 jne write_negative_address
310 mov edx,[ebx+8+4]
311 call write_hex_dword
312 mov edx,[ebx+8]
313 call write_hex_dword
314 jmp write_address_registers
315 write_negative_address:
316 mov al,'-'
317 stosb
318 mov eax,[ebx+8]
319 mov edx,[ebx+8+4]
320 not eax
321 not edx
322 add eax,1
323 adc edx,0
324 push eax
325 call write_hex_dword
326 pop edx
327 call write_hex_dword
328 write_address_registers:
329 mov dl,[ebx+16]
330 mov dh,[ebx+18]
331 call address_register
332 mov dl,[ebx+17]
333 mov dh,[ebx+19]
334 call address_register
335 mov ax,']'
336 stosb
337 address_finished:
338 mov ecx,[maximum_address_length]
339 sub ecx,edi
340 add ecx,[address_start]
341 mov al,20h
342 rep stosb
343 address_ok:
344 ret
345 address_register:
346 cmp dh,0
347 je register_ok
348 jl negative_register
349 mov al,'+'
350 jmp register_sign_ok
351 negative_register:
352 mov al,'-'
353 register_sign_ok:
354 stosb
355 push esi
356 mov esi,address_registers
357 find_register:
358 lodsb
359 test al,al
360 jz register_found
361 cmp al,dl
362 je register_found
363 cmp dl,[esi]
364 je register_found
365 lodsb
366 movzx eax,al
367 add esi,eax
368 jmp find_register
369 register_found:
370 lodsb
371 movzx ecx,al
372 rep movsb
373 pop esi
374 cmp dh,1
375 je register_ok
376 mov al,'*'
377 stosb
378 test dh,0F0h
379 jz first_scale_digit_ok
380 mov al,dh
381 shr al,4
382 cmp al,10
383 sbb al,69h
384 das
385 stosb
386 first_scale_digit_ok:
387 mov al,dh
388 and al,1111b
389 cmp al,10
390 sbb al,69h
391 das
392 stosb
393 register_ok:
394 ret
395 list_code:
396 mov ecx,[code_length]
397 cmp ecx,[code_bytes_per_line]
398 jb code_bytes_count_ready
399 mov ecx,[code_bytes_per_line]
400 code_bytes_count_ready:
401 sub [code_length],ecx
402 mov edx,[code_offset]
403 add [code_offset],ecx
404 jecxz code_bytes_ok
405 push ecx
406 add edx,[assembled_code]
407 list_code_bytes:
408 mov al,[edx]
409 and al,1111b
410 cmp al,10
411 sbb al,69h
412 das
413 mov ah,al
414 mov al,[edx]
415 shr al,4
416 cmp al,10
417 sbb al,69h
418 das
419 stosw
420 mov al,20h
421 stosb
422 inc edx
423 loop list_code_bytes
424 pop ecx
425 code_bytes_ok:
426 neg ecx
427 add ecx,[code_bytes_per_line]
428 imul ecx,3
429 mov al,20h
430 rep stosb
431 ret
432 write_listing_data:
433 mov ecx,[output_buffer]
434 sub ecx,edi
435 and ecx,111b
436 mov al,20h
437 rep stosb
438 mov edx,[output_buffer]
439 mov ecx,edi
440 sub ecx,edx
441 mov ebx,[output_handle]
442 call write
443 jc writing_error
444 ret
445 write_source_line:
446 mov esi,[current_source_line]
447 test esi,esi
448 je write_line_break
449 mov ebp,[source_length]
450 add ebp,[source]
451 mov ebx,characters
452 xor cl,cl
453 start_cutting:
454 xor dl,dl
455 cut_source_line:
456 cmp esi,ebp
457 je end_of_file
458 lodsb
459 cmp al,0Dh
460 je cr_character
461 cmp al,0Ah
462 je lf_character
463 cmp al,1Ah
464 je end_of_line
465 or al,al
466 jz end_of_line
467 cmp dl,3Bh
468 je cut_source_line
469 cmp al,3Bh
470 je start_special_block
471 cmp dl,22h
472 je inside_string
473 cmp dl,27h
474 je inside_string
475 cmp al,'\'
476 je check_for_line_continuation
477 xlatb
478 test al,al
479 jz start_cutting
480 cmp dl,0FFh
481 je cut_source_line
482 cmp al,22h
483 je start_special_block
484 cmp al,27h
485 je start_special_block
486 mov dl,0FFh
487 jmp cut_source_line
488 start_special_block:
489 mov dl,al
490 jmp cut_source_line
491 inside_string:
492 cmp al,dl
493 jne cut_source_line
494 jmp start_cutting
495 check_for_line_continuation:
496 or cl,0FFh
497 cmp esi,ebp
498 je end_of_file
499 mov al,[esi]
500 cmp al,20h
501 je start_cutting
502 cmp al,0Dh
503 je start_cutting
504 cmp al,0Ah
505 je start_cutting
506 cmp al,3Bh
507 je start_cutting
508 xor cl,cl
509 jmp start_cutting
510 cr_character:
511 mov edx,esi
512 mov word [line_break],0Dh
513 cmp esi,ebp
514 je line_with_break
515 mov al,[esi]
516 cmp al,0Ah
517 jne line_with_break
518 inc edx
519 mov [line_break+1],al
520 jmp line_with_break
521 lf_character:
522 mov edx,esi
523 mov word [line_break],0Ah
524 cmp esi,ebp
525 je line_with_break
526 mov al,[esi]
527 cmp al,0Dh
528 jne line_with_break
529 inc edx
530 mov [line_break+1],al
531 line_with_break:
532 dec esi
533 jmp write_line
534 end_of_line:
535 dec esi
536 end_of_file:
537 mov edx,esi
538 write_line:
539 cmp cl,0FFh
540 je continued_line
541 xor edx,edx
542 continued_line:
543 xchg edx,[current_source_line]
544 mov ecx,esi
545 sub ecx,edx
546 mov ebx,[output_handle]
547 call write
548 jc writing_error
549 write_line_break:
550 mov edx,line_break
551 mov ecx,2
552 cmp [line_break+1],0
553 jne line_break_size_ok
554 dec ecx
555 line_break_size_ok:
556 call write
557 jc writing_error
558 ret
559 listing_done:
560 mov ebx,[output_handle]
561 call close
562 ret
563
564 load_file:
565 push ebx
566 mov al,2
567 xor edx,edx
568 call lseek
569 test eax,eax
570 jz empty_file
571 push eax
572 call alloc
573 jc not_enough_memory
574 push eax
575 xor al,al
576 xor edx,edx
577 call lseek
578 mov ecx,[esp+4]
579 mov edx,[esp]
580 call read
581 jc reading_error
582 pop eax ecx
583 pop ebx
584 ret
585 empty_file:
586 pop ebx
587 mov ecx,eax
588 ret
589
590 write_hex_dword:
591 mov ecx,8
592 write_hex_digits:
593 xor al,al
594 shld eax,edx,4
595 cmp al,10
596 sbb al,69h
597 das
598 stosb
599 shl edx,4
600 loop write_hex_digits
601 ret
602
603 skip_preprocessed_line:
604 lods byte [esi]
605 cmp al,1Ah
606 je skip_preprocessed_symbol
607 cmp al,3Bh
608 je skip_preprocessed_symbol
609 cmp al,22h
610 je skip_preprocessed_string
611 or al,al
612 jnz skip_preprocessed_line
613 ret
614 skip_preprocessed_symbol:
615 lods byte [esi]
616 movzx eax,al
617 add esi,eax
618 jmp skip_preprocessed_line
619 skip_preprocessed_string:
620 lods dword [esi]
621 add esi,eax
622 jmp skip_preprocessed_line
623
624
625 not_enough_memory:
626 call error
627 db 'not enough memory to load the required data',0
628 input_not_found:
629 call error
630 db 'the input file was not found',0
631 code_not_found:
632 call error
633 db 'the assembled file was not found',0
634 source_not_found:
635 call error
636 db 'could not find some of the source files',0
637 reading_error:
638 call error
639 db 'some error occured while trying to read file',0
640 writing_error:
641 call error
642 db 'some error occured while trying to write file',0
643 invalid_input:
644 call error
645 db 'input file is not a recognized assembly information format',0
646 incomplete_input:
647 call error
648 db 'input file does not contain an assembly dump',0
649
650 symbol_characters db 27, 9,0Ah,0Dh,1Ah,20h,'+-/*=<>()[]{}:,|&~#`;\'
651
652 address_registers db 23h,2,'bx'
653 db 25h,2,'bp'
654 db 26h,2,'si'
655 db 27h,2,'di'
656 db 40h,3,'eax'
657 db 41h,3,'ecx'
658 db 42h,3,'edx'
659 db 43h,3,'ebx'
660 db 44h,3,'esp'
661 db 45h,3,'ebp'
662 db 46h,3,'esi'
663 db 47h,3,'edi'
664 db 48h,3,'r8d'
665 db 49h,3,'r9d'
666 db 4Ah,4,'r10d'
667 db 4Bh,4,'r11d'
668 db 4Ch,4,'r12d'
669 db 4Dh,4,'r13d'
670 db 4Eh,4,'r14d'
671 db 4Fh,4,'r15d'
672 db 80h,3,'rax'
673 db 81h,3,'rcx'
674 db 82h,3,'rdx'
675 db 83h,3,'rbx'
676 db 84h,3,'rsp'
677 db 85h,3,'rbp'
678 db 86h,3,'rsi'
679 db 87h,3,'rdi'
680 db 88h,2,'r8'
681 db 89h,2,'r9'
682 db 8Ah,3,'r10'
683 db 8Bh,3,'r11'
684 db 8Ch,3,'r12'
685 db 8Dh,3,'r13'
686 db 8Eh,3,'r14'
687 db 8Fh,3,'r15'
688 db 0F4h,3,'eip'
689 db 0F8h,3,'rip'
690 db 0,1,'?'