Simplified Assembly section definition

Source: Internet
Author: User

  1. Storage Model pseudoinstructions

Table 4.2.3 storage models supported by MASM 5.0 and MASM 6.0:

Storage Model Merit Applicable Operating Systems
Tiny(Micro) All data and code are placed in a single segment, and the access is in the near type. The entire program is less than or equal to 64 KB and A. com file is generated. MS-DOS
Small(Small) All codes are in one 64 kB segment, and all data is in another 64 kB segment (including the data segment, stack segment, and additional segment ). MS-DOS
Windows
Medium(Medium) All codes> 64 K can be placed in multiple code segments, and transfer or call can be far type. All data is limited to one segment, and DS remains unchanged. MS-DOS
Windows
Compact(COMPACT) All Code is limited to one segment, and the transfer or call can be of the near type. DATA> 64 K can be placed in multiple segments. MS-DOS
Windows
Large(Large) The code segment and Data Segment can both exceed 64 KB and are placed in multiple segments. Therefore, both data and code are remotely accessed. MS-DOS
Windows
Huge(Giant) A single data item can be larger than 64 KB, and other data items are the same as those in the large model. MS-DOS
Windows
Flat(Flat type) All code and data are stored in one segment, but the segment address is 32 bits, so the entire program can be 4 GB. This model is supported by MASM 6.0. OS/2
WindowsNT
Note:The small model is the most common model for applications. Because there is only one code segment and one data segment, data and code are both near-accessed. The data segment of this model refers to the sum of the Data Segment, stack segment, and additional segment.

When programming in an assembly language in DOS, you can select the first six models based on different features of the program. Generally, you can select the small model. In addition, the tiny model will generate com programs, while other models will generate EXE programs. The flat model can only run on a 32-bit x86 CPU. This model is not allowed in DOS. When mixed programming with advanced languages, the two storage models should be consistent.

2. Simplified segment pseudoinstructions

Table 4.2.4 the format of the simplified section pseudo commands is as follows:

Simplify segment pseudocommands Merit Note
. Code[Segment name] Create a code snippet The segment name is optional. If the segment name is not provided, the default segment name is used. For models of multiple code segments, you must specify the segment name for each code segment.
. Data Create a Data Segment Segment name: _ DATA
. Data? Create a data segment without an initial value variable Segment name: _ BSS
. Fardata[Segment name] Create a remote call data segment with an initial value You can specify the segment name. If this parameter is not specified, it will be named in far_data.
. Fardata?[Segment name] Create a remote call data segment without an initial value You can specify the segment name. If this parameter is not specified, it will be named in far_bss.
. Const Create a read-only constant data segment Segment name: const
. Stack[Size] Create a stack segment and specify the size of the stack segment Segment name: Stack. If the size of the stack segment is not specified, the default value is 1 kb.


3. pre-defined symbols related to the definition of simplified segments

The following example describes how to use predefined symbols. In the case of complete segment definition, at the beginning of the program, you need to use the segment name to load the data segment register, such as in example 4.1
MoV ax, data_seg1
MoV ds, ax
If you use a simplified segment definition, only. Data is used to define the data segment, but no segment name is provided.
MoV ax, @ data
MoV ds, ax
Here, the pre-defined symbol @ data gives the segment name of the Data Segment.

  4. Simplified section definition example
  
Example 4.3
. Model small
. Stack 100 h; Define the stack segment and its size
. Data; define data segments
       .
.
.

. Code; defines the code segment
Start:; start execution address number
MoV ax, @ data; data segment address
MoV ds, ax; store data segment registers
.
.
.

MoV ax, 4c00h
Int 21 h
End start; end of the program

From example 4.3, we can see that the simplified segment definition is much simpler than the complete segment definition. However, because the complete segment definition can fully describe the various types and attributes of the segment, you still need to use it in many cases.

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.