Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

asm Stack

Name: Anonymous 2012-01-18 9:13

So I was looking at examples of recursion in asm and how to use the stack and everything I saw would push the stack by subtracting the number of bytes it wanted at the beginning and then add them back at the very end.


Why is it that you have to subtract? Why not add and then subtract at the end?

Name: Anonymous 2012-01-18 9:18

NO EXCEPTIONS

Name: Anonymous 2012-01-18 10:13

>>1
Because the designers of the 8080, 8086, MIPS and other systems that have a downward-growing stack wanted you to put the stack at the top of memory so you could have the program and static data at the bottom, the heap in the middle, and the stack at the top. However, some computers do push by adding and pop by subtracting.

Name: Anonymous 2012-01-18 11:26

>>3
So if my default stack pointer register points to the bottom of the stack rather than the top I should be adding rather than subtracting?

Name: anonandonandon 2012-01-18 19:22

Surely if that stack grew up instead of down we'd get fewer buffer overruns.

Why don't we do that.

Name: Anonymous 2012-01-18 19:56

>>5
It grew down so people could put the stack at the top of RAM and start the program and heap at the bottom. With a 16-bit address space (or even a 32-bit address space these days), this was the simplest way to maximize memory usage and reduce stack overflows. But stupid OSes like Windows put the stack below the main program instead of at 0x7FFFFFFF (unless you force it to), so you get all the buffer overflows and return address smashing of a downward-growing stack without the benefit of a >1 GB stack.
http://chortle.ccsu.edu/assemblytutorial/Chapter-25/ass25_9.html

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List