Skip to content
Get App

PUSH and POP Instructions in 8086: Understanding Stack Memory

Engineering Funda explains PUSH and POP instructions in the 8086 microprocessor, covering LIFO stack memory, 16-bit register use, and little-endian stack operations.

Key Takeaways

  • The stack follows LIFO order, and PUSH/POP are the instructions used to access it on the 8086
  • PUSH decrements SP by 2 and POP increments SP by 2 because the 8086 works with 16-bit values
  • The 8086 is little-endian, so the lower byte of a register is stored at the lower memory address
  • PUSH and POP operate only on 16-bit registers and cannot take immediate operands

What the video covers

  • Introduces PUSH and POP as the only instructions that work with the 8086 stack segment
  • Explains stack memory as Last In First Out (LIFO) with real-world examples like WhatsApp and email ordering
  • Describes the stack pointer as indicating the top of stack
  • Notes that PUSH and POP do not support immediate addressing mode
  • States that only 16-bit registers (AX, BX, CX, DX, SI, DI) can be used, not 8-bit halves like BL or BH
  • Walks through an example: MOV BX, 2050H followed by PUSH BX and POP CX
  • Explains little-endian storage: the lower byte goes to the lower address and the higher byte to the higher address
  • PUSH decrements the stack pointer by 2 before storing data
  • POP loads data from the stack and then increments the stack pointer by 2
  • Traces how the stack pointer and memory contents change step by step during each operation

Answers

Questions about this video

What does LIFO mean in the context of 8086 stack memory?

LIFO stands for Last In First Out, meaning the data pushed onto the stack last is the first to be popped off. The video illustrates this with data inserted in the order 1, 2, 3, 4 and removed in the order 4, 3, 2, 1.

Why does the stack pointer decrease during a PUSH operation?

The video explains that PUSH decrements the stack pointer by 2 before storing the 16-bit value, because the stack grows toward lower addresses. POP then increments the stack pointer by 2 to reclaim that space.

Can PUSH and POP use 8-bit registers such as BL or BH?

No. The video states that PUSH and POP only work with 16-bit registers such as AX, BX, CX, DX, SI, and DI, and do not accept 8-bit halves like BL or BH.

Full Transcript — Download SRT & Markdown

00:00
Speaker A
welcome to engineering fender family this video is a part of microprocessor 8086 video lecture series and in this video i'll be going to explain you push and pop instructions my dear students before i explain you how push and pop is working with 8086
00:19
Speaker A
there are few very essential things that i would like to discuss with you regarding push and pop my dear students push and pop these two only instructions are working with stack memory interfaced with microprocessor 8086 you should know 8086 can be interfaced
00:43
Speaker A
with memory which is having four memory segments data segment code segment extra segment and stack segment so push and pop is working with stack segment you can say stack memory you should know my dear students there are few very interesting features which
01:03
Speaker A
is there with stack memory stack memory works as per last in first out now what is last in first out let us say you are having memory here in that you want to insert data now first of all when you insert data
01:22
Speaker A
number 1 over here then you insert data 2 here then you insert data 3 here then you insert data 4 here then what is the sequence in which you are inserting data 1 2 3 4 so data number 4 that was last in and
01:38
Speaker A
data number 1 that is first in now when you want to take data out at a time you will be taking data four first out then three then two then one so sequence is four three two one to take
01:54
Speaker A
out data what it means the data which is inserted at last that you will take it out first that is last in first out now you might be thinking like what is the use of this my dear students
02:10
Speaker A
in your daily life there are many applications that is there based on last in first out like you see your whatsapp messenger which data is appearing in front of you first the message which you have received recently so last message
02:29
Speaker A
forwarded to you that is appearing at top right so sequence is last in first out that sequence will be there right for example if you see your email address in that in inbox you observe how emails are there in order
02:49
Speaker A
so the first email that will be the most recent email forwarded to you [Music] right and in sequence there will be emails that will be as per last in first out so you will be observing in this scenario
03:06
Speaker A
they are working as per stack memory right now my dear students let us try to understand how push and pop is working with stack memory so here we have stack memory and when you want to insert data in
03:22
Speaker A
stack memory then you will have to use push instruction so by having push instruction you can load data in stack memory when you want to take data out from stack memory then you have to use pop instruction now what i'll do is i'll explain you few
03:42
Speaker A
basics regarding push and pop after that we will see how exactly it is executed in 8086 along with one practical example so my dear students when we talk about push and pop instructions that is using stack segment of
04:00
Speaker A
8086 you can say stack memory here with 8086 top of stack is indicated by stack pointer so stack pointer is pointing address that will be top of stack here my dear students you should know stack is working as per last in first
04:21
Speaker A
out i have already explained you how it is working and you should know my dear students push and pop does not support immediate addressing mode what is immediate addressing mode my dear students along with instruction you cannot write
04:39
Speaker A
data directly and here with push if you want to write instruction in 8086 then you will have to write resistors only so you cannot directly use data with push and pop so it does not supports immediate addressing mode
04:59
Speaker A
few more things that you should know my dear students push and pop is working with resistor but that resistor should be of 16 bits it means with 8086 we have ax bx cx and dx resistor as well as you can use si di
05:19
Speaker A
to work with push and pop directly but you cannot use bl or bh in terms of 8 bits of resistor so push and pop that is working as per 16 bits of resistor now let us try to understand this by one
05:35
Speaker A
example so that will resolve your understanding furthermore if i write move bx comma two zero phi zero i'll be loading bx with two zero phi zero first then when i do push bx then the value bx which is two zero phi
05:50
Speaker A
zero that are load on stack memory after that when i write pop cx then stack memory is having data which was loaded as per bx data now that i'll move it inside cx but how it will be operating along with
06:08
Speaker A
stack pointer let us try to understand that so when i write mu b x comma 2 0 phi 0 here b x is a combination of b h and b l b bh will be having 2 0 hex data and bl
06:23
Speaker A
that will be having phi 0 hex data and initially let us say stack pointer is pointing this address that is top of stack and you see now addresses are written like this in ascending order right now what i'll be doing is i'll be
06:41
Speaker A
executing push bx instruction so what i should be doing over here i should be loading value of bx that is 2050 hex on stack so here you see i have loaded 2050 hex data on stack now my dear students you might be having
07:02
Speaker A
question what is the order of this data so this 8086 that is little endian that you should know my dear students 8086 or you can say any intel processor is little endian and as per that lower byte that will be loaded on lower
07:25
Speaker A
address and higher byte that will be loaded on higher address so you see here 2 0 5 0 that is having lower byte that is phi 0 so phi 0 is loaded on lower address 1000 hex address will be having 5 0 and 1 000
07:42
Speaker A
one hacks address that will be having 2 0 that is higher byte and here you see stack pointer is decrementing by 2 so as per that you can say now new stack pointer that will be decremented by 2 of
07:56
Speaker A
original location and you see first it will decrement by 1 and when it decrement it by 1 at that time 2 0 that is a data of bh right that will be loaded on stack so stack segment is having stack pointer
08:15
Speaker A
minus 1 and bh is loaded over here and after that again stack pointer is decremented by 1 again means stack pointer is decremented by 2 over here at 1000 hex at this location this bl which is having 50 hex data that we are
08:34
Speaker A
loading so you can say this bl that is getting loaded on stack by having decrementation of stack pointer by 2. so that is how by syntax we can write it now what we are doing is we are executing pop cx
08:50
Speaker A
so what we will be doing over here will be loading data of stack inside cx you see how we do that so when you execute this you see stack pointer now that will increment by 2 and it will load this data of stack into cx
09:06
Speaker A
so obviously now cx will be having data which was there with bx right so you see now cx is having data that is 2 0 5 0.
09:18
Speaker A
how that is happening so for that you see now stack pointer is incremented by 2 with respect to previous stack pointer and if you observe whatever data initially it was there with stack pointer that was phi 0 that
09:33
Speaker A
was the case which was there with bl now this data will be loaded in cl so stack pointers data that is loaded over here with cl and after that stack pointer will increment by 1 and the date of stack pointer
09:50
Speaker A
that is sp plus 1 now that will get loaded in ch and again stack pointer will increment by 1 so resultant stack pointer that will be incremented by 2 after pop so my dear students you should know here when you do push
10:06
Speaker A
and pop operation at that time you are loading data and you are taking data from stack and that will be happening as per little endian here you should understand what is little endian in little endian higher data that will be loaded on
10:21
Speaker A
higher address and lower data that will be loaded on lower address while you push at that time you will be decrementing stack pointer by 2 and when you pop at that time you will be incrementing stack pointer by 2 that is
10:35
Speaker A
how you should remember so push instruction will decrement stack pointer by 2 and it will load data on stack as per little endian and after pop instruction stack pointer will increment by 2 and it will load data of stack into given resistor as per
10:54
Speaker A
little ndn so this is all about basics and execution of push and pop instruction still if you have any query what i want is you just post that in comment box so that we can have further discussion thank you so much for watching this
11:09
Speaker A
video
Topics:8086PUSH instructionPOP instructionstack memoryLIFOstack pointerlittle endianmicroprocessorassembly language8086 stack segment

Get More with the SozAI App

Transcribe recordings, audio files, and YouTube videos — with AI summaries and speaker detection. 30 minutes free.

Or transcribe another YouTube video here →