On 5 October 2014 23:08, David Wohlferd <dw@xxxxxxxxxxxxxxxxxx> wrote: > Well, as written, gcc discards the whole asm statement as unneeded when > using any optimization since none of the outputs (ie ret) get used and the > statement is not volatile. > > I believe that adding "m" (hello) as an input will resolve your other > problem. Note that you may not easily see the string in the asm output > since gcc may encode this using something like this: > > movabsq $8022916924116329800, %rax > movq %rax, 32(%rsp) > movl $10, %eax > movw %ax, 44(%rsp) > > Also, I'd probably write this statement as something more like this > (untested): > > asm volatile > ( > "syscall" > : "=a" (ret) > : "0" (1), "S" (hello), "d" (hello_size), "D" (1), "m" (hello) > : "rcx", "r11", "memory", "cc" > ); > Thanks a lot! This version is certainly much better. > This lets gcc do as much of the work as possible, which generally produces > better code. And are you sure rcx and r11 get clobbered? Seems odd. Agreed. I'm positive about rcx and r11, since the ABI for Linux amd64 systems specifies that "The kernel destroys registers %rcx and %r11.". Thus, I guess it's safer to put them on the clobber list. > > dw Thanks again, dkk