X86 Assembly/Interfacing with C stdlib and own libraries

Prerequisites: CDECL, X86_Assembly/GAS_Syntax.

Using the C stdlib
If you use GCC for linking, it will link with the C library by default. This means that you can probably call printf without changing your build process at all.

On this platform, the CDECL is used. Note the order in which the arguments are pushed.

Output
double: 3.750000 eax = in decimal: -559038737 in hex: deadbeef ecx:edx = testdouble = 400e0000 00000000 hi	wikibooks	!

Questions and exercises

 * 1) Try reading about the double-precision floating-point format and understand why this bit pattern produces the number 3.75.
 * In double precision numbers, the exponent is 11 bits, which means the bias is 210-1. The formula would be (Python, note that the range excludes the ending number, that's why there's a +1):
 * 1) What happens to the hex representation if you change the 10th last bit to 1?
 * Answer: the second double word of the double would change to 00000200, the floating point representation would change, but the change wouldn't be visible with this printf call because it is too small.
 * 1) How does printf know how many stack elements to pop?
 * Answer: printf doesn't pop, it only reads. The top of the stack is a pointer to the format string which it reads. When it sees a %f, it will read 8 bytes. If it sees a %d, it will read 4 bytes.
 * Answer: printf doesn't pop, it only reads. The top of the stack is a pointer to the format string which it reads. When it sees a %f, it will read 8 bytes. If it sees a %d, it will read 4 bytes.