Having this code:
int main (void) {
int dividend =20;
int divisor =4;
int res;
asm(
"divb %2\n\t"
"movl %%eax, %0"
: "=m"(res)
: "a"(dividend), "m"(divisor));
printf("res:%d\n",res);
return 0;
}
Generates this asm:
main:
.LFB6:
.cfi_startproc
pushq %rbp #
.cfi_def_cfa_offset 16
.cfi_offset 6, -16
movq %rsp, %rbp #,
.cfi_def_cfa_register 6
subq $32, %rsp #,
# c.c:4: int main (void) {
movq %fs:40, %rax # MEM[(<address-space-1> long unsigned int *)40B], tmp92
The only thing I am interested in is what value is on the %fs:40
, before going to rax
(last row of asm). Why does compiler decided to put the var there? Moreover, why does it use offset 40
? like %fs:40
? What is there?
EDIT:
I think it does have something with values in inline asm to be put in memory ("=m"(res)
), So the %fs
reg. is used by compiler to put temporary variables? But why are they put right in this segment? Does compiler have any internal mechanism to decide, on which address (and in a particular segment of course) should be variable put? (If programmer specify to place the var in memory, as is in this case).