[go: up one dir, main page]

0% found this document useful (0 votes)
51 views3 pages

PUSH and POP Operations

Uploaded by

atulitbhai
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
51 views3 pages

PUSH and POP Operations

Uploaded by

atulitbhai
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Que :Demonstrate PUSH and POP operations and their impact on the stack

in the 8086 Microprocessor.

The Stack in 8086

In the 8086 microprocessor, the stack is an essential data structure that


operates on a Last-In, First-Out (LIFO) basis.

It serves as a designated memory area for temporarily storing data, return


addresses for subroutines, and local variables.

The stack is controlled by two 16-bit registers.

The Stack Segment Register (SS)

This register is a vital part of the 8086 microprocessor's memory


management system, characterized by the following features: ·

 It is a 16-bit register.
 It indicates the current stack and holds the base address of the stack
memory segment.
 The 20-bit physical stack address is derived from the Stack Segment
(SS) and the Stack Pointer (SP) for stack instructions like PUSH and
POP.
 In Based addressing mode, the 20-bit physical stack address is
calculated using the Stack Segment (SS) and the Base Pointer (BP)
with the formula (SS×10h)+BP.

Stack Pointer (SP) and Base Pointer (BP)

 SP and BP are utilized to access data within the stack segment.


 SP acts as an offset from the current SS during the execution of
instructions involving the stack segment in external memory.
 The contents of SP are automatically updated (incremented or
decremented) when a POP or PUSH instruction is executed.
 BP holds an offset address in the current SS, used by instructions
employing the based addressing mode.
 The stack expands downward in memory, meaning that as new data is
added to the stack, the SP register decreases.
1. PUSH Operation

 The PUSH instruction is employed to add a 16-bit word to the top


of the stack.
Syntax: PUSH source (where the source can be a 16-bit register, a
memory location, or an immediate value).
 The PUSH operation involves two steps:
First, the SP register is decreased by 2 (since the stack stores 16-bit
words). Then, the content of the source is copied to the memory
location indicated by the new value of SS:SP.

Example:

PUSH AX

Before: Let's assume SP contains 1000h and AX contains 1234h.

Action: The instruction first decrements SP from 1000h to 0FFEh. Then, the
value 1234h from AX is copied to the memory location at SS:0FFEh.

After: SP is now 0FFEh, and the value 1234h is at the new top of the stack.

2. POP Operation

 The POP instruction is used to extract a 16-bit word from the top
of the stack.
Syntax: POP destination (where the destination can be a 16-bit
register or a memory location).
 The POP operation also consists of two steps:
The content of the memory location pointed to by SS:SP is transferred
to the destination operand. Subsequently, the SP register is increased
by 2, effectively removing the item from the stack (although the data
remains in memory until it is overwritten).

Example:

POP BX
Before: Let's assume SP contains 0FFEh and the value 1234h is at the top of
the stack (SS:0FFEh). The BX register has an unknown value.

Action: The instruction first copies the value 1234h from SS:0FFEh into BX.
Then, SP is incremented from 0FFEh to 1000h.

After: BX now contains 1234h, and SP is restored to 1000h.

Thus the PUSH and POP operations work in reverse order confirming the
LIFO nature of the stack. These instructions are crucial for saving register
contents during subroutine calls and managing temporary data.

You might also like