Sie sind auf Seite 1von 2

Design Implementation of Stack(LIFO) Memory Block

WHAT IS A STACK (last in first out)?


Stack is used to store your local variables and is used for passing arguments to the functions
along with the return address of the instruction which is to be executed after the function call
is over. When a new stack frame needs to be added (as a result of a newly called function),
the stack grows downward. The stack and heap are traditionally located at opposite ends of
the process’s virtual address space. The stack grows automatically when accessed, up to a
size set by the kernel. Implementation of both the stack and heap is usually down to the
runtime/OS. Often games and other applications that are performance critical create their own
memory solutions that grab a large chunk of memory from the heap and then dish it out
internally to avoid relying on the OS for memory.

Stacks in computing architectures are regions of memory where data is added or removed in a
last-in-first-out manner. In most modern computer systems, each thread has a reserved region
of memory referred to as its stack. When a function executes, it may add some of its state
data to the top of the stack; when the function exits it is responsible for removing that data
from the stack. At a minimum, a thread’s stack is used to store the location of function calls
in order to allow return statements to return to the correct location, but programmers may
further choose to explicitly use the stack. If a region of memory lies on the thread’s stack,
that memory is said to have been allocated on the stack. Because the data is added and
removed in a last-in-first-out manner, stack allocation is very simple and typically faster than
heap-based memory allocation (also known as dynamic memory allocation).

Another feature is that memory on the stack is automatically, and very efficiently, reclaimed
when the function exits, which can be convenient for the programmer if the data is no longer
required. If however, the data needs to be kept in some form, then it must be copied from the
stack before the function exits. Therefore, stack based allocation is suitable for temporary
data or data which is no longer required after the creating function exits.A call stack is
composed of stack frames (sometimes called activation records). These are machine
dependent data structures containing subroutine state information. Each stack frame
corresponds to a call to a subroutine which has not yet terminated with a return.

2.DESIGN OF STACK: clk count[1:0]


pop tos[3:0]

push_data[3:0] empty
MTech VLSI & ES,PESIT,BSC Page 3
push full
reset
Design Implementation of Stack(LIFO) Memory Block

popping. Reading is similar but a little simpler. We are reading if asked to pop and there is
data available.

Now for counting the data. We compute a combinational next_count value because that
allows us to register the empty and full outputs. The logic is really quite simple. The count
goes up when we write and don’t read, it goes down if we read and don’t write. Otherwise it
just stays the same.For the memory pointer, if we are writing, then we use the location
pointed to by the count and if we are reading then we will use the location one before.

Writing to the memory is simple enough. If we are writing and not reading then we write the
current top of stack into the RAM. The top of stack will be replaced with what we are
pushing onto the stack. If we are writing and reading, we don’t want to write anything. The
top of stack register will do all the work in this case.

For reading, first we just use a simple register that can map onto the read output register.
Then we create a top of stack “shadow” register. This will hold the value being written to the
top of the stack since we can’t store it in the RAM output register. Only the RAM can do that.
Finally we need a MUX to select who really holds the top of stack value.

Table 1:PORT LIST:

PIN PIN NAME SIAGNAL TYPE INDICATION


NO.

1 clk active high input clock signal is provided to synchronise all


operations in the STACK.

2 reset active high input this signal when asserted high, resets the
stack. All data cleared and flags set to 0.

3 push_data[3:0] 4-bit input it is a 4-bit data input into STACK.

4 push active high input write into STACK signal

5 pop active high input read from STACK signal

6 count[1:0] 2-bit output indicates number of values stored.

7 full active high output signal indicating that STACK is full.

8 empty active high output signal indicating that STACK is empty.

9 tos[3:0] 4-bit output indicates the last value stored onto STACK.

MTech VLSI & ES,PESIT,BSC Page 6

Das könnte Ihnen auch gefallen