 <p>Your opcode is incorrect, this works:</p> <pre><code>if(data) { *p++ = 0xb8; //mov $1, %eax *p++ = 0x01; *p++ = 0x00; *p++ = 0x00; *p++ = 0x00; *p++ = 0xC3; //ret } </code></pre> <p>0xb8 is moving a 32bit immediate into eax, so you have to specify all 4 bytes.</p>