Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8774941
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T18:41:27+00:00 2026-06-13T18:41:27+00:00

Lets say I want to write an inline assembly function in a c++ code

  • 0

Lets say I want to write an inline assembly function in a c++ code that returns its return address.

So if I’m calling the function returnAddress() from some address and it needs to return to the address X after the function is done, I want returnAddress() to return the value X.

example of code for returnAddress():

void* getAddress()
{
    __asm {
        pop ebx;     // moving return offset to ebx?
        push ebx;    // restoring stack state
        xor eax, eax;
        mov ax, cs;  // ax <- code segment
        mov ecx, 16;
        mul ecx;     // multiplying the code segment by 16
        add eax, ebx;// adding offset
    }
}

The previous code doesn’t work correctly, since when I press alt+8 I can clearly see my code’s address is completely different from the return value of this function.

The reason I want to find my code’s address in the memory is because I want to try and change it while the code itself is running. If there is any other way to find the address of my code without using inline assembly (maybe using windows API?) let me know please.

Also I’m pretty sure I can’t even use CS’s (code segment) value using visual studio 2010, so maybe that’s what causing me problems… CS always equals to 35.
Does the assembly view (alt+8) show incorrect addresses because VS2010 runs a virtual machine?

This is my first post here so maybe I didn’t make my point very clear. Please let me know if I can explain myself to make it any clearer.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T18:41:28+00:00Added an answer on June 13, 2026 at 6:41 pm

    Code segments are only used in 16-bit systems. With the introduction of 32-bit, code segments went away.

    You can use VisualStudio’s intrinsic _ReturnAddress() function:

    void * _ReturnAddress(void);
    #pragma intrinsic(_ReturnAddress)
    
    void* getAddress()
    {
        return _ReturnAddress();
    }
    

    If you want to do it manually, say on a non-VisualStudio compiler, then the call stack of a 32-bit x86 function call contains the full 32-bit return address, so you can return it as-is:

    void* __declspec(naked) getAddress()
    {
        asm
        {
            mov eax, [esp];
            ret;
        }
    }
    

    For x64 function calls, you should be able to use the equivilent 64-bit registers:

    void* __declspec(naked) getAddress()
    {
        asm
        {
            mov rax, [rsp];
            ret;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Lets say we've got a function like f below, that returns a monad. However,
Let's say there are two python scripts that want to write data to the
I want to write a program that would take a string, let's say Fox
Lets say you want to write a high performance method which processes a large
Lets say I want to save function in database. For example we have table
Lets say I want to write an AJAX chat box, just something simple, I
Lets say I've got 50 pages, and I want to write a description for
I want to write a general purpose utility function that will use an OpenGL
So basically I want to write a function that can be written like this:
Lets say I want to replace the following string within a textfile: document.write(unescape(%3Cscript src='

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.