Effect of the FLAT operand on the SEGMENT directive?

MASM provides the SEGMENT directive. The directive takes several parameters. The parameter usecan take a value FLAT. I don’t understand what this meaning is.

Microsoft docs indicate it as an accepted value, but don't try to describe it:

use
USE16 , USE32 , FLAT

The book "The Art of Assembly Language Programming" is mentioned on the Internet, but is called from the scope and recommends reading the MASM programmer’s manual:

The operands use32also FLATtell MASM to generate code for the 32-bit segment. Since this text does not apply to programming with protected mode, we will not consider these parameters. See the MASM Programmer's Guide for more information.

The Microsoft MASM 6.1 Programmer's Guide, in the section describing the directive SEGMENT, indicates the value FLAT, but its effects are never described:

The size attribute can be USE16 , USE32, or FLAT .

What are the effects of the FLAT operand in the SEGMENT directive?

+4
source share
1 answer

FLAT , USE32. USE32 FLAT , 64 , , , 32- , 16- . , CS. SEGMENT ASSUME CS:xxx, xxx - , FLAT ASSUME CS:FLAT.

ASSUME , , , . , 32- , 4 . , , FLAT , , , . , ASSUME DS:FLAT , DS. , ASSUME DS:_DATA , DS _DATA, .

, :

_DATA   SEGMENT PUBLIC USE32
var DD  ?
_DATA   ENDS

_TEXT   SEGMENT PUBLIC PARA 'CODE' FLAT

    mov eax, [zero]
    mov [var],eax 

    ASSUME  DS:FLAT

    mov eax, [zero]
    mov [var],eax 

    ASSUME  CS:_TEXT  
    ASSUME  DS:_DATA

    mov eax, [zero]
    mov [var],eax 

zero    DD  0

_TEXT   ENDS

    END

, :

  00000000: 2E A1 00 00 00 00  mov         eax,dword ptr cs:[zero]
  00000006: 2E A3 00 00 00 00  mov         dword ptr cs:[var],eax

CS (2E), zero var. , , , CS , _TEXT _DATA, , .

, , ASSUME DS:_FLAT:

  0000000C: A1 00 00 00 00     mov         eax,dword ptr [zero]
  00000011: A3 00 00 00 00     mov         dword ptr [var],eax

, CS, DS . DS zero var , DS CS, .

, , ASSUME DS:_DATA ASSUME CS:_TEXT, , , FLAT :

  00000016: 2E A1 00 00 00 00  mov         eax,dword ptr cs:[zero]
  0000001C: A3 00 00 00 00     mov         dword ptr [var],eax

, CS _TEXT DS _DATA. zero CS, var DS, .

, FLAT USE32 SEGMENT , CS, :

error A2074:cannot access label through segment registers

, , , _TEXT CS, - , _DATA.

.MODEL FLAT , . USE32 FLAT , FLAT.

+4

Source: https://habr.com/ru/post/1681539/


All Articles