OSDev.org

The Place to Start for Operating System Developers
It is currently Tue Mar 19, 2024 5:41 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: Is the top and bottom of the stack defined backwards here?
PostPosted: Tue Jul 27, 2021 9:00 pm 
Offline

Joined: Thu Aug 08, 2019 8:21 am
Posts: 17
Reading this page:
https://wiki.osdev.org/Bare_Bones

I noticed this code snippet setting the stack pointer:

Code:
.section .bss
.align 16
stack_bottom:
.skip 16384 # 16 KiB
stack_top:
...
...


As this gets compiled and linked, `stack_bottom` will get a lower memory address than `stack_top`, i.e it will look like this:

Code:
  Low address                                                             High address
[.......... stack_bottom ............... <-- 16 KiB -- > ......... stack_top.........]


The stack point will point to stack_top and grow toward stack_bottom.

But looking at memory layout of C programs, "bottom" should be at the high address and "top" at a lower address:
https://media.cheggcdn.com/media%2Fa00% ... plvboo.png

Shouldn't the labels be reversed in the assembly code?


Top
 Profile  
 
 Post subject: Re: Is the top and bottom of the stack defined backwards her
PostPosted: Tue Jul 27, 2021 11:33 pm 
Offline
Member
Member
User avatar

Joined: Sat Mar 31, 2012 3:07 am
Posts: 4591
Location: Chichester, UK
The Wiki is correct.


Top
 Profile  
 
 Post subject: Re: Is the top and bottom of the stack defined backwards her
PostPosted: Wed Jul 28, 2021 12:13 am 
Offline
Member
Member

Joined: Wed Mar 30, 2011 12:31 am
Posts: 676
The use of "bottom" and "top" in combination with "growing down" can be ambiguous - who's to say the bottom of a stack that grows down isn't the downward side of it?
As long as you point the stack pointer at the correct end, the names aren't too important...

_________________
toaruos on github | toaruos.org | gitlab | twitter | bim - a text editor


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot] and 28 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group