1
\$\begingroup\$

I'd like to know what is the difference between RAM ( data memory ) and the stack memory in PIC micro controllers if both of them is volatile( not sure about stack ) and the stack is temporary memory?

\$\endgroup\$
2
\$\begingroup\$

All RAM memory requires a constant current to hold its state. That is, as soon as you turn the power off, all of your RAM memory vanishes. Thus, RAM is volatile.

The stack is a specific area of RAM memory used to store temporary variables during program execution. Each function call "pushes" data to the stack. The data is "popped" when the function returns. Because the stack is stored in RAM, it too is volatile.

\$\endgroup\$
2
\$\begingroup\$

In 8-bit-data PIC MCUs, "the" stack is a small area of RAM dedicated to the storage of return addresses only. You cannot access it other than implicitly through CALL and RET instructions.

\$\endgroup\$
0
\$\begingroup\$

When a subroutine is called, the processor pushes the return address on the stack, and may make space for local variables (this can very with processor and compiler). A processor register called the stack pointer contains the address of the next free location on the stack, and is decremented when something is pushed onto the stack, and incremented when something is removed from the stack.

The stack is usually placed at the top of RAM, and extends downward as items are pushed on it.

The stack is usually part of the volatile RAM memory space, but actual implementation may vary between microcontroller families.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.