1. Integers and floating-point numbers have different storage formats and layouts in memory (please refer to/songjin/article/details/7753777 for the memory layout and representation of floating-point numbers).
2. When putting parameters on the stack, printf puts parameters on the stack according to the type of actual parameters, not according to the type specified in the formatting characters. The specific stacking process is as follows. As a result, the types of parameters put on the stack do not match the types used by the actual functions (the key point is that the occupied memory size is different), so the results mentioned in the title will appear in the specific analysis, because the memory layout will be very small when shaping is parsed into floating-point numbers, because shaping was originally stored in 4 bytes, but it was parsed into 8-byte floating-point numbers, so the value obtained will be very small, just as floating-point numbers indicate: denormalization: when all binary bits of e are 0, n,
Note that the hidden bit to the left of the decimal point is 0. Why e equals (1-bias) instead of (-bias) is mainly designed for the smooth transition between normalized and denormalized values. We will continue our discussion later.
In denormalized form, we can represent 0. After setting the sign bit s to 1 and all other bits to 0, we get-0.0; Similarly, if all bits are set to 0, you get +0.0. Non-normalized numbers have other uses, such as representing decimals that are very close to 0, and these decimals are evenly close to 0, which is called "gradual underflow" attribute.
Here are two pieces of disassembly code to analyze how parameters are put on the stack:
printf("%f ",45);
00405028 mov esi,esp
0040502A Push 2Dh.
0040502 c push offset _ ORDER _ SERVER _ ADDRESS-0 ach(43 F2 ach)
0040503 1 call dword ptr [_ _ imp _ _ printf (43c124h)].
00405037 Add esp, 8
printf("%f ",d); (d is an integer variable)
00405028 mov esi,esp
0040502A mov ecx,dword ptr [d]
0040502D Push ecx
0040502 e push offset _ ORDER _ SERVER _ ADDRESS-0 ach(43 F2 ach)
00405033 call dword ptr [_ _ imp _ _ printf (43c124h)].
00405039 Add esp, 8
0040503C cmp esi,esp
0040503 e call _ RTC _ check esp(439760h)
Double a=5, c;
Floating b;
int d=0x40a00000,y = 6;
int * p;
char s = 5;
p = & ampd;
b =(float)a;
printf("%f,%f,%f,%f,%f,%f,%d ",b,c,(float)d,s,(float)s,y,y);
00405028 mov esi,esp
0040502A mov ecx,dword ptr [y]
0040502D Push ecx
0040502E mov edx,dword ptr [y]
0040503 1 push edx
00405032 movsx eax, byte pointer [s]
00405036 mov dword ptr [ebp-34h],eax
00405039 field dword ptr [ebp-34h]
0040503C submersible pump, 8
0040503F fstp qword ptr [esp]
00405042 movsx ecx, byte pointer [s]
00405046 Push ecx
00405047 field double-word pointer [d]
0040504A Sub-esp, 8
0040504D fstp qword ptr [esp]
00405050 Sub esp, 8
00405053 fld qword ptr [c]
00405056 fstp qword ptr [esp]
00405059 fld dword ptr [b]
0040505C submersible pump, 8
0040505F fstp qword ptr [esp]
00405062 push offset _ ORDER _ SERVER _ ADDRESS-0C4h(43 F2 ach)
00405067 call dword ptr [_ _ imp _ _ printf (43c124h)].
0040506D Add ESP for 30h.
00405070 cmp esi,esp
00405072 call _ RTC _ check esp(439780h)