about execute assembly exapmles under freebsd
Ryan Sommers
ryans at gamersimpact.com
Sun Apr 24 04:06:21 PDT 2005
Something else than can be useful is to use inline assembly and the -S
switch for GCC (gcc -S sourcefile, produces sourcesfile.s which is the
assembly that would have been sent to gas if you had specified -o).
Inline assembly example:
(ryans at blue)~:cat test.c
int
main()
{
int input=0;
void *edx, *ebx, *ecx, *eax;
asm("cpuid" : "=a" (eax), "=b" (ebx), "=c" (ecx), "=d" (edx) : "a" (input));
printf("CPUid returned: EAX=%0.8x EBX=%0.8x ECX=%0.8x EDX=%0.8x\n", eax,
ebx, ecx, edx);
return 1;
}
(ryans at blue)~:./test
CPUid returned: EAX=0001 EBX=68747541 ECX=444d4163 EDX=69746e65
(ryans at blue)~:perl -e 'print
"\x41\x75\x74\x68\x65\x6e\x74\x69\x63\x41\x4d\x44\n";'
AuthenticAMD
(ryans at blue)~:
NOTE: If the order in the Perl command confused you, remember,
byte-ordering. :) Little-endian you have to reverse the bytes.
--
Ryan Sommers
ryans at gamersimpact.com
More information about the freebsd-hackers
mailing list