11/7/2023 0 Comments Write in c![]() In the end, the behavior we see occurs because of how the x86_64 architecture is made. ![]() Why? Well, since we asked for two integers, the printf call will look into the first integer register ( esi) and print its content ( 24, as we stated above), then look in the following integer register ( edx) and print whatever is in it (incidentally 0). The double(42) value still goes into the xmm0 register, and the 24 integer, logically, ends up in the esi register. We can prove that statement pretty easily. Since it is given the same string as before, it’s pretty guessable that the printf function will look into the esi register again, whatever there is in there. However, we can see in the blue part of the code (lines 10 to 14, the equivalent to printf("%d\n", double(42)) ) the value is put in another register: the xmm0 register. So it’s an educated guess to say that when the printf function reads a %d in the string it is given, it’ll look in the esi register for what to print. ![]() ![]() In the yellow zone of the assembly code (lines 6-to 9, the equivalent to printf("%d\n", 666) ) we can see that everything’s fine, the 666 value is put in the esi register and then the function printf is called. (use this Godbolt link to have a clearer matching between the C++ code and the assembly instructions: ) ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |