EXE format file under DOS

Source: Internet
Author: User
Tags reserved

Generate EXE Format file

; Model pseudo-operation format: Model Memory_mode,model_options
of which: memory can be tiny/small/medium/compact/large/huge/flat, etc.
Except tiny compiled into COM format file, the other is exe format file
Small is one of the more commonly used, so this explains small
For small, all data is placed in a 64K segment, all code is placed in another 64K segment, data and code are near access.
--------------------------------------------------------------------
, Example: Display a string
; file name: 2.asm, build the file 2.exe after compiling the link

. model small; EXE format file generation

. stack 100h; without 100h, the default stack size is 400H

. data, initialized segments
Mess db ' How, world!$ '

. data?; uninitialized segments, which do not occupy the size of the EXE file!
PP Dw 200H DUP (?); for uninitialized data, only use "? ”

. Code Snippets

. startup; You can use this pseudo-directive to initialize DS and stack values (examples following the parameters)
MOV ah,9
Lea Dx,mess
int 21h; display information
MOV Pp,ax
. exit; You can set the return code
Use. startup, so don't point out where the program started!
---------------------------------------------------------------
The detailed procedure for generating 2.exe files:

D:\masm615>dir 2

Volume in Drive D has no label
Volume Serial number is 18f0-186b
Directory of D:\Masm615

2 ASM 711 02-15-03 10:48 2.asm
1 file (s) 711 bytes
0 dir (s) 2,408,906,752 bytes free

D:\MASM615>ML 2.asm
Microsoft (R) Macro assembler Version 6.15.8803
Patched for your by Promethee [ECL] in the year 2001-enjoy
Copyright (C) Microsoft Corp. 1981-2000. All rights reserved.

Assembling:2.asm

Microsoft (R) segmented executable Linker Version 5.60.339 Dec 5 1994
Copyright (C) Microsoft Corp. 1984-1993. All rights reserved.

Object Modules [. obj]: 2.obj
Run File [2.exe]: "2.exe"
List File [Nul.map]: nul
libraries [. Lib]:
Definitions File [Nul.def]:

D:\masm615>dir 2

Volume in Drive D has no label
Volume Serial number is 18f0-186b
Directory of D:\Masm615

2 ASM 711 02-15-03 10:48 2.asm
2 OBJ 207 02-15-03 10:50 2.obj
2 EXE 562 02-15-03 10:50 2.exe
3 file (s) 1,480 bytes
0 dir (s) 2,408,910,848 bytes free

D:\masm615>2
How, world!
D:\masm615>_
_______________________________________________________________
To view the generated EXE file with debug

-R
ax=0000 bx=0000 cx=0032 dx=0000 sp=0100 bp=0000 si=0000 di=0000
ds=128c es=128c ss=12a0 cs=129c ip=0000 NV up EI PL NZ NA PO NC
129c:0000 ba9e12 MOV dx,129e
-u0 25
129c:0000 ba9e12 MOV dx,129e; This is translated by the. Startup pseudo instruction.
129c:0003 8EDA MOV ds,dx; Set data segments (initialization and uninitialized data have the same segment value)
129c:0005 8CD3 MOV Bx,ss
129c:0007 2BDA SUB BX,DX
129c:0009 d1e3 SHL bx,1
129c:000b d1e3 SHL bx,1
129c:000d d1e3 SHL bx,1
129c:000f d1e3 SHL bx,1
129c:0011 FA CLI
129c:0012 8ed2 MOV ss,dx; reset Stack
129c:0014 03E3 ADD sp,bx; So, Ds=ss
129c:0016 FB STI
129c:0017 B409 MOV ah,09; Here we start with the program we wrote.
129c:0019 8d160600 LEA dx,[0006]; for small, the location type of the data is word, which must be an even number, such as 6
129c:001d CD21 INT 21
129c:001f A32001 MOV [0120],ax; uninitialized data is located behind the code \ Data \ Stack
129c:0022 b44c MOV ah,4c
129c:0024 CD21 INT 21
-d129e:6 11
129e:0000 6f-77 2C 6F A 6C of the world
129e:0010 21 24!$
-g17

ax=0000 bx=0020 cx=0032 dx=129e sp=0120 bp=0000 si=0000 di=0000
ds=129e es=128c ss=129e cs=129c ip=0017 NV up EI PL NZ NA PO NC
129c:0017 B409 MOV ah,09
---------------------------------------------------
At this point you can look at the layout of the program in store, in order to deepen understanding!

Note: The original stack ss:sp=12a0:0100 and the new stack 129e:0120 are the same!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.