News:

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

Using Full Segment Definitions

Started by AsmER, March 31, 2006, 10:10:41 PM

Previous topic - Next topic

AsmER

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?

BogdanOntanu

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
Ambition is a lame excuse for the ones not brave enough to be lazy.
http://www.oby.ro

AsmER

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?

BogdanOntanu

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)


Ambition is a lame excuse for the ones not brave enough to be lazy.
http://www.oby.ro

asmfan

use flat memory flag instead of use32 and assume cs:flat instead...
Russia is a weird place

AsmER

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.

MichaelW

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

eschew obfuscation