The MASM Forum

General => The Workshop => Topic started by: jacklack on January 15, 2015, 04:18:53 AM

Title: Get globals, instructions and function addresses at assembly time.
Post by: jacklack on January 15, 2015, 04:18:53 AM
In the process of writing a debugger for a custom language, I would like to know how to get global variables addresses, functions addresses and instructions addresses at assembly time.

I would like to write this addresses along with other debugging symbols to a debug file. (That I will use later to use for debugging, much like the pdb files generated by c/c++).
I think Masm fixes the address for code and globals at assembly time and would like to know how to get them?

Thanks in advance;
Title: Re: Get globals, instructions and function addresses at assembly time.
Post by: dedndave on January 15, 2015, 04:23:56 AM
    .data?

dwSomeVar dd ?

    .code

SomeProc PROC
;
    ret
SomeProc ENDP

;to get addresses....

    mov     edx,offset dwSomeVar  ;EDX = address of dwSomeVar
    mov     ecx,SomeProc          ;ECX = address of SomeProc ("offset" not needed for code)
Title: Re: Get globals, instructions and function addresses at assembly time.
Post by: jacklack on January 15, 2015, 04:30:02 AM
Thank you, but I would like to know theses address at assembly time, not when executing the program (runtime).
That is when Masm is assembling assembly files, he is assigning addresses to globals and instructions, I would like to know those addresses, and match each global, function or instruction to it's address.
Title: Re: Get globals, instructions and function addresses at assembly time.
Post by: dedndave on January 15, 2015, 04:36:32 AM
duh - my mistake - i didn't read carefully (first cup of coffee, here)

as far as i know, the assembler makes at least 2 passes
addresses may not be known in pass 1 that are in pass 2

refer to the MASM manual for some conditionals related to assembler passes
Title: Re: Get globals, instructions and function addresses at assembly time.
Post by: jacklack on January 15, 2015, 05:09:44 AM
Thank you dedndave.
Searching for masm and assembly passes, I found that masm generates a listing for all the symbols and include even code addresses and instruction hex in the .lst file.
Just opened my generated lst, looks like everything I need is there.
That is really all need. Just great!