181 questions
17
votes
3
answers
1k
views
Stack memory in a freestanding environment
I'm reading a GNU as introductory book for programs running on top of an OS. I'm at the stack memory part and I was curious how the stack looks like in a freestanding environment.
I'm guessing that ...
0
votes
1
answer
74
views
Null in a dereferenced Stack Pointer in Rust on Cortex-M4 (nRF52833)
When developing a Rust no_std bootloader for my micro:bit v2.21 (Cortex-M4, nRF52833), I have encountered a weird error.
The bootloader jumps to the main application using cortex_m::asm::bootstrap(sp, ...
-1
votes
1
answer
106
views
(ARM assembly) how to address elements on the stack relative to the sp
How can I address elements on the stack that are not on top of it? I am talking about for instance first executing stmfd sp!, {r0-r12} and then push {lr}. Now I want to work with the first address of ...
3
votes
1
answer
90
views
Does a write to SP on ARMv8 also write to SP_ELx?
I have been attempting to read through the ARM manual to gain an understanding of how ARM works architecturally. I know that there is a system register for SP at each EL, like SP_EL0, SP_EL1, etc. I ...
0
votes
4
answers
898
views
How does stack pointer works on STM32F103
I have recently become interested in linker scripts and assembly coding for MCUs. I just discovered that the first thing we do in the reset_handler is set the stack pointer register (sp).
My question ...
0
votes
1
answer
185
views
riscv stack pointer initialization
I am using https://www.qemu.org/docs/master/system/riscv/virt.html to compile some code that prints 'U' out the uart.
My question is about stack initialization. I am assuming I can do this various ...
1
vote
1
answer
146
views
How to get the stack pointer and return address and restore them to a previous state
I'm trying to implement a poor man's call with current continuation for a program written in C. I can "easily" access and memcpy the relevant part of the C stack (obviously, that's not ...
1
vote
1
answer
614
views
ARM Cortex-M PC and SP values - reset behavior
I am trying to understand the ARM cortex-M hardware behavior on reset; particularly how the SP and PC values are written upon a cold start or hard reset.
Basically, it would seem the hardware (aka PE ...
2
votes
1
answer
171
views
Using end of memory address as process stack pointer value causing INVPC hard fault
In STM32L432KC(arm cortex-m4+FPU) there are two ram memory blocks. Following is a snippet from the linker script I use.
_e_ram2_stack = ORIGIN(RAM2) + LENGTH(RAM2);
_e_ram_stack = ORIGIN(RAM ) + ...
0
votes
1
answer
305
views
Cortex M4 stacking and unstacking with a diferent stack pointer
It is possible to achieve this in a cortex-m4? What i mean is having PSP only on that intervals, and all the rest MSP when there is an interrupt?
The objective is just to do the stacking and ...
1
vote
1
answer
250
views
STM8 Assembly startup code: Access Core registers to initialize stack pointer
I am currently trying to write startup code in assembly for an STM8 without any vendor libraries. More specifically, I am using an STM8S103f3p6. I am still inexperienced in assembly and with startup ...
0
votes
1
answer
107
views
Stack pointer add on loop
Learning some reverse engineering and I came across some examples of loops in x86 assembly
00401036 mov [ebp+var_4], 0
0040103D mov [ebp+var_8], 0
00401044 loc_401044:
00401044 ...
2
votes
0
answers
209
views
What happens in the CPU if I pop / push all the stack?
I am doing an energy profile of an ARM processor for an academic project. I managed to measure the power consumption of several assembly instructions by running them in a ~200 insts loop, e.g.:
.rept ...
1
vote
1
answer
145
views
Storing and Loading $ra
I'm currently having trouble writing this recursive factorial assembly code in MIPS. I do not want to change the format of this code, as it is for a project, but I want to understand how to store or ...
1
vote
2
answers
412
views
What is the benefit of having a dedicated stack pointer register?
As a more specific question for assembly - Why make ISA be aware of the existence of "stack" concept? - Stack Overflow and suggested by @xiver77, what is the benefit of having a dedicated ...
0
votes
1
answer
291
views
Why does printf make a segmentation fault if there is no \n?
To learn multithreading, I use code given by the teacher, that works for my classmates, but not for me.
The error happens here:
void fonction2(){
int compteur1 = 1;
while(1){
...
3
votes
1
answer
329
views
why rsp register starts at 0x7FFFFFFFDFD0
im learning x86 assembly, using the code below for testing, i see in gdb console that the rsp register which points at the top of the stack starts at 0x7FFFFFFFDFD0, if i understand correctly, in the ...
1
vote
1
answer
692
views
why stack pointer is initialized to the maximum value?
why stack pointer is initialized to the maximum value?
I only knows that It is the tiny register which stores the last program request’s address in a stack. It is the particular kind of buffer that ...
0
votes
1
answer
108
views
Stack pointer set correctly but call not working
I'm using TI Code Composer Studio for the MSP430F1232.
Starting from a template in assembler, a call to a routine doesn't work but when I put the routine directly in the code,it works. Why does the ...
0
votes
1
answer
965
views
8051 Assembly Language - Stack pointer initialization
Considering the 8051 micro controller RAM organization, I would like to set my stack pointer to address 30h.
I would like to know if I have to do it only once in the beginning of my program, or is it ...
3
votes
1
answer
1k
views
What Is The Initial Value of Stack Pointer of 8086 (x86-16) CPU?
What is the initial value of SS, SP, BP? Are they null (0x0) or for example does SP immediately set to 0xFFFE?
When we write an assembly code without using pop and push statements does stack pointer ...
1
vote
0
answers
53
views
segmentation fault after linking c++ file with asm file [duplicate]
still me. I am following the sample code given in a book but I got a segmentation fault error when linking extern asm file with cpp file
Could someone tell me what the issue is:
global _integer_add
; ...
1
vote
1
answer
461
views
Why is value of RSP higher than RBP as displayed in GDB?
I am inspecting a process (which has no bugs actually) with gdb.
However I noticed, when doing info registers, that RSP is higher than RBP, which is not consistent with the fact that the stack grows ...
-2
votes
1
answer
781
views
What is the initial value of `ESP`?
Under Visual Studio masm:
mov ecx,270
l1: pop eax
loop l1
push eax
The point of this code is to find out if there is and what is the initial value of ESP. I try to pop immediately after ...
0
votes
0
answers
2k
views
Can you push/pop a 32-bit register in a 64-bit program? [duplicate]
It seems that, while a 32-bit program can push/pop either 2 or 4 bytes to the stack, a 64-bit program has no choice but to push/pop 8 bytes at a time. Is there really no way to push/pop a 4-byte value ...