x86 assembly code examples
Each of the below C functions examples was compiled with:
gcc -S -m32 [options] source.cusing the following versions of gcc:
gcc version 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2336.11.00)and
gcc version 4.1.2 20080704 (Red Hat 4.1.2-52)Note that using -O, especially, may inline functions and eliminate code so that the generated assembly does not perform the same operations as the original C code.
Topic | Source | gcc -m32 -S source.c | gcc -m32 -S -O1 source.c | gcc -m32 -S -O source.c | |||
---|---|---|---|---|---|---|---|
Arithmetic | arith.c | arith.s | arith.linux.s | arith.O1.s | arith.linux.O1.s | arith.O.s | arith.linux.O.s |
Bitwise | bitwise.c | bitwise.s | bitwise.linux.s | bitwise.O1.s | bitwise.linux.O1.s | bitwise.O.s | bitwise.linux.O.s |
Shifts | shift.c | shift.s | shift.linux.s | shift.O1.s | shift.linux.O1.s | shift.O.s | shift.linux.O.s |
Comparisons | compare.c | compare.s | compare.linux.s | compare.O1.s | compare.linux.O1.s | compare.O.s | compare.linux.O.s |
If | if.c | if.s | if.linux.s | if.O1.s | if.linux.O1.s | if.O.s | if.linux.O.s |
While | while.c | while.s | while.linux.s | while.O1.s | while.linux.O1.s | while.O.s | while.linux.O.s |
Calls | call.c | call.s | call.linux.s | call.O1.s | call.linux.O1.s | call.O.s | call.linux.O.s |
Arrays | array.c | array.s | array.linux.s | array.O1.s | array.linux.O1.s | array.O.s | array.linux.O.s |
Structs | struct.c | struct.s | struct.linux.s | struct.O1.s | struct.linux.O1.s | struct.O.s | struct.linux.O.s |