Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Sorry to quibble about details, but doesn't "leal 0x1(%rdi), %eax" actually add one to the address %rdi and not to the contents of (%rdi)? It's usefulness for trick additions is because of its origins as "Load Effective Address": it doesn't actually access memory. Their stack gymnastics are silly, but I think you may be stuck with "mov (%rdi), %eax; add $1, %eax; ret" or some other 3 instruction equivalent.


You're right, it does add 1 to RDI, but this is exactly what we want. This is x86_64 calling convention, where arguments come on registers, not the stack. On 32-bit x86 you'd do something like

    mov eax, 1
    add eax, [esp + 4]
    ret




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: