how do i move the value of %eax to the memory location of %0

int size 10;
long *list = (long*) malloc(size*sizeof(long));
asm(
movl   $999, %%eax
movl   %eax, (%0) // this is what im trying, how do i fix it?
:"=r"(list)
:"0"(list), "a"(strLen)
);

Try something like below

#include <stdio.h>
#include <stdlib.h>

unsigned long *lptr = NULL;

int main()
{
  lptr = (unsigned long*)malloc(sizeof(unsigned long));
  
  /*check if allocation failed*/
  
  __asm__ 	(
				"movq	%0, %%rax\n\t"
				"movq	$6, (%%rax)\n\t"
				:"=m"(lptr)
			);
			
  fprintf(stdout, "ans->%lu\n", *lptr);
  return 0;
}
commented: =D great helpl +2

yah..=D that works for me..
and a other question.. if my system is 32bit, i coulnt use 64bit registers?

yah..=D that works for me..
and a other question.. if my system is 32bit, i coulnt use 64bit registers?

Then just replace "%%rax" with "%%eax" and "movq" with "movl"

commented: :D thx +2

ya. thx for all your helo :D

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.