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 840925
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T05:42:29+00:00 2026-05-15T05:42:29+00:00

I have a function in VS where I pass a pointer to the function.

  • 0

I have a function in VS where I pass a pointer to the function. I then want to store the pointer in a register to further manipulate. How do you do that?

I have tried

float __declspec(align(16)) x[16] = 
{
    0.125000, 0.125000, 0.125000, 0,
    -0.125000, 0.125000, -0.125000, 0,
    0.125000, -0.125000, -0.125000, 0,
    -0.125000, -0.125000, 0.125000, 0
};

void e()
{
    __asm mov eax, x // doesn't work
    __asm mov ebx, [eax]
}

void f(float *p)
{
    __asm mov eax, p // does work
    __asm mov ebx, [eax]
}

int main()
{
    f(x);
    e();
}
  • 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-05-15T05:42:29+00:00Added an answer on May 15, 2026 at 5:42 am

    Option 1 actually seems to work fine. Consider the following program:

    #include <stdio.h>
    
    void f(int *p) {
        __asm mov eax, p
        __asm mov ebx, [eax]
        // break here
    }
    
    void main()
    {
        int i = 0x12345678;
        f(&i);
    }
    

    With Visual Studio 2008 SP1, a single-file C++ program and debug build, I’m getting the following in the registers window when stepping into the end of f():

    EAX = 004DF960 
    EBX = 12345678 
    ECX = 00000000 
    EDX = 00000001 
    ESI = 00000000 
    EDI = 004DF884 
    EIP = 003013C3 
    ESP = 004DF7B8 
    EBP = 004DF884 
    EFL = 00000202
    

    Looking at the values in EAX, EBX and ESP, that looks like a pretty good evidence that you actually have the pointer you wanted in EAX. The address in EAX is just a tad higher than the one in ESP, suggesting it’s one frame higher up the stack. The dereferenced value loaded into EBX suggests we got the right address.


    Loading the address of a global is subtly different. The following example uses the LEA instruction to accomplish the task.

    #include <stdio.h>
    
    int a[] = { 0x1234, 0x4567 };
    
    void main()
    {
        // __asm mov eax, a    ; interpreted as eax <- a[0]
        __asm lea eax, a       ; interpreted as eax <- &a[0]
        __asm mov ebx, [eax]
        __asm mov ecx, [eax+4]
        // break here
    }
    

    Stepping to the end of main() gets you the following register values. EAX gets the address of the first element in the array, while EBX an ECX get the values of its members.

    EAX = 00157038 
    EBX = 00001234 
    ECX = 00004567 
    EDX = 00000001 
    ESI = 00000000 
    EDI = 0047F800 
    EIP = 001513C9 
    ESP = 0047F734 
    EBP = 0047F800 
    EFL = 00000202 
    

    The magic isn’t in the LEA instruction itself. Rather, it appears that the __asm directive treats C/C++ identifiers differently depending on whether a MOV or an LEA instruction is used. Here is the ASM dump of the same program, when the MOV instruction is uncommented. Notice how the MOV instruction gets the content of a[] as its argument (DWORD PTR), while the LEA instruction gets its offset.

    ; ...
    
    PUBLIC ?a@@3PAHA       ; a
    _DATA SEGMENT
    ?a@@3PAHA DD 01234H    ; a
              DD 04567H
    _DATA   ENDS
    
    ; ...
    
    mov eax, DWORD PTR ?a@@3PAHA
    lea eax, OFFSET ?a@@3PAHA
    mov ebx, DWORD PTR [eax]
    mov ecx, DWORD PTR [eax+4]
    
    ; ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 423k
  • Answers 423k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Try this (see also on rubular.com): ^(\d{13})?$ Explanation: ^, $… May 15, 2026 at 11:46 am
  • Editorial Team
    Editorial Team added an answer The ConsumerBase you've initialized and passed in needs to have… May 15, 2026 at 11:46 am
  • Editorial Team
    Editorial Team added an answer You don't need the launcher for Java - the eclipse… May 15, 2026 at 11:46 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.