Skip to content

Instantly share code, notes, and snippets.

@NalaGinrut
Created December 31, 2013 03:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NalaGinrut/8192163 to your computer and use it in GitHub Desktop.
Save NalaGinrut/8192163 to your computer and use it in GitHub Desktop.
A case for %Pn in GCC inline ASM
cat test.c
------------------------------------------------------------
int main(int argc, char * argv[]) {
__asm__ ("call __foo_bar_%P0" : : "i"(42));
return 0;
}
------------------------------------------------------------
gcc -S test.c
cat test.s
-------------------------------------------------------------
.file "test.c"
.text
.globl main
.type main, @function
main:
.LFB0:
.cfi_startproc
pushq %rbp
.cfi_def_cfa_offset 16
.cfi_offset 6, -16
movq %rsp, %rbp
.cfi_def_cfa_register 6
movl %edi, -4(%rbp)
movq %rsi, -16(%rbp)
#APP
# 3 "test.c" 1
call __foo_bar_42
# 0 "" 2
#NO_APP
movl $0, %eax
popq %rbp
.cfi_def_cfa 7, 8
ret
.cfi_endproc
.LFE0:
.size main, .-main
.ident "GCC: 4.8.1"
.section .note.GNU-stack,"",@progbits
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment