Follow these steps:
test.c
#include <arpa/inet.h> int main() { volatile uint32_t x = 0x12345678; x = ntohl(x); return 0; }
Then compile with:
$ gcc -O3 -g -save-temps test.c
And test.s resulting test.s file test.s or alternatively run objdump -S test.o
On my machine (Ubuntu 13.4) the corresponding asssembler:
movl $305419896, 12(%esp) movl 12(%esp), %eax bswap %eax movl %eax, 12(%esp)
Tips:
- 305419896 - 0x12345678 in decimal form.
12(%esp) is the address of the mutable variable.- All
movl instructions exist for volatile -ness << 28>. The only really interesting instruction is bswap . - Obviously,
ntohl compiled as inline-inline.
Also, if I look at test.i (precompiled output), I find that ntohl is #defined as just __bswap_32() , which is a built-in function, only with a call to __builtin_bswap32() .
source share