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 ...
1
vote
0
answers
56
views
How to initialize stack pointer in x86 assembler on Linux [duplicate]
Given the example of a simple program for GNU assembler on i386 architecture in Linux:
.section .data
msg: .ascii "Hi, People!\n"
len = . - msg
.section .text
.global _start
_start:
# ...
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
vote
0
answers
104
views
Stack frame contents, pointer to another address within stack frame
I'm trying to learn more about memory and trying to dissect a stack frame. For reference here is the source code that I'm running through gdb.
#include <stdio.h>
void test_function(int a, int b,...
-1
votes
1
answer
111
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 ...
2
votes
1
answer
122
views
Stack is not aligned to 8 bytes on exception entry
I'm writing a mini OS for my STM32F0 board, which has a Cortex-M0 CPU based on the ARMv6-M architecture.
In particular, I'm doing the msp/psp switch after I've created the process queue for the ...
3
votes
1
answer
94
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 ...
1
vote
1
answer
105
views
Can we set the SP register to 0 in x86 assembly real mode?
I was following a tutorial on operating system development, and as a bit of a fanatic, I came across a line in the code that caught my attention:
bits 16
section _ENTRY CLASS=CODE
extern _cstart_
...
0
votes
4
answers
911
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 ...
-1
votes
1
answer
57
views
How to understand the bytes the stack pointer changed when call function
I feel confused about the bytes the stack pointer changes when callq or retq is invoked?
Here’s a little example
; Disassembly of leaf (long y) y in %rdi
0000000000400540 <leaf>:
400540: 48 8d ...
0
votes
1
answer
187
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 ...
22
votes
2
answers
2k
views
How to prepare stack pointer for bare metal Rust?
I'm trying to write an x86 bootloader and operating system completely in Rust (no separate assembly files, only inline assembly within Rust).
My bootloader works completely as intended within the QEMU ...
1
vote
1
answer
152
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 ...
2
votes
2
answers
143
views
If the stack grows downwards, how does it not overlap with other stuff in the address space?
I realized I never really thought of this.
If I made a large enough recursive call chain, wouldn't the stack eventually grow down enough that it will overlap with other things, like shared libraries (...
1
vote
1
answer
635
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 ...
5
votes
1
answer
454
views
Why does the Stack Pointer in MIPS Typically Start at 0x7FFFFFFC but not 0x80000000?
According to Patterson & Hennessy's Computer Organization and Design (MIPS Edition),
the stack pointer $sp is typically initialized to 0x7FFFFFFC.
the stack pointer $sp is always pointing at the ...
2
votes
1
answer
173
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 ) + ...
3
votes
0
answers
261
views
Clang ignores -mstack-alignment=XX flag
This is related to an issue described in this question -- a reproducible example can be found there, as well as a description of the environment (briefly: Apple Silicon with macOS Sonoma and clang 15)....
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 ...
0
votes
0
answers
98
views
I can't use RSP to reference the end of the stack
in my system (x86_64), when I'm using GDB, both RBP and RSP point to the same memory address after pushing a new stack frame, therefore I can't reference the end of the stack with the register RSP ...
1
vote
1
answer
251
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
77
views
Frame, Stack Frame in process Stacking Unstacking
Stacking process
When I talked about the stacking process I was talking about the frame that it would store the data of CPU registers like PC(Program counter) or LR but the advisor said it wasn't and ...
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
567
views
STM32 and SP value at startup: should the reset handler set SP manually?
I am experiencing a sporadic bug on some STM32F7s. While usually SP register takes its initial value from reset vector (stored in persistent read-only memory), sometimes it is initially set to an ...
2
votes
0
answers
210
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
0
answers
842
views
Can I get %rsp with inline assembly?
This question is related to this question: How can I access arguments 7+ using inline assembly?
I understand that accessing the pointers myself is non-standard, potentially unsafe, and not portable.
...
1
vote
1
answer
152
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 ...
0
votes
4
answers
456
views
What is the RUST equivalent of following C code?
I have a small C code which demonstrate Runtime Stack functionality by modifying data at a stack address.
#include <stdio.h>
int * fun() {
int a = 10;
return &a;
}
int * fun2() {
...
1
vote
2
answers
416
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
538
views
How stack memory works when pushing value to it on x86_64?
I have been writing some code in assembly and i found a bug that was overwriting others memory locations and giving to me a segmentation fault, this trouble was made using the rbp register, but the ...
0
votes
1
answer
292
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){
...
1
vote
1
answer
507
views
Why does the stack pointer and frame pointer have the same address?
I was under the impression that the frame pointer $fp is set to the first word of stack according to Computer Organization and Design MIPS 5th ed page 103.
int func(int g) {
int f = 9;
return ...
3
votes
1
answer
334
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
239
views
How can DOS's stack pointer init put a segment just below another segment?
I am learning MS-DOS source
code during that i am in
difficulty with some line of
code:
BIOSSEG: EQU 40H
BIOSLEN: EQU 2048
DOSLEN: EQU 8192
In the next page there are
some lines of code,
INIT:
XOR BP,...
1
vote
1
answer
693
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 ...
1
vote
1
answer
847
views
How to create a dumpRegisters PROC in assembly?
I'm creating a program that shows the registers called dumpRegisters. The registers need to match what is shown in the Registers window in the debugger (using Visual Studio). The registers in the ...
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 ...
1
vote
0
answers
271
views
Why the stack pointer is special in the register file?
I have a question about the register file.
As I know, the stack pointer is one of the special registers in the register file. Why it is determined specifically?
I mean compiler can define any register ...
0
votes
1
answer
971
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 ...
2
votes
1
answer
191
views
Current state of Stack Pointer in 8085
In Intel 8085 microprocessor, is there any way or instruction exist for find out, to where Stack Pointer currently points to?.
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 ...
8
votes
1
answer
325
views
Why GCC generates strange way to move stack pointer
I have observed that GCC's C++ compiler generates the following assembler code:
sub $0xffffffffffffff80,%rsp
This is equivalent to
add $0x80,%rsp
i.e. remove 128 bytes from the stack.
Why does ...
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
; ...
2
votes
0
answers
164
views
I thought 8086's stack grew down, but my memory dump routine shows it growing up?
I'm testing some memory dumping routines in 8086 Assembly based on the one that Keith of Chibiakumas created for displaying registers and showing memory. This routine is a modified version of his that ...
1
vote
1
answer
462
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
2
answers
1k
views
Rust assembly: how do I indicate that I need the value of the SP?
I'm messing around with the asm! macro on an embedded ARM (Thumb) target. I have an interrupt service routine that is designed to get the number that the svc instruction was called with:
#[cortex_m_rt:...
-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
744
views
Write an MIPS program that reads 5 integers and displays them in reversed order
I have already done that, but I don't seem to understand the $sp - Stack pointer fully. As it says that the Stack Pointer $ sp should always point to the last occupied memory cell of the stack. (when ...
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 ...
0
votes
0
answers
265
views
What is the difference between temporary register($t) and stack pointer($sp)
Hi I am studying computer architecture. We learned that we usually use temporary registser($t) to temporarily store values in registers. However, I saw a data that uses the stack pointer ($sp) to ...