How do I make a variable accessable by other modules?

main.asm
.data?
example dd ?


module1.asm
.code
mov example,100
Posted on 2005-07-27 02:40:12 by BBS
try this http://www.asmcommunity.net/board/index.php?topic=15097.0
Posted on 2005-07-27 04:24:27 by roticv
It depends on the order you include files. Look at one of my templates.
Attachments:
Posted on 2005-07-27 09:51:48 by JimmyClif
But, whenever I try to assemble the modules, it spits back that 'example' is undefined when assembling Module2.asm.

I tried using "PUBLIC example" before declaring example in Module1.asm, but with no luck.  Here's an example of what I tried. 

Module1.asm
.586
model flat, stdcall
option casemap :none

include Module1.inc

.data
example db "I'm public!",0

.code
entry:
  invoke Module2
  invoke ExitProcess,0
END entry


Module2.asm
.586
.model flat, stdcall  ; 32 bit memory model
option casemap :none  ; case sensitive

include windows.inc
include user32.inc
inlcudelib user32.lib

.code

Module2 proc
invoke MessageBox,NULL,addr example,NULL,MB_OK
ret

Module2 endp

end


Module1.inc
include windows.inc
include kernel32.inc
includelib kernel32.lib

Module2 PROTO
Posted on 2005-07-27 12:59:21 by BBS
Try this:

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

include windows.inc
include user32.inc
includelib user32.lib

EXTERNDEF example:byte

.code


Module2 proc
invoke MessageBox,NULL,addr example,NULL,MB_OK
ret

Module2 endp

end


...proc for function prototypes, EXTERDEF for external data :)
Posted on 2005-07-27 13:11:37 by f0dder
Thanks!!?

That was all good, but when I defined "EXTERNDEF example:BYTE" in Module2.asm and tried to assemble the modules, it spit out "unresolved external symbol _example".?

So in Module1.asm I defined "PUBLIC example" as well, and it worked perfectly.

Here's the working code.

Module1.asm
.586
model flat, stdcall
option casemap :none

include Module1.inc

.data
PUBLIC example
example db "I'm public!",0

.code
entry:
? ?invoke Module2
? ?invoke ExitProcess,0
END entry


Module2.asm
.586
.model flat, stdcall? ; 32 bit memory model
option casemap :none? ; case sensitive

include windows.inc
include user32.inc
inlcudelib user32.lib

EXTERNDEF example:BYTE

.code

Module2 proc
invoke MessageBox,NULL,addr example,NULL,MB_OK
ret

Module2 endp

end


Module1.inc
include windows.inc
include kernel32.inc
includelib kernel32.lib

Module2 PROTO
Posted on 2005-07-27 13:22:22 by BBS