prepsrc.inc 1.82 KB
Newer Older
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

preprocessed_source:
	mov	edx,[input_file]
	call	open
	jc	input_not_found
	mov	al,2
	xor	edx,edx
	call	lseek
	cmp	eax,30h
	jb	invalid_input
	push	eax
	call	alloc
	jc	not_enough_memory
	push	eax
	xor	al,al
	xor	edx,edx
	call	lseek
	mov	ecx,[esp+4]
	mov	edx,[esp]
	call	read
	jc	reading_error
	pop	eax ecx
	cmp	dword [eax],1A736166h
	jne	invalid_input
	mov	esi,[eax+32]
	add	esi,eax
	mov	ebp,[eax+36]
	add	ebp,esi
	mov	edi,eax
	push	eax
      preprocessed_to_text:
	cmp	esi,ebp
	jae	conversion_done
	add	esi,16
	xor	dl,dl
      convert_preprocessed_line:
	lodsb
	cmp	al,1Ah
	je	copy_symbol
	cmp	al,22h
	je	copy_symbol
	cmp	al,3Bh
	je	preprocessor_symbols
	or	al,al
	jz	line_converted
	stosb
	xor	dl,dl
	jmp	convert_preprocessed_line
      copy_symbol:
	or	dl,dl
	jz	space_ok
	mov	byte [edi],20h
	inc	edi
      space_ok:
	cmp	al,22h
	je	quoted
	lodsb
	movzx	ecx,al
	rep	movsb
	or	dl,-1
	jmp	convert_preprocessed_line
      quoted:
	mov	al,27h
	stosb
	lodsd
	mov	ecx,eax
	jecxz	quoted_copied
      copy_quoted:
	lodsb
	stosb
	cmp	al,27h
	jne	quote_ok
	stosb
      quote_ok:
	loop	copy_quoted
      quoted_copied:
	mov	al,27h
	stosb
	or	dl,-1
	jmp	convert_preprocessed_line
      preprocessor_symbols:
	mov	al,3Bh
	stosb
	jmp	copy_symbol
      line_converted:
	mov	ax,0A0Dh
	stosw
	jmp	preprocessed_to_text
      conversion_done:
	mov	edx,[output_file]
	call	create
	jc	writing_error
	pop	edx
	mov	ecx,edi
	sub	ecx,edx
	call	write
	jc	writing_error
	call	close
	ret

not_enough_memory:
	call	error
	db	'not enough memory to load the required data',0
input_not_found:
	call	error
	db	'the input file was not found',0
reading_error:
	call	error
	db	'some error occured while trying to read file',0
writing_error:
	call	error
	db	'some error occured while trying to write file',0
invalid_input:
	call	error
	db	'input file is not a recognized assembly information format',0