60 likes | 370 Vues
The Instruction Pointer Register IP . Mian (). ip : Instruction Pointer Register. ip =01F01. ip =01F02. ip =01F03. ip =01F04. ip =01F05. 1:The address where the sub-function foo() starts. ip =? 1. ip =01F07. ip =01F08. 2:assigned another address by the O.S. .
E N D
The Instruction Pointer Register IP Mian() ip: Instruction Pointer Register ip=01F01 ip=01F02 ip=01F03 ip=01F04 ip=01F05 1:The address where the sub-function foo() starts ip=? 1 ip=01F07 ip=01F08 2:assigned another address by the O.S. ip = ? 2
Stack and Sub functions • Stack Memory: • Stack memory is a part of the system memory that is used during calling and returning to and from sub-function within a program • Such as • Passes parameters to a sub-functions and get the return values from the sub-function • Stores local variables of the sub function • Stack Mechanism: • Stack memory follows the LIFO mechanism (Last In First Out) • You can put values on the stack and get values from the stack according to LIFO • Stack Memory commands : • push <value> • Store a value at the TOP of the stack • pop • Take the value at TOP of the stack and assign it to a variable or register
Stack and Sub functions Mian() • When we call a sub-function : • Store the address of next instructioninto the stack memory using the push command • Start address of that sub-function goes to IP Register Foo() moo() koo() • When we return from a sub-function : • The address of next instructionpoppedfrom the stack memory and stored in the IP Register using the pop command
Stack and Sub functions • When we call a sub-function : • Store the address of next instructioninto the stack memory using the push command • Start address of that sub-function goes to IP Register • When we return from a sub-function : • The address of next instructionpoppedfrom the stack memory and stored in the IP Register using the pop command
Stack Memory Stack and Sub functions Mian() Foo() 0x001F1F0E Push 0x000F1F09 moo() 0x00001F06 koo() Push Push Pop Pop Pop Push 0x000F1F09 Push 0x001F1F0E Push 0x00001F06