ok, I think I got it now :) finally

Here is a little test program I was messing with

.386
.model flat, stdcall
option casemap:none

include C:\masm32\include\windows.inc
include C:\masm32\include\user32.inc
include C:\masm32\include\masm32.inc
includelib C:\masm32\lib\user32.lib
includelib C:\masm32\lib\kernel32.lib

includelib C:\masm32\lib\masm32.lib

main PROTO

.data

.code
start:
invoke main
ret

anotherProc proc
.data
externdef szText:byte
.code
invoke MessageBox, NULL, offset szText, offset szText, MB_OK
ret
anotherProc endp


main proc
.data
szText db "This is a test", 0
.code
invoke MessageBox, NULL, offset szText, offset szText, MB_OK
invoke anotherProc
ret
main endp


end start


I couldn't access szText in 'anotherProc' .... my bad... once I used externdef, I could. <-Lesson learned, I don't want szText to be global :)

But what do u mean that proc's don't have sections? How can I .data and .code above?

Thanks again for any help,
a slow lumbering stupid troll - gorshing
Posted on 2002-06-26 13:29:20 by gorshing
This is an assembler limitation, i believe. If you have coded in HLL remember the word scope? When the assembler tokenizes your code, it will tokenize from top to bottom meaning it will tokenize first "anotherproc" before it arrives to mainproc. So when it tokenizes szText in "anotherproc" it will then hash that token and checks if such hash value exists on the hash table(on the assembler), since the declaration of szText is after "anotherproc" it will then produce an error/undefined variable or something like this. If you put "anotherproc" after mainproc you have to create a prototype for "anotherproc" since mainproc calls anotherproc before it leaves(ret) and doesn't have scoped with "anotherproc". Try this one
.386 

.model flat, stdcall
option casemap:none

include C:\masm32\include\windows.inc
include C:\masm32\include\user32.inc
include C:\masm32\include\masm32.inc
includelib C:\masm32\lib\user32.lib
includelib C:\masm32\lib\kernel32.lib

includelib C:\masm32\lib\masm32.lib

main PROTO
anotherProc PROTO

.code
start:
invoke main
ret

main proc
.data
szText db "This is a test", 0
.code
invoke MessageBox, NULL, offset szText, offset szText, MB_OK
invoke anotherProc
ret
main endp

anotherProc proc
invoke MessageBox, NULL, offset szText, offset szText, MB_OK
ret
anotherProc endp end start
When you declare something like this


.data
szText db "This is a test", 0
.code
szText during the assembling stage will go to the .data section. And no this is not a local variable just because you declared it inside a procedure.

Forget about tokenizing, I was just explaining some parts on how the assembler was doing to your code and why it didn't recognize szText as global(until you declared externdef).
Posted on 2002-06-26 13:55:30 by stryker