stack frame in memory(一)

The content of this article is from Assembly Language For x86 Processors Sixth Edition By Kip R.Irvine,appended with some understanding of myself.



1.Stack Parameters

1.1    Contrast register parameters with stack parameters

1.2    Two general types of arguments are pushed on the stack during subroutine calls:


2.Accessing Stack Parameters

2.1    prologue & epilogue

prologue:

push ebp

mov ebp,esp

epilogue:

pop ebp

ret

2.2    clearing the stack

The illustration above is of vital important to show the right order of the content in the subroutine‘s stack——the return address is must be the fisrt one to be pushed into the stack.

The reason that I emphasize this is because we‘re gonna deal with a tough problem derived from the call of a subroutines.

So now let me summerize the whole stuff:First of all,there‘s a successive space in the memory,whose first address is pointed by sp.And the moment when our procedure call the subroutine,which leads to the prologue step as we‘ve mentioned above.Then we substrct the sp,which means to expand the space of the stack,and the space we get now is constant during the calling of the subroutine.sp and bp remain fixed throughout the subroutine,because we always need "somebody" to tell us the exact location of the stack we use.However,we can move si or bx across the stack to get and process the data inside it.

2.3    Passing 8-bit and 16-bit arguments on the stack

general way to solve it

2.4    Saving & Restoring registers

From this illustration we can see that all the parameters and return address are stored upside the EBP&ESP,because they are tranmitted from outside,not produced by the subroutine itself.And we can also see that all the push&pop operators are operated under the ESP and EBP.

时间: 2024-10-16 21:09:26

stack frame in memory(一)的相关文章

Stack frame

http://en.citizendium.org/wiki/Stack_frame In computer science, a stack frame is a memory management strategy used to create and destroy temporary (automatic) variables in some programming languages. Among other things, use of a stack allows programm

PHP错误: Exception thrown without a stack frame in Unknown on line 0[转载]

来自:网易博客 就目前我的了解,在两种情况下,PHP会报 Exception thrown without a stack frame in Unknown on line 0这种错误: 1)异常捕捉用了set_exception_handler导向,Exception里面执行另一个Exception 如下面这段代码,就会出现这种问题: http://de.php.net/manual/de/function.set-exception-handler.php#88082 function er

How a stack frame works 栈帧

http://en.citizendium.org/wiki/Stack_frame To use a stack frame, a thread keeps two pointers, often called the Stack Pointer (SP), and the Frame (FP) or Base Pointer (BP). SP always points to the "top" of the stack, and FP always points to the &

Modern C++ Course [Lecture 7] {Pointers, const with pointers, Stack and Heap, Memory leaks, Dangling pointers}

https://en.cppreference.com/w/cpp/language/range-for every object has a pointer to itsleft. stack operations are very quick it's computationally expensive to search variables in a stack, when the scopes and functions are very large. So, keep your sco

sparc v8 stack frame

main.c int enable=1; int main() { int a, b; int sum; a = 1; b = 3; sum = add(a, b); return 0; } int add(int a, int b) { return (a+b); } int del() { return 0; } 汇编如下: main.elf: file format elf32-sparc Disassembly of section .text: 70000000 <main>: 70

[ZZ]10 Most Common Mistakes that Python Programmers Make

About Python Python is an interpreted, object-oriented, high-level programming language with dynamic semantics. Its high-level built in data structures, combined with dynamic typing and dynamic binding, make it very attractive for Rapid Application D

Dr.memory

Run Dr.memory on visual c++ 2013 Title: Dr. Memory Command: C:\Program Files (x86)\Dr. Memory\bin\drmemory.exe Arguments: -visual_studio -- $(TargetPath) Initial Directory: $(TargetDir) set arguments-light -no_midchunk_inheritance_ok -no_check_gdi -n

C# Heap(ing) Vs Stack(ing) in .NET [C# 堆和栈的使用以及垃圾回收原理]

最近在<C#Corner>上看到了一篇关于.NET内存管理以及垃圾回收的文章,虽说是英文的内容,但还是硬着头皮读了下来.发现并不是我原本想象中的那么枯燥,因为语言通俗而且还有很多图片示意,感觉让我又对"堆"和"栈"以及垃圾回收机制有了更加深刻的理解和认知,记录下来提醒自己尽量书写优质的代码,而不是只管实现功能,不管性能优劣去蛮干.  [文章出自: http://www.c-sharpcorner.com/article/c-sharp-heaping-v

ucore Lab2学习:Virtual Memory

我觉得这个lab最主要就是理解好Virtual memory是怎么map到physical memory的.在CSAPP里面了,通过MMU和TLB电路来实现转换.x86中是用的2级page table. 还要理解stack frame(譬如lab1的project 4.1.1):switch_to_u2k和swith_to_k2u.有2种方法.一个是通过改写stackframe的TSS.一个是直接用asm改写gate descriptor. CSAPP讲了:每一个process有一个对应的VM和