The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: AsmER on March 31, 2006, 10:10:41 PM

Title: Using Full Segment Definitions
Post by: AsmER on March 31, 2006, 10:10:41 PM
Hi everybody,

Maybe it is stiupid maybe no, but if MASM have this option, why I shouldn't know how to use it :toothy.
I always using .DATA, .CODE etc. segment definitions, but I'd like know how to do it by using full definitions.
I know it should looks like:
name SEGMENT [[align]] [[READONLY]] [[combine]] [[use]] [['class']] ;i read it in MASM guide for v. 6.1

I tried do it myself, but I got error messages from MASM, which says :

Microsoft (R) Macro Assembler Version 6.14.8444
Copyright (C) Microsoft Corp 1981-1997.  All rights reserved.

Assembling: test.asm
test.asm(11) : error A2015: segment attributes cannot change : Alignment
test.asm(13) : error A2006: undefined symbol : T
test.asm(13) : error A2114: INVOKE argument type mismatch : argument : 3
test.asm(13) : error A2006: undefined symbol : TXT
test.asm(13) : error A2114: INVOKE argument type mismatch : argument : 2

And my code:
.386
.MODEL  FLAT, stdcall
OPTION CASEMAP:none

include \masm32\include\windows.inc
include  \masm32\include\kernel32.inc
include  \masm32\include\user32.inc
includelib  \masm32\lib\kernel32.lib
includelib  \masm32\lib\user32.lib

_TEXT SEGMENT WORD PUBLIC 'CODE'
start:
        invoke  MessageBox, 0, ADDR TXT, ADDR T, MB_OK
        invoke  ExitProcess, 0h
_TEXT ENDS

_DATA SEGMENT WORD PUBLIC 'DATA'
TXT     DB      'MY TXT',0
T       DB      'HELLO',0
_DATA ENDS

STACK SEGMENT PARA STACK 'STACK'
db      100h dup(?)
STACK ENDS
END start


Could somebody tell me what I doing wrong?
Title: Re: Using Full Segment Definitions
Post by: BogdanOntanu on March 31, 2006, 10:20:25 PM
No need to double post :D

Well the directive: .MODEL FLAT, STDCALL
already defines some simple memory model that is incompatible with defining other SEGMENTS
So you will have to remove that...

Also  other includes might not be compatile with this segments memory model...

When you do a "test" work bench do it as simple as possible... remove everything not needed for the testing and i mean everything :D

be prepared to "drop" any invokke and many macros also

A corect segment declaration is like this (from SolarOS):

code32 SEGMENT use32 'CODE'   
   assume cs:code32,ds:code32,es:code32,ss:code32


code32 ENDS
Title: Re: Using Full Segment Definitions
Post by: AsmER on March 31, 2006, 10:30:06 PM
QuoteNo need to double post :D
I agree. I don't know why there are two copies of my subject (I already asked huth-- if he can delete one of them.)
-So I should delete .model directive, and use use32 to create 32 bit segments, yes?
Title: Re: Using Full Segment Definitions
Post by: BogdanOntanu on April 01, 2006, 02:32:33 AM
Theoretically yes...

And you should align at PARA or DWORD not WORD

Besides it is possible that you will need another linker also ;) (if that assembles)


Title: Re: Using Full Segment Definitions
Post by: asmfan on April 01, 2006, 04:38:18 AM
use flat memory flag instead of use32 and assume cs:flat instead...
Title: Re: Using Full Segment Definitions
Post by: AsmER on April 07, 2006, 09:13:05 AM
All right, it works.


.386
.MODEL  FLAT, stdcall
OPTION CASEMAP:none

include \masm32\include\windows.inc
include  \masm32\include\kernel32.inc
include  \masm32\include\user32.inc
includelib  \masm32\lib\kernel32.lib
includelib  \masm32\lib\user32.lib

_stack segment word stack 'stack'
db 100h dup(?)
_stack ends

_data segment word public 'data'
txt db "I'did it...",0
capt db "It works",0
_data ends

_code segment word readonly public flat 'code'
assume ds:_data,ss:_stack
start:
invoke MessageBox, 0, addr txt, addr capt, MB_OK or MB_ICONINFORMATION
invoke ExitProcess, 0
_code ends

END start


-work correct with link.exe :toothy
I put it here, because maybe it can help somebody else.
Title: Re: Using Full Segment Definitions
Post by: MichaelW on April 07, 2006, 10:11:10 AM
These are the segment and related definitions generated by the Microsoft Visual C++ Toolkit 2003 compiler (no stack segment definition present in listing):

if @Version gt 510
.model FLAT
else
_TEXT SEGMENT PARA USE32 PUBLIC 'CODE'
_TEXT ENDS
_DATA SEGMENT DWORD USE32 PUBLIC 'DATA'
_DATA ENDS
CONST SEGMENT DWORD USE32 PUBLIC 'CONST'
CONST ENDS
_BSS SEGMENT DWORD USE32 PUBLIC 'BSS'
_BSS ENDS
$$SYMBOLS SEGMENT BYTE USE32 'DEBSYM'
$$SYMBOLS ENDS
_TLS SEGMENT DWORD USE32 PUBLIC 'TLS'
_TLS ENDS
FLAT GROUP _DATA, CONST, _BSS
ASSUME CS: FLAT, DS: FLAT, SS: FLAT
endif