Reputation:
How can I write a 32-bit value to the low doubleword of the registers r8-r15 with asm()? The following code won't compile:
#include <stdlib.h>
#include <stdio.h>
int main()
{
float f0,f1,f2=-2.4f;
asm volatile
(
"movl %2, %%r8\n"
"movl %%r8, %1\n"
"movl %1, %%r15\n"
"movl %%r15, %0"
:"=r"(f0,f1)
:"r"(f1,f2)
:"%r8,%r15"
);
printf("%f\n",f0);
system("pause");
return 0;
}
The error I get:
unknown register name '%r8,%r15' in 'asm'
Note that It is a x64 program so r8-r15 registers should be available.
Upvotes: 1
Views: 2235
Reputation: 12435
Use r8d to access the low 32 bits of r8. Note that when you write to r8d (or any 32-bit register in 64-bit mode), it clears the upper 32 bits. There is no way to write to the low 32 bits and preserve the upper 32 bits.
Upvotes: 7