Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 1105 Vote(s) - 3.48 Average
  • 1
  • 2
  • 3
  • 4
  • 5
manipulating c variable via inline assembly

#1
> **Possible Duplicate:**
> [How to access c variable for inline assembly manipulation](

[To see links please register here]

)

<!-- End of automatically inserted text -->

Given this code:

#include <stdio.h>

int main(int argc, char **argv)
{
int x = 1;
printf("Hello x = %d\n", x);


}

I'd like to access and manipulate the variable x in inline assembly. Ideally, I want to change its value using inline assembly. GNU assembler, and using the AT&T syntax. Suppose I want to change the value of x to 11, right after the printf statement, how would I go by doing this?

Reply

#2
The `asm()` function follows this order:

asm ( "assembly code"
: output operands /* optional */
: input operands /* optional */
: list of clobbered registers /* optional */
);

and to put 11 to x with assembly via your c code:

int main()
{
int x = 1;

asm ("movl %1, %%eax;"
"movl %%eax, %0;"
:"=r"(x) /* x is output operand and it's related to %0 */
:"r"(11) /* 11 is input operand and it's related to %1 */
:"%eax"); /* %eax is clobbered register */

printf("Hello x = %d\n", x);
}

You can simplify the above asm code by avoiding the clobbered register

asm ("movl %1, %0;"
:"=r"(x) /* related to %0*/
:"r"(11) /* related to %1*/
:);

You can simplify more by avoiding the input operand and by using local constant value from asm instead from c:

asm ("movl $11, %0;" /* $11 is the value 11 to assign to %0 (related to x)*/
:"=r"(x) /* %0 is related x */
:
:);

Another example:

[To see links please register here]

Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through