Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 604 Vote(s) - 3.51 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Stack in assembly vs stack in c?

#1
I've been wondering whats the difference between stack in C and stack in assembler for processors like RISC or ARM?

Proffesor said, be cautious, stack is different than stack you've learned about on other subject(Algorithms and Structures, where we learn about C)

As far as I can recall, both are just data saved in memory, both function on LastInFirstOut scheme, both need to be cleaned up after usage.

I mean, they cant be the same because they are in two different "worlds" but am I missing something important that differs them? Maybe thats it, but its been bugging me ever since.

Thank you

Reply

#2
The stacks are exactly the same. One can write a program mixed assembly / C and they use the same stack.

The C compiler uses some conventions on how to use the stack : a well-formed stack frame is filled in at each function entry ; and cleaned-up at function leaving. There are compiler directives specific for altering the stack management. For example : [gcc stack checking][1]

Some references on the web : [google : c stack frame][2]

In Assembly, the stack has to be managed entirely by the programmer. It is a good practise to have rules on how to manage the stack (and mimicking C rules for example)

The stack management instructions are also quite processor dependant (instructions like `push` and `pop` on x86, or `stmia` / `ldmfd` on ARM. Similarly, some processors have dedicated registers for stack pointer (`esp` on x86), for some other it is only conventional (`r13` on ARM7.)

A good way to learn on stack management is to use a debugger and do some backtracing to see the frame contents.

For a good understanding of the x86 stack at assembly level, I'd recommend [this Wikipedia article][3] and [this one for stack frames][4]



[1]:

[To see links please register here]

[2]: http://www.google.com/search?hl=en&q...ck%20frame
[3]:

[To see links please register here]

[4]:

[To see links please register here]

Reply

#3
I have seen compilers which use an [overlay](

[To see links please register here]

) model rather than a stack model for their automatic variables. While the language presents the allocation and deallocation of automatic variables as a stack, the underlying implementation does not need to be so.

On some compilers the C stack exists but is separate from the hardware stack.

Then there are concepts like [register-windows](

[To see links please register here]

).

The list goes on, but I couldn't guarantee that any of these are what your professor had in mind, or even that I'm on the right track. There's only one person who can answer that reliably.

Most of these variations are broadly conceptually consistent with stacks, but the implementation details are something you do need to be aware of if you're working with both languages.
Reply

#4
One thing that's different about the conceptual stack vs. an x86 stack (and possibly other architectures) is the direction the stack grows. It's common to teach the stack as growing "up" when (depending on architecture) it may actually grow *down* in memory.
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through