News:

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

Variable names from with #asm

Started by V Coder, October 03, 2005, 05:32:54 PM

Previous topic - Next topic

V Coder

When incorporating non-HLA code, I sometimes use #asm ... #endasm blocks with the code simply copied. Unfortunately, I cannot access HLA variables from within the "MASM" sections noting know the compile time variable name, so I have to use broken blocks, with repeated #asm...#endasm

Is it possible to access HLA variables from within the #asm block without having to switch back out frequently? Thanks.

Sevag.K

You have to declare them @external


program testvar;
#include ("w.hhf")
static
stext :string; @external;
stext :string := "Test string";
caption :string; @external;
caption :string := "Test Message Box";
endstatic;
begin testvar;

#asm
; fasm syntax, masm may vary
push dword 0
push [caption]
push [stext]
push dword 0
call dword [__imp__MessageBoxA@16]
#endasm;

end testvar;


edit: some more info on the @external.

Using @external forces HLA to use the supplied variable name as-is.

These 2 lines force "variable" to be a global label
variable : dword; @external
variable :dword;

You can also supply your own "global" label (in case of any conflicts).
The following line forces "__variable4__" as a global label representing "variable"
variable: dword; @external ("__variable4__");
variable: dword;

V Coder

Please illustrate further, eg. variable testflag, apart from Windows external.

Thanks

Sevag.K

Well, in the example above, the 'stext' and 'caption' varaibles are "local" labels forced as @external so that the low level assembler can recognize them.

Here's another example:
Suppose you want a static variable called "testflag" (size dword) to be visible both in HLA and MASM (.data section).


static

// define the label as MASM will see it
testflag :dword; @external;

// allocate storage for this label
// so that both HLA and MASM can access it
testflag :dword;

endstatic;

...  in your program:

#asm
; fasm syntax
mov eax, testflag ; load eax with address of testflag
mov ebx, [testflag] ; load ebx with value of testflag
#endasm;

I believe in MASM that would be...
#asm
; masm syntax... not sure if correct
mov eax, addr testflag
mov ebx, testflag
#endasm;


If you have multiple units, it's best to put all the @external declarations in a common header file.


The same is true for any arbitrary label in your program:


program testlabel;
#include ("stdlib.hhf")

// define an external label that the low level assembler can access
label jumpTo; @external;

begin testlabel;

#asm
jmp jumpTo
#endasm;


hereTo:
stdout.put ("you'll never see me",nl);

jumpTo:
stdout.put ("you'll see me", nl);



end testlabel;


Randall Hyde

Quote from: V Coder on October 03, 2005, 05:32:54 PM
When incorporating non-HLA code, I sometimes use #asm ... #endasm blocks with the code simply copied. Unfortunately, I cannot access HLA variables from within the "MASM" sections noting know the compile time variable name, so I have to use broken blocks, with repeated #asm...#endasm

Is it possible to access HLA variables from within the #asm block without having to switch back out frequently? Thanks.

Yes, though it's ugly. See the following link:
http://webster.cs.ucr.edu/AsmTools/HLA/HLADoc/HLARef/HLARef15.html#1028044

Cheers,
Randy Hyde