0

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)
);
3
Contributors
4
Replies
6
Views
6 Years
Discussion Span
Last Post by wildplace
1

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;
}
Votes + Comments
=D great helpl
0

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

1

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"

Votes + Comments
:D thx
0

ya. thx for all your helo :D

Edited by wildplace: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.