The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: asm_coder on April 26, 2010, 04:31:47 AM

Title: Naming variables on the stack
Post by: asm_coder on April 26, 2010, 04:31:47 AM
Hello people,

I have a question about naming initializing variables on the stack and naming it,first I know that I can create a variable on the stack using the LOCAL directive right after the procedure ,but for example what if I want to Create a variable on the stack manually and assign name for it,is that possible or every time I have to modify where it is in the stack and modify it ?I know that a name is just a label for the address,but I want to know if there is directive which could assign a name to a specific address.


Title: Re: Naming variables on the stack
Post by: dedndave on April 26, 2010, 04:47:24 AM
i prefer to do it that way too   :P
i use TEXTEQU
there are some examples in the LLKF9_1 download...

http://www.masm32.com/board/index.php?topic=12363.msg94779#msg94779

i also use TEXTEQU to rename the passed parameters
;#########################################################
;
; Stack Frame Equates
;
;#########################################################

_ModeControl  TEXTEQU <[EBP+36]> ;signed/unsigned mode control
_OutBufSize   TEXTEQU <[EBP+32]> ;output buffer size in bytes
_OutBufBase   TEXTEQU <[EBP+28]> ;output buffer base address
_InpValSize   TEXTEQU <[EBP+24]> ;input value size in bytes
_InpValBase   TEXTEQU <[EBP+20]> ;input value base address

;                      [EBP+16]   PROC return address
;                      [EBP+12]   saved ESI contents
;                      [EBP+8]    saved EDI contents
;                      [EBP+4]    saved EBX contents
;                      [EBP]      saved EBP contents

_SignXorMask  TEXTEQU <[EBP-4]>  ;sign XOR mask
_OutLastDword TEXTEQU <[EBP-8]>  ;address of last dword in output buffer
Title: Re: Naming variables on the stack
Post by: asm_coder on April 26, 2010, 05:11:34 AM
thanks for your help I didn't about that directive.
Title: Re: Naming variables on the stack
Post by: MichaelW on April 26, 2010, 05:27:57 AM
One problem with using text equates to name locals is that the equate is not local.
Title: Re: Naming variables on the stack
Post by: dedndave on April 26, 2010, 12:30:28 PM
thanks for pointing that out, Michael
that is why i use a leading underscore in the names - not that i "own" the underscore, either   :P
Title: Re: Naming variables on the stack
Post by: jj2007 on April 26, 2010, 01:01:15 PM
Quote from: MichaelW on April 26, 2010, 05:27:57 AM
One problem with using text equates to name locals is that the equate is not local.

Maybe one could overcome this restriction by turning the equates into macros, and purging those macros inside the ret macro.
Unfortunately, there seems no easy way to "purge" equates...
Title: Re: Naming variables on the stack
Post by: donkey on April 26, 2010, 01:13:03 PM
Quote from: MichaelW on April 26, 2010, 05:27:57 AM
One problem with using text equates to name locals is that the equate is not local.

Does MASM have an equivalent to GoAsm's LOCALEQU or #localdef ?
Title: Re: Naming variables on the stack
Post by: qWord on April 26, 2010, 01:51:21 PM
an other method would be to create an local stack frame:
local_vars macro locals:VARARG
LOCAL dummyProc
lv_dummyproc TEXTEQU <dummyProc>
dummyProc proc
LOCAL &locals
endm

local_end macro
leave
% lv_dummyproc endp
endm

local_vars aa:DWORD,bb[128]:BYTE
mov aa,1
mov bb[0],1
local_end

Title: Re: Naming variables on the stack
Post by: dedndave on April 26, 2010, 02:05:52 PM
for all that effort, i think i would just use [ebp-8]   :bg
Title: Re: Naming variables on the stack
Post by: MichaelW on April 26, 2010, 02:09:22 PM
Quote from: jj2007 on April 26, 2010, 01:01:15 PM
Unfortunately, there seems no easy way to "purge" equates...

That was the first thing I tried. Changing the equate to <> did not work either, I suspect because equates are somehow involved in more than one pass.