Questions tagged [stack-pointer]

The register that points to the current location in the call-stack. Details vary by CPU architecture, but implicit use by push/pop instructions is common. (Please also include an architecture tag!)

1
vote
4answers
61 views

Deallocating locally defined variables in C

Assume we have the following piece of code: void foo() { char buffer[100]; } Is there a (preferably portable) way in C to deallocate buffer from the runtime stack (akin to add esp, 100 in assembly)...
0
votes
1answer
54 views

Stack Pointer (SP) adjustment at RST 5.5 interruption

In a microprocessor-8085 we run the command CALL 3000H . The program counter (PC) is equal to (PC)=2000H and the stack pointer is equal to (SP)=4000H. In the middle of the execution of the command we ...
1
vote
1answer
37 views

Is the difference between programming model wrt Program Counter and Stack Pointer in case of Assembly?

Processor model I ● Registers  PC – Program Counter  Single data register (accumulator) without name  We will use symbol A to describe operations on this register ● Stack with ...
2
votes
3answers
61 views

If esp points to the top of the stack, where does ebp point to?

I am having some trouble understanding how the esp and ebp registers are used. Why do we do: pushl %ebp movl %esp, %ebp at the start of every function? What is ebp holding when it is pushed for ...
2
votes
2answers
173 views

ARM assembly. Is it safe to use r13 (stack pointer) as a general purpose register?

I'm writing an extremely optimized leaf function and to make it run faster I want to use R13 as a general purpose register. I preserve R13 by moving it to one of VFP registers before using it and ...
4
votes
2answers
109 views

Who defines the stack pointer address

In terms of microcontrollers and embedded systems with C startup code, one of the functions of the C startup code is to initialize the stack pointer. Is this initial stack pointer address and C ...
1
vote
0answers
37 views

assembly: I don't understand why the stackpointer seems(!) to reserve insufficient memory here [duplicate]

I'm a beginner in assembly, so the answer to my question probably is totaly obvious for most of you, but not for me. Please don't blame. On a 64-bit-system this C-code: 1| int main () 2| { 3| ...
-1
votes
1answer
52 views

Stack Pointer in Assembly. ESP points always empty space or not?

Initially, ESP refers to the empty space of memory. When I push something such as push 1, then it will refers to the memory location of 1, or next empty space? here is the example push ebp mov ...
2
votes
2answers
213 views

convert C code to MIPS assembly - combination function using recursion

I have a problem with conversing C code to MIPS assembly code of combination function (nCr). nCr = (n-1Cr-1) + (n-1Cr) and when I put int 5 for n and 3 for r (digit data), the result has to be 10. ...
0
votes
0answers
34 views

Why ASLR generates SIGSEV if the stack pointer is reassigned

I am writing a char device that takes as input with ioctl a function pointer and a buffer pointer. I want to modify the user machine context so that back in user mode, that function is executed with a ...
0
votes
0answers
116 views

Modify the user stack pointer in kernel mode

I am writing a char device that takes as input with ioctl a function pointer and a buffer pointer. I want to modify the user machine context so that back in user mode, that function is executed with a ...
2
votes
1answer
453 views

Which Stack Is Used Coming Out of Reset In ARM Cortex-M, MSP or PSP?

I've been reading various sections in the ARM Information Center to try and find my answer, however I came to a point where the documentation confused me so I'm hoping someone here can help. I ...
2
votes
2answers
1k views

What is the difference between Stack Pointer and Program Counter?

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 ...
3
votes
1answer
139 views

Stack Pointer points to reserved Memory

I am debugging a code for a cryptographic implementation on a Tricore TC275 from Infineon (reference assembly language). PMI_PSPR (wx!p): org = 0xC0000000, len = 24K /*Scratch-Pad RAM (PSPR)*/ ...
2
votes
1answer
139 views

Interrupt / Stack Pointers / PIC Microcontroller

I am currently working with the PIC16F1829 micro controller. However, I am stuck on interrupt routine appropriate execution method. I want the interrupt routine to exit out of the infinite loop in all ...
5
votes
1answer
188 views

Operand type mismatch when using “jmp *%esp”

I have this snippet in my code void jmp_esp() { __asm__("jmp *%esp"); } when compiling with gcc gcc aslr.c -o aslr -ggdb -fno-stack-protector -z execstack i get this error. aslr.c: Assembler ...
0
votes
1answer
119 views

Long division in ASM x86

I am writing an ASM program that divides two numbers and calculates 20 decimal places. My strategy was to calculate the next digits with a long division sort of process and push them to the stack. ...
0
votes
0answers
19 views

Mips Stack Pointer can't reach next stack value

i'm trying to do a program in mars that , using $sp, can jump to the next address of the stack and read the value: fine_while: add $a0, $S,$a2 li $v0, 1 syscall move $t5, $sp#indirizzo iniziale ...
0
votes
1answer
318 views

Where exactly(!) does the stack pointer point to on x86-CPUs? TO the top element or RIGHT BEHIND it?

In some tutorials it is said that the stack pointer points TO the top element of the stack: +-------------+ | stack | +-------------+ | top element | <-- esp +-------------+ In others it ...
0
votes
3answers
187 views

Compiling an Assembly Program using avr

why do we need to initialize stack pointer in the begnning of the program of AVR assembly programming
1
vote
1answer
176 views

'dds esp' on Windbg

I am not sure if I am understanding the raw output of dds esp or its 64-bit counterpart dqs rsp properly. When I see a list of entries in the stack, I tend to assume that wherever I see return ...
-1
votes
4answers
526 views

In C language, can I access local variable of main function in another function through stack pointer?

I need to access the value of variable a which is defined in main function without passing it as argument. main() { int a=10; func(); printf("%d\n",a); } void func(){ //i need access ...
1
vote
1answer
100 views

$sp register does not change at the beginning of the function

Linked to: How to get a call stack backtrace?(GCC,MIPS,no frame pointer) I am reproducing the call stack(more details at the link above) by iterating the function using the assembly code and user ...
-4
votes
1answer
2k views

Why is Saved Frame Pointer present in a stack frame?

I read that the SFP is used to restore EBP to its previous value. Why does EBP needs to return to it's initial value?
0
votes
2answers
64 views

Extending an ArrayList - fragile-base class

Examining the best practices in Java, we find avoiding inheritance is a good one. One of the reasons maybe illustrated in the following problem: Here we have a sub-class "Stack" extends "ArrayList" ...
0
votes
1answer
584 views

Why does %rbp point to nothing?

It is known that %rsp points to the top of the stack frame and %rbp points to the base of the stack frame. Then I can't understand why %rbp is 0x0 in this piece of code: (gdb) x/4xg $rsp ...
4
votes
1answer
164 views

Why reset the stack pointer register in FreeBSD?

I'm trying to get a grip on assembler in FreeBSD. In the handbook's code example for a UNIX filter the register esp is reset after each system call. The code in question is: %include 'system.inc' ...
4
votes
1answer
83 views

Do I have to clean the stack when I call the C function “exit” from assembly?

I was asked to create a small program in assembly while using C functions. While doing so, I was wondering about something specific. I know that when working with assembly, wherever I want to call a ...
0
votes
1answer
57 views

Stack pointer moved back but values not loaded to register file?

What happens when the stack pointer is moved back to its original position but values that were saved in the stack are not loaded back from the memory into the register file? ie values are still ...
1
vote
2answers
711 views

How to manipulate MIPS code and use stack pointers?

So, I recently made a code to count the number of binary 1's in C-code and in MIPS code. I did so in C by using a remainder value and increment a count_one variable. In MIPS, I did the same program ...
2
votes
1answer
557 views

Making a space for local variables in assembly

So I do have to write an assembly program which would call extern C function. So I wrote simple pow function, I compiled my assembly program with this C code. Everything works. But as I saw from -S ...
0
votes
1answer
142 views

Where is The Value of the Current Stack Pointer Register Stored Before Context Switching In POSIX C Threads

If I were to use pthreads in POSIX environments, and a context switch is about to happen, the current value of the esp register has to be stored somewhere so I can retrieve it when I context switch ...
0
votes
0answers
89 views

Get the Current Value of the Stack Pointer of a POSIX Thread in C

I would like to know if there exists a portable way to retrieve the current stack pointer value in C of a specific POSIX thread, pointed by its thread ID? The only way to get an approximate stack ...
38
votes
2answers
34k views

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

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 ...
0
votes
0answers
43 views

C call stack uses “ebp” to visit variables, then “esp” seems redundant? [duplicate]

C function uses call stack(stack frame) to push/pop registers before/after function call. If ebp is the frame pointer that's used to visit all variables on stack, then seems esp is redundant? Then ...
1
vote
0answers
190 views

How esp register move?

I have a piece of code like this: #include<stdio.h> main() { xxx(1234); } int xxx(int b) { int c; c=b; return c; } I use gdb to show what value of ESP register and how it work ...
3
votes
2answers
666 views

Prologue of “add esp, 0FFFFFFF8h”

I'm a tad bit rusty on my MASM, so I don't really recall what to do here (if anything needs to be done at all). I have a MASM (X86) routine that looks as follows. It has two local variables taking up ...
0
votes
1answer
52 views

vector, sfml and “the value of esp was not properly saved across the function call” error

I have a struct "Layer" and class "LayerHandler". Layer consists only a texture, sprite and two constructors - one default and one with a reference parameter. LayerHandler class is a class that ...
3
votes
3answers
476 views

Using the esp register

I was trying to understand how to use the stack with assembly and in my attempt I came across the following code in one of the questions in SO, namely: push ecx mov eax, 4 mov ebx, 1 mov ecx, ...
1
vote
4answers
2k views

Why do we need to decrement the stack pointer when calling a function

I've been studying assembly for a while now and i'm beginning to get the hang of it, however the one thing that i can't seem to understand is why do we need for decrementing the stack pointer to leave ...
1
vote
1answer
294 views

Incrementing %esp and CDECL

I've been reading up on the x86 stack and the CDECL convention and read something that confused me. Among the caller's responsibilities listed were popping the parameters, using them or simply ...
2
votes
1answer
54 views

Reason for making esp as reference for variables on 32bit OS while rbp on 64bit OS on intel machines?

Below program is giving different output on 32bit and 64bit machine. When i checked its assembly code generated by compiler, i found that reference of variable on 32bit machine was esp while on 64bit ...
0
votes
1answer
370 views

Boost exceptions lead to stack pointer corruption (Run-Time Check Failure #0 …)

In an small project i am using several boost packages (asio, property_tree, filesystem, etc.) and i had to notice, that everything works fine, until an exception gets thrown somewhere in the boost ...
1
vote
4answers
466 views

How does the stack pointer register work

Well, how does the stack work? For example the instruction: push ax is equal to: sub sp, 4 mov sp, ax where sp is a stack pointer. Is that right? My question is - what's the point of subtracting ...
13
votes
4answers
15k views

x86 where stack pointer points?

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 ...
3
votes
1answer
1k views

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

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: ...
0
votes
3answers
578 views

why ESP register is discouraged to use while using PUSH or POP instructions?

I was going through the C code in which i have to figure out the number of registers used in a particular trace of program.The code was neglecting to store ESP register whenever push or pop commands ...
31
votes
2answers
15k views

Base pointer and stack pointer

Given this piece of code: swap: push ebp ; back up the base pointer, mov ebp, esp ; push the context of the registers on the stack push eax ...
2
votes
2answers
2k views

Why does “push ebp” change the value of ebp?

I have a simple code: void func() { func2(); } I omit the implementation of func2 and main since they are irrelevant. Then I used windbg to trace the assembly, following is the output of ...
2
votes
1answer
1k views

The value of ESP was not properly saved… and C/C++ calling conventions

I am writing an application using the OpenCV libraries, the Boost libraries and a pieve of code that I have downloaded from this LINK. I have created a project under the same solution with Thunk32 and ...

http://mssss.yulina-kosm.ru