Borland x86 inlined assembler; get a label's address?

前端 未结 12 864
清酒与你
清酒与你 2021-01-05 03:15

I am using Borland Turbo C++ with some inlined assembler code, so presumably Turbo Assembler (TASM) style assembly code. I wish to do the following:

void foo         


        
相关标签:
12条回答
  • 2021-01-05 03:51

    I think the problem you're running into is that a label inside the __asm block and the label in the C++ code are two completely different things. I wouldn't expect that you could reference a C++ label in that way from inline assembly, but I must say it's been a very long time since I've used Turbo C++.

    Have you tried the lea instruction instead of mov?

    0 讨论(0)
  • 2021-01-05 03:51

    This is a variant of Ivan's suggestion but give this a try:

    void foo::bar( void )
    {
        __asm
        {
          mov eax, offset SomeLabel
          // ...
        }
        // ...
        __asm SomeLabel:
        // ...
    }
    
    0 讨论(0)
  • 2021-01-05 03:53

    I don't know about your compiler / assembler specifically, but a trick I've used quite a bit is to call the next location and then pop the stack into your register. Be certain the call you make only pushes the return address.

    0 讨论(0)
  • 2021-01-05 03:54

    Just guessing since I haven't used inline assembler with any C/++ compiler...

    void foo::bar( void )
    {
        __asm
        {
          mov eax, SomeLabel
          // ...
        }
        // ...
        __asm
        {
          SomeLabel:
          // ...
        }
        // ...
    }
    

    I don't know the exact syntax of TASM.

    0 讨论(0)
  • 2021-01-05 03:59

    one of the options would be to use separate "naked" (prolog-less) procedure SomeLabel instead of label

    0 讨论(0)
  • 2021-01-05 04:03

    Does the Turbo C++ environment have a way to set options for TASM (I know that some of the Borland IDEs did)?

    If so, see if changing the option for "Maximum passes (/m)" to 2 or more helps (it might default to 1 pass).

    Also, if you're using a long label name that might pose a problem - at least one IDE had the default set to 12. Change the "Maximum symbol length (/mv) option".

    This information is based on Borland's RAD Studio IDE:

    • http://docs.codegear.com/docs/radstudio/radstudio2007/RS2007_helpupdates/HUpdate4/EN/html/devcommon/tasm32_options_xml.html
    0 讨论(0)
提交回复
热议问题