函數棧幀
棧高地址向下增長棧基棧指針
函數棧幀BP of calleeSP of calleeBP of caller局部變量回去值參數
……return1棧a1a2r1r2局部變量BP of ASP of A回去值BP of callerreturn2param1參數param2
……return1棧a1a2r1r2局部變量BP of ASP of A回去值BP of callerreturn2param1參數param2SP of B+偏移……SP of B
……return1棧a1a2r1r2局部變量BP of ASP of A回去值BP of callerreturn2param1參數param2SP of B 回去地址BP of A……
……return1棧a1a2r1r2局部變量BP of ASP of A回去值BP of callerreturn2param1參數param2SP of B回去地址BP of A……
……return1棧a1a2r1r2局部變量BP of ASP of A回去值BP of callerparam1參數SP of C 回去地址BP of A……
……棧g1g2g3free越界了
……棧g1g2g3free
傳參
……棧a=1b=2b=2a=1局部變量SP of main參數BP of caller……BP of main回去地址SP of sap值拷貝
……棧a=1b=2b=1a=2局部變量SP of main參數BP of caller…… BP of main 回去地址SP of sap互換
……棧a=0b=01a=1局部變量SP of main參數BP of caller…… BP of main 回去地址SP of incr回去值b=1拷貝回去值
……棧a=0b=01a=2局部變量SP of main參數BP of caller…… BP of main 回去地址SP of incr回去值b=2
……棧a=0b=11a=2局部變量SP of main參數BP of caller…… BP of main 回去地址SP of incr回去值b=2b=incr(a)
……棧a=0b=0b=1a=1局部變量SP of main參數BP of caller…… BP of main 回去地址回去值拷貝回去值SP of incr
……棧a=0b=0b=2a=2局部變量SP of main參數BP of caller……BP of main回去地址回去值SP of incr
……棧a=0b=2b=2a=2局部變量SP of main參數BP of caller…… BP of main 回去地址SP of incr回去值b=incr(a)
函數跳轉與回去
……棧存放器BPSPIP棧基棧指針指令指針指令push 3push 4
……棧存放器BPSPIP棧基棧指針指令指針指令push 3push 43
……棧存放器BPSPIP棧基棧指針指令指針指令push 3push 4……34
……棧存放器BPSPIP棧基棧指針指令指針指令把3挪動到SP+16處把4挪動到SP+8處
……棧存放器BPSPIP西班牙對哥斯大黎加賠率棧基棧指針指令指針指令把3挪動到SP+16處把4挪動到SP+8處……34
……棧a=1b=2……代碼段…………a1call b1~~~~~~~~~~~~~~~~b1~~~~~~~~……~~~~~~~~~~~~~~~~RETAB存放器BPSPa1IPs1s2d=2c=1s3s4s5s6
……棧a=1b=2……代碼段…………a1call b1~~~~~~~~~~~~~~~~b1~~~~~~~~……~~~~~~~~~~~~~~~~RETAB存放器BPSPb1IPa2a2d=2c=1s1s2s3s4s5s6
棧a=1b=2…………代碼段…………a1call b1~~~~~~~~~~~~~~~~b1~~~~~~~~……~~~~~~~~~~~~~~~~RETAB存放器BPSPb4IPa2a2s1b4d=2c=1s1s2s3s4s5s6s7s8s9
棧a=1b=2……代碼段…………a1call b1~~~~~~~~~~~~~~~~b1~~~~~~~~……~~~~~~~~~~~~~~~~RETAB存放器BPSPbnIPa2a2s1bnc=1d=2c=1d=2……s1s2s3s4s5s6s7s8s9
……代碼段…………a1call b1~~~~~~~~~~~~~~~~b1~~~~~~~~……~~~~~~~~~~~~~~~~RETAB存放器BPSPa2IPa2棧a=1b=2a2s1c=1d=2c=1d=2……s1s2s3s4s5s6s7s8s9