News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

SEGMENT Label is a constant?

Started by fonolite, September 03, 2010, 04:13:45 AM

Previous topic - Next topic

fonolite

TEXT SEGMENT PARA USE16 'CODE'
assume cs:TEXT

mov eax, TEXT   ; OK
mov eax, TEXT + 16  ; OK

but,

mov eax, TEXT * 16  ; Error
mov eax, TEXT SHL 4  ; Error
dd TEXT * 16  ; Error

Why isn't Segment label a normal constant?
Is it possible to handle some operators for segment label?

japheth

Quote from: fonolite on September 03, 2010, 04:13:45 AM
Why isn't Segment label a normal constant?
Is it possible to handle some operators for segment label?

because the segment is "relocatable". This means that the final value of this item isn't set by the assembler, but by the linker or program loader. Due to fixup limitations, the only arithmetic operation which is allowed for such symbols is '+'.

clive

The segment register is also only 16-bits wide, DOS will only fixup a 16-bit constant, and you are not going to be able to do flat memory accesses (ie up to 4GB, and beyond 64 KB) against [eax] even if you set DS to zero.

Microsoft (R) Macro Assembler Version 6.15.8803     09/03/10 10:21:33
test45.asm      Page 1 - 1


        .MODEL SMALL

0000         .DATA

0000 00000000 _text_flat dd ?

0000         .CODE

        .386
0000 start:

0000  66| B8 00000000 R         mov     eax,_TEXT
0006  66| C1 E0 04         shl     eax,4


000A  B8 ---- R         mov     ax,_TEXT
000D  66| 0F B7 C0         movzx   eax,ax
0011  66| C1 E0 04         shl     eax,4

0015  66| A3 0000 R         mov     _text_flat,eax


0019  B8 ---- R         mov     ax,_TEXT + 123

001C  B8 ---- R         mov     ax,_TEXT - 456

001F  C3         ret

        END     start
It could be a random act of randomness. Those happen a lot as well.

fonolite

Thanks guys.

I forgot the segment is not fixed until linking.

clive

Quote from: fonolite
I forgot the segment is not fixed until linking.

Actually it gets a little more complicated than that. The linker can deal with all the segments in an EXE, and where they fall with respect to each other, where as the loader makes the final determination about where they end up sitting in memory.
It could be a random act of randomness. Those happen a lot as well.