User: alciro    User
 Original    Translate to:  Deutsch  English  Français  中文  
 

Microcontroladores 8051

5.3. Stack or pile

Stack or stack is a data structure with access to the LIFO (Last In First Out), last in, first out. As similarity may be associated with storage in a pile of books, which are stored on each other, new elements are stacked on the last, and brother are removed is removed last to be stacked.

This type of data structure is easy to develop systems for microprocessors and is useful for working with lists of data and is essential for the inner workings of the microprocessor in subroutines and interrupts.

Some chips may have the inside Stack, representing a very fast but limited in size, most microprocessors have the stack in external memory, a fact which provides a large storage capacity and control of location, although access slower.

5.3.1. Stack pointer (stack pointer)

The stack pointer SP (stack pointer) as its name suggests is a record pointer to the memory location where the stack. In the 8051 family register SP is located in the SFR memory 81F.

When you perform a reset the SP register is set automatically with the value 07H, so that the stack is set by default in the 08H position, an area that is used by banks records. It is advisable to change the battery in another area of memory, for example, 30H position (outside the record). To place the stack pointer is set as the first statement of the program:

MOV SP,#2FH ; Situar el puntero del stack en la posición 30H

Stack pointer (stack pointer)

5.3.2. PUSH

The PUSH instruction, located on the stack the contents of the address, first to increase the stack pointer and then follow the contents of the address is copied into RAM indicating the stack pointer SP.

PUSH Instruction Dir

1 º
(SP) = (SP) +1 Increase Stack pointer to the next position
2 º
((SP)) = (Address)
Putting on the stack (address pointed to by SP) content management

Example:

MOV A,#3 ; Cargar el acumulador con la constante 3
MOV B,#5 ; Cargar el registro B con la constante 5
...
...
PUSH A ; Situar en el Stack el contenido del Acumulador
PUSH B ; Situar en el Stack el contenido del registro B

PUSH instruction

5.3.3. POP

POP instruction reads the contents of the address of the stack indicates the SP (stack pointer) and places it in the specified address, then decrements the stack pointer SP leaving the position.

Dir POP Instruction

1 º
  (Address) = ((SP))
Recalls the contents of the address of the stack (pointed to by SP)
2 º
  (SP) = (SP) -1 Stack pointer decremented to the previous position

It should be borne in mind that for the proper functioning of the stack, the last data that is entered must be the first to recover, if we focus on the example above, has been placed on the stack the contents of register A and then B, when retrieving the data has to be done in reverse order entered, first B and then A.

Example:

...
...
POP B ; Recupera en el registro B el contenido del Stack
POP A ; Recupera en el acumulador el contenido del Stack

POP instruction
Loading
copyright © 2007-2021  www.alciro.org  All rights reserved.         
Share |