| 『第 5 楼』:
 
 
使用 LLM 解释/回答一下 
 
 
再给个COM2EXE的转换程序,大家可以对照学习EXE与COM的文件差别。所附源程序中第1行及相关部分为我所加,你可以根据需要把xtra_bytes equ后面的数字256改为0到65500之间的任何值。试一试吧!
 
 xtra_bytes equ 256      ;0--65500,so long as you need!!!
 .286
 Code    SEGMENT para PUBLIC 'CODE'
 Assume  CS:Code, DS:Code
 ORG     100h
 ;==========================================================
 cr	equ	10
 lf	equ	13
 
 ;==========================================================
 Start:
 Call	Header          ;logo
 Call	CmdLine
 cmp	al,-1
 je	_usage
 Call	OpenRFile       ;open readfile
 cmp	al,-1
 je	_norfile
 Call	OpenWFile	;open writefile
 cmp	al,-1
 je	_nowfile
 Call	HeadOn		;write header
 _closewfile: Call CloseWFile	;close writefile
 jmp	_closerfile
 _nowfile: Call	NoFile
 _closerfile: Call CloseRFile    ;close readfile
 jmp	_ende
 _norfile: Call	NoFile
 jmp	_ende
 _usage:	Call	Usage           ;display usage
 _ende:	Call	Footer          ;display ---------------------
 mov     ax,4c00h
 int     21h
 
 ;==========================================================
 HeadOn	PROC near
 pusha
 mov cx,32+xtra_bytes   ;bytes
 mov	ah,40h		;write to file
 mov	bx,WFileHandle	;handle of file
 lea	dx,exe_header	;data: where at
 int	21h
 jc	headon_fail
 
 headon_lop:
 mov	ah,3fh		;read
 mov	bx,RFileHandle	;handle
 mov	cx,63000	;bytes
 lea	dx,loadword	;where at
 int	21h
 or	ax,ax		;0 bytes ?	!!!!
 jz	headon_end	;		!!!!
 add	filesize,ax
 mov	cx,ax		;bytes
 mov	ah,40h		;write
 mov	bx,WFileHandle	;handle
 lea	dx,loadword	;where at
 int	21h
 jc	headon_fail
 jmp	headon_lop
 headon_end:
 add filesize,32+xtra_bytes
 xor	cx,cx
 mov	dx,2		;where at (cx:dx)
 mov	ax,4200h	;move filepointer to (from files begin)
 mov	bx,WFileHandle	;handle
 int	21h
 mov	ax,filesize
 and	ax,511
 mov	loadword,ax	;length mod 512
 mov	ax,filesize
 mov	cl,9
 shr	ax,cl 		;div 512
 inc	ax
 mov	,ax	;pages
 mov	cx,4		;bytes
 mov	ah,40h		;write
 mov	bx,WFileHandle	;handle
 lea	dx,loadword	;where at
 int	21h
 lea  	dx,headon_
 Call 	Print
 popa
 ret
 headon_fail:
 lea	dx,headon_fail_
 Call	Print
 CALL	FileName
 popa
 mov	al,-1
 ret
 headon_ db  	'CREATED EXE-FILE',cr,lf,'$'
 headon_fail_ db 'CANNOT WRITE TO $'
 exe_header db	'MZ'		;offset 00 (EXE-signature)
 dw	0,0		;bytes on last page, pages
 dw	0		;relocations
 dw      2+(xtra_bytes shr 4)               ;size of header in paragraphs
 dw	1000h,-1	;minimum, maximum memory
 dw	0fff0h,0fffeh	;ss,sp values (ss=PSP)
 dw	0		;checksum
 dw	100h,0fff0h	;ip,cs values (cs=PSP)
 dw	1ch		;offset to reloc table
 dw	0,0,0		;overlay number, 0,0 (fill-ups)
 db xtra_bytes dup(0)
 HeadOn	ENDP
 
 ;==========================================================
 CloseRFile PROC	near
 pusha
 mov   	bx,RFileHandle
 mov	ah,3eh
 int	21h
 popa
 ret
 CloseRFile ENDP
 
 ;==========================================================
 CloseWFile PROC	near
 pusha
 mov   	bx,WFileHandle
 mov	ah,3eh
 int	21h
 popa
 ret
 CloseWFile ENDP
 
 ;==========================================================
 NoFile	PROC	near
 pusha
 lea  	dx,nofile_
 Call	Print
 Call	FileName
 popa
 ret
 nofile_	db	'CANNOT OPEN FILE $'
 NoFile	ENDP
 
 ;==========================================================
 OpenRFile PROC	near
 pusha
 mov	dx,82h		;asciiz = cmdline
 mov	ax,3d00h	;open it for read
 int	21h
 jc   	openrfile_fail
 mov	RFileHandle,ax
 lea	dx,openrfile_
 Call	Print
 Call	FileName
 popa
 ret
 openrfile_fail:
 popa
 mov	al,-1
 ret
 openrfile_ db	'OPENED FILE $'
 OpenRFile ENDP
 
 ;==========================================================
 OpenWFile PROC	near
 pusha
 xor  	ah,ah
 mov	al,ds:80h
 mov	di,ax
 mov	ds:,'XE'
 mov	byte ptr ds:,'E'
 mov	dx,82h		;asciiz = cmdline
 mov	ah,3ch		;open it for write
 mov	cx,0		;attribute
 int	21h
 cmp	ax,0
 je   	openwfile_fail
 mov	WFileHandle,ax
 lea	dx,openwfile_
 Call	Print
 Call	FileName
 popa
 ret
 openwfile_fail:
 popa
 mov 	al,-1
 ret
 openwfile_ db	'OPENED FILE $'
 OpenWFile ENDP
 
 ;==========================================================
 CmdLine	PROC	near
 pusha
 xor  	ah,ah
 mov	al,ds:80h
 cmp	ax,6 		;less than 5 chars (cmd-LINE) incl. ret?
 jl	cmdline_fail
 mov	di,ax
 mov	word ptr ds:,'$'*256
 popa
 ret
 cmdline_fail:
 popa
 mov	al,-1
 ret
 CmdLine	ENDP
 
 ;==========================================================
 Header	PROC	near
 pusha
 lea	dx,header_
 Call	Print
 popa
 ret
 header_	db	cr,lf
 db	'--==-- COM2EXE --==-- by HENDR璛 of OBSESSION',cr,lf,'$'
 Header	ENDP
 
 ;==========================================================
 Footer	PROC	near
 pusha
 lea  	dx,footer_
 Call	Print
 popa
 ret
 footer_	db    	'--==**==-- COM2EXE --==**==--',cr,lf,'$'
 Footer	ENDP
 
 ;==========================================================
 Usage	PROC	near
 pusha
 lea  	dx,usage_
 Call	Print
 popa
 ret
 usage_ 	db	'USAGE: C2E PROGRAM.COM',cr,lf,'$'
 Usage	ENDP
 
 ;==========================================================
 Print	PROC	near
 mov	ah,09h
 int	21h
 ret
 Print	ENDP
 
 ;==========================================================
 Return	PROC	near
 pusha
 lea	dx,return_
 Call	Print
 popa
 ret
 return_	db	cr,lf,'$'
 Return	ENDP
 
 ;==========================================================
 FileName PROC	near
 pusha
 mov  	dx,82h
 Call	Print
 Call	Return
 popa
 ret
 FileName ENDP
 
 ;==========================================================
 filesize	dw	0
 RFileHandle	dw	?
 WFileHandle	dw	?
 loadword	dw	?
 
 ;==========================================================
 Code    ENDS
 END     Start
 
 Last edited by 本是 on 2007-1-21 at 01:22 AM ]
 
 
 
 
 
 |