Monday, 9 September 2013

How to define or initialized the stack in program?

It is very good question that How to define or initialized the stack in program? And before
starting the answer i should mention please see my previous post regarding 

Video Tutorial: What is a stack and use of it ?
 Now getting the answer of How to define or initialized the stack in program? The most important thing which we have to remember when we are using stack in program that the stack should be initialized at the high end of the memory map. Now question is why stack should be initialized at the high end of the memory map? See the block diagram first





 From this block diagram you may understand that the user program should start at the low end of the memory map, while the stack should be initialized at the high end of the memory map. Because when the program is being executed, the PC (Program Counter) is auto-incremented now look at stack while we want to store temporary data in the stack, it is auto-decremented. Thus we should maintain sufficient gap between main programs and stack if sufficient gap is not maintained, the program area may get corrupted by the filling-in of the stack. In such a case, the program will ‘crash’.


Now question is how to define or initialized the stack in program?

In the program a programmer can initialized or define the stack by means of the stack pointer. And the software instruction for defining stack pointer is like this: LXI SP, FFFF H.


It means that the stack is initiated at the memory location FFFF H by the stack pointer.

You can download this study notes in Pdf format by clicking on download . DOWNLOAD 

No comments:

Post a Comment