News:

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

Public values

Started by ecube, November 08, 2006, 09:13:40 PM

Previous topic - Next topic

ecube

I wrote a big project in masm and broke up the code into various .asm files. I want them all to use values from config.asm but my question is, is there a way to have say files.asm use only 1 or 2 values from config.asm without including the entire file and all other values? Don't want to have to include config.asm in each and every file file, seems redundant to me.

ramguru

When you use macros.asm do you think all the file is included in final exe  :naughty: , the same case here... However, you need only include that config.asm (everything) once in your main asm.

asm_main.asm
-----
.386
.model flat, stdcall
option casemap :none

include config.asm
include |many_files...|
....
-----

Other files (*.inc; *.asm) should begin by words: .DATA; .CODE. Not .386 again

ecube

Yeah I see that, not sure what my problem was before, but alright thanks.

Relvinian

Quote from: E^cube on November 08, 2006, 09:13:40 PM
I wrote a big project in masm and broke up the code into various .asm files. I want them all to use values from config.asm but my question is, is there a way to have say files.asm use only 1 or 2 values from config.asm without including the entire file and all other values? Don't want to have to include config.asm in each and every file file, seems redundant to me.

E^cube,

Along with what ramguru wrote, you can do the following which helps with multiple .asm files and keeping some things "hidden". Below is an example of three .asm files using   a variable declared in the first and used in all three .asm files.


; ======================================
; ASM file #1
; ======================================
.486
.model flat, stdcall

option readonly
option casemap:none

include windows.inc
includelib kernel32.lib


; declare the variable
.data
   hProcessHeap dd 0

; make the variable available to other modules
public hProcessHeap

GetHeapID proc
    invoke GetProcessHeap
    mov [hProcessHeap], eax
    ret
GetHeapID endp

END


; ======================================
; ASM file #2
; ======================================
.486
.model flat, stdcall

option readonly
option casemap:none

include windows.inc
includelib kernel32.lib


; this variable are declared in another module but referenced in this one
extern hProcessHeap:near


AllocMemory proc nBlocksize:dword
    mov ecx, [nBlockSize]           ; allocation size
    mov edx, [hProcessHeap]      ; get the address (offset) of the variable

    ; parameters to HeapAlloc
    ; [edx]  = value stored in hProcessHeap variable --- hProcessHeap itself is just
                   the address of the variable -- need to de-reference
    ; HEAP_ZERO_MEMORY  = make all allocated memory zeroed during the call.
    ; ecx = size of memory block to allocate
    invoke HeapAlloc, [edx], HEAP_ZERO_MEMORY, ecx
    ret
AllocMemory endp

END


; ======================================
; ASM file #3
; ======================================
.486
.model flat, stdcall

option readonly
option casemap:none

include windows.inc
includelib kernel32.lib


; this variable are declared in another module but referenced in this one
extern hProcessHeap:near


FreeMemory proc pMemory:dword
    mov ecx, [pMemory]            ; allocated memory pointer from HeapAlloc
    mov edx, [hProcessHeap]     ; get the address (offset) of the variable

    ; parameters to HeapFree
    ; ecx     = address of memory block to free
    ; [edx]  = value stored in hProcessHeap variable --- hProcessHeap itself is just
                   the address of the variable -- need to de-reference
    invoke HeapAlloc, [edx], 0, ecx
    ret
FreeMemory endp

END


Hope this helps.


Attached is a .zip file with three .asm files that I have written for my own ASM needs that fully expands on these three examples I have shown you. Feel free to take a look.

Relvinian


[attachment deleted by admin]

ecube

Fantastic Relvinian, thankyou.

sinsi

You could also use EXTERNDEF - this acts as PUBLIC in the file it is defined in and EXTERN in a file that uses it
but doesn't define it (although this is of more use with seperate .OBJ files when linking). Make a common include file,
define all your shared stuff and include it in all of your .ASM files - if a module doesn't reference an EXTERNDEF, it is ignored.
Light travels faster than sound, that's why some people seem bright until you hear them.