The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: asmftw on September 08, 2008, 10:27:06 PM

Title: Controlling Section Attributes?
Post by: asmftw on September 08, 2008, 10:27:06 PM
How can I control section attributes in masm32 like in fasm:

section ".data" data readable writeable executable
section ".text" code readable writeable executable


I just want one section with .data and .text, but I want .text to come before .data, which I don't think you can do in link.exe or polink.exe.
Title: Re: Controlling Section Attributes?
Post by: FORTRANS on September 09, 2008, 06:31:06 PM
Hello,

   This is from memory, and older versions of LINK (6.0 and
earlier).

   If you use the .model and .data simplified directives, you
cannot specify an order.

   If you use the older directives SEGMENT, ASSUME, and the
like you can specify the order.  This is the relevant code from
my heapsort programs that I attached to my introductory
posting to the group.

        PAGE ,132
        TITLE HeapSort Testing
        NAME HEAP

; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
; Set up the code definitions the operating system wants.  Stack segment:
STCKSG  SEGMENT STACK
        ASSUME  SS:STCKSG, CS:CODE
        DB      64 DUP('STACK   ')      ; Stack area, and filler (512 Bytes)
STCKSG  ENDS

; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
BIOSSEG SEGMENT AT 40H  ; BIOS Data area
        ORG    6CH
ClockTic LABEL DWORD    ; 55 ms timer ticks since CPU reset
BIOSSEG ENDS

; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
; Set up the code definitions the operating system wants.  Data segment:
DATASG  SEGMENT PUBLIC
        ASSUME  DS:DATASG, SS:STCKSG, CS:CODE

; Data area
; Deleted

; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
; Set up the code definitions the operating system wants.  Code segment:
CODE    SEGMENT PUBLIC
        ASSUME  CS:CODE,DS:DATASG,ES:DATASG,SS:STCKSG

START   PROC FAR        ; PROC needed for RET typing {OBE}
        MOV     AX,SEG DATASG
        MOV     DS,AX

;Code deleted.

START   ENDP

;Code deleted.

; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
CODE    ENDS
        END     START


   If you download my program and look at it in a hex editor,
you will see that the Stack Segment is at the front of the
EXE, followed by the Data Section, and then the Code Section.
If you use the simplified directives, the code comes first.  And
this is 16-bit code, though I think 32-bit makes little difference
to the linker's actions.  Somewhere around MASM 6.1, they
changed the linker so it could not make OS/2 programs.

HTH,

Steve N.

Title: Re: Controlling Section Attributes?
Post by: Vortex on September 09, 2008, 07:51:34 PM
Try link -edit or editbin :

usage: EDITBIN [options] [files]

   options:
.
.
.
/SECTION:name[=newname][,[[!]{cdeikomprsuw}][a{1248ptsx}]]
.
.
.