stack-pointer

What is the difference between Stack Pointer and Program Counter?

允我心安 提交于 2021-02-07 13:14:53
问题 As we always know the procedure of executing task by a microprocessor is just executing binary instructions from memory one by one and there is a program counter which holds the address of the next instruction. So this is how processor executes it's tasks if I am not wrong. But there is also another pointer named Stack Pointer which does almost same thing like the program counter. My question is why we need a Stack Pointer to point address of memory(Stack)? Can somebody tell me about the main

What are the x86 instructions that affect ESP as a side effect?

懵懂的女人 提交于 2020-08-20 02:01:50
问题 I know that call and ret will modify the value of esp and that push and pop have a number of variants, but are there other instructions that will affect the stack pointer ? 回答1: The following instructions modify the stack pointer 1 : call enter int n/into/int 3 iret/iretd leave pop push ret sysenter sysexit pusha/pushad popa/popad pushf/pushfd/pushfq popf/popfd/popfq vmlaunch/vmresume eexit I leave to you the burden of telling primary and side effects apart. Keep in mind that any instruction

Function call jumps to the wrong function

余生长醉 提交于 2019-12-22 02:32:42
问题 I am compiling a c++ static library in vs2008, and in the solution i also have a startup project that uses the lib, and that works fine. But when using the lib in another solution i get an run-time check failure. "The value of ESP was not properly saved across a functioncall" Stepping through the code i noticed a function foo() jumping to bar() instead right before the crash. The functions in question are just regular functions and no function pointers. Anyone has any clue what might be going

Function call jumps to the wrong function

夙愿已清 提交于 2019-12-22 02:32:40
问题 I am compiling a c++ static library in vs2008, and in the solution i also have a startup project that uses the lib, and that works fine. But when using the lib in another solution i get an run-time check failure. "The value of ESP was not properly saved across a functioncall" Stepping through the code i noticed a function foo() jumping to bar() instead right before the crash. The functions in question are just regular functions and no function pointers. Anyone has any clue what might be going

x86 where stack pointer points?

南笙酒味 提交于 2019-12-18 12:26:05
问题 For example if I pushed ax is [SP] points to my value of ax or the word after ax? Also is it differs from real mode to protected mode? I ask this because the Art of assembly book illustrates and explains as the sp points to last pushed data, and on this page OSDev Wiki - Stack it illustrated as it points to empty word after last pushed data. 回答1: Wikipedia says here: The stack is implemented with an implicitly decrementing (push) and incrementing (pop) stack pointer. In 16-bit mode, this

What is the purpose of the RBP register in x86_64 assembler?

瘦欲@ 提交于 2019-12-17 15:16:32
问题 So I'm trying to learn a little bit of assembly, because I need it for Computer Architecture class. I wrote a few programs, like printing the Fibonacci sequence. I recognized that whenever I write a function I use those 3 lines (as I learned from comparing assembly code generated from gcc to its C equivalent): pushq %rbp movq %rsp, %rbp subq $16, %rsp I have 2 questions about it: First of all, why do I need to use %rbp ? Isn't it simpler to use %rsp , as its contents are moved to %rbp on the

Why is 0x20 subtracted from the stack pointer in the prologue of this function's code?

馋奶兔 提交于 2019-12-12 13:53:12
问题 void main(){ int c; c = function(1, 2); } int function(int a, int b){ char buf[10]; a = a+b; return a; } Assembly code: main: 08048394: push %ebp 08048395: mov %esp,%ebp 08048397: and $0xfffffff0,%esp **0804839a: sub $0x20,%esp <-----------------------???????** 0804839d: movl $0x2,0x4(%esp) 080483a5: movl $0x1,(%esp) 080483ac: call 0x80483b7 <function> 080483b1: mov %eax,0x1c(%esp) 080483b5: leave 080483b6: ret function: 080483b7: push %ebp 080483b8: mov %esp,%ebp 080483ba: sub $0x10,%esp

Run-Time Check Failure #0 in embedded asm code

孤者浪人 提交于 2019-12-11 06:37:17
问题 I'm a bit new to assembler, but I'm trying to lookup the parameters from a C++ method in the esp stack, using embedded assembler code. So far I haven't even been able to copy the esp pointer to ebp so I can get a hold on the stack (in case it changes). Even this little piece of code gives me the failure: #include <stdlib.h> int main(int argc, char* argv[]) { __asm { mov ebp, esp } system("pause"); return 0; } After I run this, I get: Run-Time Check Failure #0 - The value of ESP was not