Microprocessor & assembly language

15
Welcome To Our Presentation

description

 

Transcript of Microprocessor & assembly language

Page 1: Microprocessor & assembly language

Welcome To Our Presentation

Page 2: Microprocessor & assembly language

Presentation Topic :

PUSH, PUSHF, POP, POPF

Presented By :

Page 3: Microprocessor & assembly language

Contents : The Stack Push Pop PushF PopF

Page 4: Microprocessor & assembly language

A stack in one-dimensional data structure. Items are added and removed from one end of the structure; that is, it is processed in a “Last-in, first out” manner. The most recent addition to the stack is called the top of the stack.

A program must set aside a block of memory to hold the stack.

We have been dong this by declaring a stack segment ;

For example :

.STACK 100H

THE STACK

Page 5: Microprocessor & assembly language

To add a new word to the stack we PUSH it on. The syntax is

PUSH source

Where source is a 16-bit register or memory word.

For example,

PUSH AX

Execution of PUSH causes the following to happen :

1. SP is decreased by 2.

2. A copy of the source content is moved to the address specified by SS:SP. The source is unchanged.

PUSH AND PUSHF

Page 6: Microprocessor & assembly language

The instruction PUSHF, which has no operands, pushes the contents of the FLAGS register onto the stack.

Initially SP contains the offset address of the memory location immediately following the stack segment; the first PUSH decreases SP by 2, making it point to the last word in the stack segment. Because each PUSH decreases SP, the stack grows toward the beginning of memory

PUSH AND PUSHF

Page 7: Microprocessor & assembly language

FIGURE : EMPTY STACKoffset

00F0

00F2

00FA

00F4

00F6

00F8

00FC

00FE

0100

1234

SP

5678

0100

AX

BX

STACK(empty)

SP

Page 8: Microprocessor & assembly language

FIGURE : AFTER PUSH AXoffset

00F0

00F2

00FA

00F4

00F6

00F8

00FC

00FE

0100

1234

1234

SP

5678

00FE

AX

BX

STACK

SP

Page 9: Microprocessor & assembly language

FIGURE : AFTER PUSH BXoffset

00F0

00F2

00FA

00F4

00F6

00F8

00FC

00FE

0100

5678

1234

1234

SP

5678

00FC

AX

BX

STACK

SP

Page 10: Microprocessor & assembly language

To remove the top item from the stack we POP it. The Syntax is

POP destination

Where destination is a 16-bit register (except IP) or memory word. For example,

POP BX

Executing POP causes this to happen:

1. The content of SS:SP (the top the stack) is moved to the destination

2. SP is increased by 2.

POP AND POPF

Page 11: Microprocessor & assembly language

The instruction POPF pops the top of the stack into the FLAGS

Register. There is no effect of PUSH, PUSHF, POP, POPF on the flags.

Such as

Illegal : PUSH DL

Is illegal. So is a push of immediate data, such as

Illegal : PUSH 2

Page 12: Microprocessor & assembly language

FIGURE : BEFORE POPoffset

00F0

00F2

00FA

00F4

00F6

00F8

00FC

00FE

0100

5678

1234

FFFF

SP

0001

00FC

CX

DX

STACk

SP

Page 13: Microprocessor & assembly language

FIGURE : AFTER POP CXoffset

00F0

00F2

00FA

00F4

00F6

00F8

00FC

00FE

0100

5678

1234

5678

SP

0001

00FE

CX

BX

STACK

SP

Page 14: Microprocessor & assembly language

FIGURE : AFTER POP DXoffset

00F0

00F2

00FA

00F4

00F6

00F8

00FC

00FE

0100

5678

1234 5678

SP

1234

0100

CX

DX

STACK(empty)

SP

Page 15: Microprocessor & assembly language

THANK YOU END