【dos】将文本文件转化成EXE文件,忘了当初的出发点是啥
1
;将文本文件转化成EXE文件
97
zbin
2
3 code segment
4 org 100h
5 assume cs:code,ds:code,es:code
6 b0: jmp b2
7 file db 13 dup ( ? )
8 handle dw ?
9 lenth dw ?
10
11
12 b1: push cs
13 pop ds
14 mov cx, 0
15 lea si,buf1
16 n1:lodsb
17 cmp al,1ah
18 je exit
19 cmp al,0dh
20 je n3
21 n4:mov dl,al
22 mov ah,2h
23 int 21h
24 jmp n1
25 n3: inc cx
26 cmp cx, 15
27 je n5
28 jmp n4
29 n5: mov ah, 0
30 int 16h
31 mov cx, 0
32 jmp n4
33 exit: mov ah,4ch
34 int 21h
35 buf1 db 40 dup( 1024 dup( ? ))
36
37 ; **************************
38 b2: mov si,81h
39 m1: lodsb
40 cmp al,20h
41 je m1
42 dec si
43 mov di,si
44 mov cx, 20
45 cld
46 mov al,0dh
47 repnz scasb
48 dec di
49 mov byte ptr cs:[di], 0
50 mov dx,si
51 mov di,si
52 mov cx, 10
53 mov al, ' . '
54 cld
55 repnz scasb
56 dec di
57 sub di,si
58 mov cx,di
59 lea di,file
60 cld
61 rep movsb
62 mov byte ptr[di], ' . '
63 mov byte ptr[di + 1 ], ' e '
64 mov byte ptr[di + 2 ], ' x '
65 mov byte ptr[di + 3 ], ' e '
66 mov byte ptr[di + 4 ], 0
67 ; ***************************
68 mov ah,3dh
69 mov al, 0
70 int 21h
71 mov handle,ax
72 mov bx,ax
73 mov ah,42h
74 mov cx, 0
75 mov al, 2
76 mov dx, 0
77 int 21h
78 mov lenth,ax
79 mov ah,42h
80 mov al, 0
81 mov cx, 0
82 mov dx, 0
83 int 21h
84 mov cx,lenth
85 mov bx,handle
86 lea dx,buf1
87 mov ah,3fh
88 int 21h
89 mov di,lenth
90 mov byte ptr buf1[di],1ah
91 mov ah,3eh
92 int 21h
93
94 lea ax,b1
95 lea bx,b2
96 sub ax,bx
97 mov lenth,ax
98 mov ah,3ch
99 lea dx,file
100 mov cx, 0
101 int 21h
102 mov handle,ax
103 mov bx,ax
104 mov cx,lenth
105 lea dx,b1
106 mov ah,40h
107 int 21h
108 mov ah,3eh
109 int 21h
110 mov ah,4ch
111 int 21h
112
113 code ends
114 end b0
115
2
3 code segment
4 org 100h
5 assume cs:code,ds:code,es:code
6 b0: jmp b2
7 file db 13 dup ( ? )
8 handle dw ?
9 lenth dw ?
10
11
12 b1: push cs
13 pop ds
14 mov cx, 0
15 lea si,buf1
16 n1:lodsb
17 cmp al,1ah
18 je exit
19 cmp al,0dh
20 je n3
21 n4:mov dl,al
22 mov ah,2h
23 int 21h
24 jmp n1
25 n3: inc cx
26 cmp cx, 15
27 je n5
28 jmp n4
29 n5: mov ah, 0
30 int 16h
31 mov cx, 0
32 jmp n4
33 exit: mov ah,4ch
34 int 21h
35 buf1 db 40 dup( 1024 dup( ? ))
36
37 ; **************************
38 b2: mov si,81h
39 m1: lodsb
40 cmp al,20h
41 je m1
42 dec si
43 mov di,si
44 mov cx, 20
45 cld
46 mov al,0dh
47 repnz scasb
48 dec di
49 mov byte ptr cs:[di], 0
50 mov dx,si
51 mov di,si
52 mov cx, 10
53 mov al, ' . '
54 cld
55 repnz scasb
56 dec di
57 sub di,si
58 mov cx,di
59 lea di,file
60 cld
61 rep movsb
62 mov byte ptr[di], ' . '
63 mov byte ptr[di + 1 ], ' e '
64 mov byte ptr[di + 2 ], ' x '
65 mov byte ptr[di + 3 ], ' e '
66 mov byte ptr[di + 4 ], 0
67 ; ***************************
68 mov ah,3dh
69 mov al, 0
70 int 21h
71 mov handle,ax
72 mov bx,ax
73 mov ah,42h
74 mov cx, 0
75 mov al, 2
76 mov dx, 0
77 int 21h
78 mov lenth,ax
79 mov ah,42h
80 mov al, 0
81 mov cx, 0
82 mov dx, 0
83 int 21h
84 mov cx,lenth
85 mov bx,handle
86 lea dx,buf1
87 mov ah,3fh
88 int 21h
89 mov di,lenth
90 mov byte ptr buf1[di],1ah
91 mov ah,3eh
92 int 21h
93
94 lea ax,b1
95 lea bx,b2
96 sub ax,bx
97 mov lenth,ax
98 mov ah,3ch
99 lea dx,file
100 mov cx, 0
101 int 21h
102 mov handle,ax
103 mov bx,ax
104 mov cx,lenth
105 lea dx,b1
106 mov ah,40h
107 int 21h
108 mov ah,3eh
109 int 21h
110 mov ah,4ch
111 int 21h
112
113 code ends
114 end b0
115