Quantcast
Channel: Active questions tagged gcc - Stack Overflow
Viewing all articles
Browse latest Browse all 22228

Copying value from an x86 register to a memory location which is given by a pointer

$
0
0

Assuming I have a memory location that I want to copy data to, and I have that address in a pointer, Is it possible to copy data at that location via MOV instruction and inline assembly.Or basically how would I copy data to a memory location via inline assembly.

In the code snippet I have provided below, I am just copying my value the the eax register then copying from eax register to some out value, whereas i would like to copy it to some memory address.

In short what is in the eax register I would like to store in the address pointed by outpointer is it possible or is there a better way to do it in inline assembly?

#include <stdio.h>
#include <iostream>

using namespace std;

int func3(int parm)
{


    int out =0;
    // int *outpointer =&out;
    //what is in the eax register I would like to store 
    //in the address pointed  by outpointer

    asm("mov  %1 ,%%eax\n\t""mov %%eax, %0": "=r"(out) : "r"(parm));


    // cout<<outpointer;
    return out;
}

int main(int argc, char const *argv[])
{
    int x{5};
    int y{0};


    y = func3(x);

    cout<<y;


    return 0;
} 

Viewing all articles
Browse latest Browse all 22228

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>