#include <stdio.h>
int main(){
__asm__ (
"result: \n\t"
".long 0 \n\t"
"rdtsc \n\t"
"movl %eax, %ecx\n\t"
"rdtsc \n\t"
"subl %ecx, %eax\n\t"
"movl %eax, result\n\t"
);
extern int result;
printf("%d\n", result);
}
I would like to pass some data from assembler to main via the result variable. Is this possible? My assembler code causes a Segmentation fault (core dumped). I am using Ubuntu 15.10 x86_64, gcc 5.2.1.
__asm__fragment.resultin the program's code segment, and.long 0produces twoadd %al,(%rax)instructions.unsigned long long a = __builtin_ia32_rdtsc()? Then you don't need to write any asm.