我通过汇编代码使用printf。 我注意到在下面的例子中,如果我省略了期望的参数,垃圾被打印。
.386 .model flat, c .stack 100h printf PROTO arg1:Ptr Byte, printlist:VARARG .data msg3fmt byte 0Ah,"%s",0Ah,"test output",0Ah,0 .code main proc INVOKE printf, ADDR msg3fmt ret main endp end我的问题是为什么? 有没有一个设置的内存地址printf使用期望找到一个参数? 为什么打印任何东西,因为没有参数通过?
I am using printf via assembly code. I note that in the following example if I ommit the expected argument, garbage is printed.
.386 .model flat, c .stack 100h printf PROTO arg1:Ptr Byte, printlist:VARARG .data msg3fmt byte 0Ah,"%s",0Ah,"test output",0Ah,0 .code main proc INVOKE printf, ADDR msg3fmt ret main endp endMy question is why? Is there a set memory address printf uses expecting to find an argument? Why is anything printed at all since no argument is passed?
最满意答案
原因是格式说明符告诉printf应该收到多少个参数。 Printf从堆栈获取数据; 如果你没有提供任何数据,那么它会将任何发生在堆栈上的事情都视为参数。
The reason is that the format specifiers tell printf how many arguments it should have received. Printf gets its data from the stack; if you don't provide any data for it then it will pull whatever happened to be on the stack and treat as an argument.
更多推荐
发布评论