I am trying to organize my code into multiple asm files that are connected through a inc file.

I already know that to create a variable I can use externdef in the inc file and define the variable in one of the asm files.

However, is there any way to define the variable directly in the inc file?? I tried that and each asm file creates its own copy of the variables. Is there any way to tell the assembler that the .data section in the inc file should be "global" and should be created only once?
Posted on 2002-03-13 14:09:46 by Hel
However, is there any way to define the variable directly in the inc file?? I tried that and each asm file creates its own copy of the variables. Is there any way to tell the assembler that the .data section in the inc file should be "global" and should be created only once?
One way for a separate .inc file whose data are to be declared as global is to change how you declare your segments.



.586
OPTION SCOPED
OPTION CASEMAP:NONE
OPTION LANGUAGE:STDCALL

_TEXT SEGMENT READONLY PAGE PUBLIC USE32 'CODE'
_TEXT ENDS
_DATA SEGMENT PAGE PUBLIC USE32 'DATA'
_DATA ENDS
CONST SEGMENT READONLY PUBLIC USE32 'CONST'
CONST ENDS
_BSS SEGMENT PAGE PUBLIC USE32 "BSS"
_BSS ENDS

ASSUME CS:FLAT, DS:FLAT, SS:FLAT, ES:FLAT

;Include and Includelibs here

You can declare like this on any asm/inc file:


_DATA SEGMENT
Data1 DD 0FFh
Data2 DD 0FFFFFFFFh
_DATA ENDS

This will now be a part of the chunk of global variables. Just be careful where you place these declarations. Since order matters here. You can download examples from here 1 or 2 and play with it for awhile.

Check out the MASM manual, it'll explain more of this.
Posted on 2002-03-13 14:39:35 by stryker
i'm currently had to split my project too.
I'm using other method than stryker
described above.




.586
.model flat, stdcall
option casemap :none ; case sensitive

; #########################################################################

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

includelib \masm32\lib\user32.lib
includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\masm32.lib


; #########################################################################


FILE_NAME_BUFFER equ 256 ; how big is that buffer
LSTRING_BUFFER_SIZE equ 256 ; how big are local string buffers
STRING_BUFFER_SIZE equ 1024 ; how big is the main string buffer

;include your files here
include file1.asm
; etc...


this is the fragment out of the main ASM file.
the files included simply contain the keywords

.data or .code

off course you can use equates as well and all
other stuff.

Example: file1.asm




RGB_white equ 0ffffffh

.data
myRGB dd 0

.data?
yourRGB dd ?


.code

getRGB proc
mov myRGB, eax
ret
getRGB endp


setRGB proc rgb:DWORD
mov eax, rgb
mov yourRGB, eax
ret
setRGB endp

Posted on 2002-03-13 15:06:03 by marsface