News:

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

Way to Reference an offset through a name

Started by AgentSmithers, July 04, 2009, 09:29:29 PM

Previous topic - Next topic

AgentSmithers

mytest db "Hello World" db 5 <0>

Something like this would have a byte array like "Helloworld<0><0><0><0><0>"


But is their a way to reference a offset in mytest through a variable name without using any + signs

mytest db "Hello World",
MytestOffset11 db 5 <0>

or is above the best way so i can reference it after hello world so when i print it out or pass it through a function I can just pass mytest for the complete string or mytestOffset11 for just whats after it.

EDIT: to create a local var we use LOCAL MYVAR:DWORD

How would I put Hello world in a Local in the Declare statment

Somehting like LOCAL MYstr:Byte "Helloworld"

??

Thanks!
-Agent

Jimg

Yes, you can put a label anywhere like

mytest db "Hello World"
MyTestOffset11 db 5 dup 0


but you can't initialize a local in a proc because the local can be anywhere in the stack at run time.  You can manually put the string in a local each time the proc is called, but that doesn't save anything, in fact it uses much more memory-

testmy proc
local MYstr[11]:byte

lea edi,MYstr
mov al,"H"     ; just one of hundreds of ways to store a character
stosb
mov al,"e"
stosb
... etc.


AgentSmithers

Well I got a Global Var and  local var I want to copy into it

Will something like this work??

            mov ECX, LENGTHOF GlobalVar

                lea edi, LocalVar
                mov esi, OFFSET GlobalVar
            LoadMyString:
                mov edi, [esi]
                inc edi
                inc esi
            loop LoadMyString

dedndave

no
you are using the EDI register for two different things

        mov     esi,offset GlobalVar
        lea     edi,LocalVar
        mov     ecx,sizeof GlobalVar
        cld
        rep     movsb


Vortex

Hi AgentSmithers,

You should also preserve esi,edi,ebx,esp and ebp if you are going to modify them.