I wrote a simple C program to look at the stack frame of printf()
#include <stdio.h>
int main(void){
printf("%s");
}
I thought the way the stack would work is main() would first push "%s" onto the stack, so printf will either seg fault or print out garbage. However, nowhere in my disassembly does it push "%s" onto the stack. I printed out all the values between %fp and %sp, but none of them contains "%s".
The assembly dump for main:
0x00400950 <+0>: lui gp,0x2
0x00400954 <+4>: addiu gp,gp,-32224
0x00400958 <+8>: addu gp,gp,t9
0x0040095c <+12>: addiu sp,sp,-32
0x00400960 <+16>: sw ra,28(sp)
0x00400964 <+20>: sw s8,24(sp)
0x00400968 <+24>: move s8,sp
0x0040096c <+28>: sw gp,16(sp)
0x00400970 <+32>: lw v0,-32744(gp)
0x00400974 <+36>: nop
0x00400978 <+40>: addiu v0,v0,2864
0x0040097c <+44>: move a0,v0
0x00400980 <+48>: lw v0,-32688(gp)
0x00400984 <+52>: nop
0x00400988 <+56>: move t9,v0
0x0040098c <+60>: jalr t9
0x00400990 <+64>: nop
0x00400994 <+68>: lw gp,16(s8)
0x00400998 <+72>: move sp,s8
0x0040099c <+76>: lw ra,28(sp)
0x004009a0 <+80>: lw s8,24(sp)
0x004009a4 <+84>: addiu sp,sp,32
0x004009a8 <+88>: jr ra
0x004009ac <+92>: nop
If "%s" is not stored on the stack, where is it stored? Also, where does it get the corresponding string to print out?