The Assembly Programming Master Book
| ||
| ||
|
Both MASM and TASM support so-called simplified segmentation. I am backing the classical structure of an Assembly language program. However, I must admit that simplified segmentation is a convenient method, especially when programming for Windows.
The main idea of simplified segmentation is as follows : The starting point of the code segment is determined by the .CODE directive, and the .DATA directive [iii] specifies the starting point of the data segment. Both directives can occur several times in the source code of the program. The translator then assembles the code and data together as appropriate. The main goal of such an approach is the possibility of placing the data in the source code of the program as close as possible to the lines of code that use them. Such a possibility was in due time implemented in C++. In my opinion, it results in inconvenience when reading the code. Furthermore, although I don't pretend to be an aesthete, I don't feel comfortable when I see data mixed with the code.
Listing 1.9 illustrates the use of the simplified segmentation mode.
Listing 1.9: A program that uses simplified segmentation
|
.586P ; Flat memory model .MODEL FLAT, STDCALL ;------------------------------------------ ; Data segment .DATA SUM DWORD 0 ; Code segment .CODE START: ; Data segment . DATA A DWORD 100 ; Code segment . CODE MOV EAX, A ; Data segment . DATA B DWORD 200 ; Code segment .CODE ADD EAX, B MOV SUM, EAX RET ; Exit END START.
|
Note | Commands such as .DATA and .CODE can be used within the code segment defined in a traditional way. This is convenient for creating useful macro definitions (these will be covered in more detail in Chapter 12). |
[iii] There also is a special directive for the stack namely, the .STACK directive. However, I will use it rarely.
| ||
| ||
|