1. Trang chủ
  2. » Giáo Dục - Đào Tạo

079 the stack kho tài liệu training

38 48 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 38
Dung lượng 567,71 KB

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Nội dung

Stack  Abstract idea for storing data.. Stack  Abstract idea for storing data.. Stack  Abstract idea for storing data.. Example – Saving and restoring  Example: We want to keep the e

Trang 2

Objectives

We learn about the stack data structure

We study the x86 stack implementation and instructions

We see simple examples of using the stack

Trang 3

Stack

 Abstract idea for storing data

 Two operations are allowed: PUSH and POP

 The last element pushed is the first element to be popped

 LIFO - Last In First Out

Trang 4

Stack

 Abstract idea for storing data

 Two operations are allowed: PUSH and POP

 The last element pushed is the first element to be popped

 LIFO - Last In First Out

Trang 5

Stack

 Abstract idea for storing data

 Two operations are allowed: PUSH and POP

 The last element pushed is the first element to be popped

 LIFO - Last In First Out

PUSH

Trang 6

Stack

 Abstract idea for storing data

 Two operations are allowed: PUSH and POP

 The last element pushed is the first element to be popped

 LIFO - Last In First Out

PUSH

Trang 7

Stack

 Abstract idea for storing data

 Two operations are allowed: PUSH and POP

 The last element pushed is the first element to be popped

 LIFO - Last In First Out

PUSH

Trang 8

Stack

 Abstract idea for storing data

 Two operations are allowed: PUSH and POP

 The last element pushed is the first element to be popped

 LIFO - Last In First Out

POP

Trang 9

Stack

 Abstract idea for storing data

 Two operations are allowed: PUSH and POP

 The last element pushed is the first element to be popped

 LIFO - Last In First Out

POP

Trang 10

Stack

 Abstract idea for storing data

 Two operations are allowed: PUSH and POP

 The last element pushed is the first element to be popped

 LIFO - Last In First Out

POP

Trang 11

Stew Dean

Trang 12

ESP

 ESP is a 32 bits register (Extended Stack Pointer)

 At the moment your code begins to run, esp already contains an

address of a location in memory called “the stack”

 ESP and the stack are set up automatically by the operation system

 There are some special instructions that deal with ESP and the stack

esp

sp

… 00 13 2a de 4f 11 00 00 ff ff …

esp

Trang 21

???????? ????????

Trang 22

00000003 ????????

Trang 23

00000003 12345678

Trang 24

Example – Exchanging values

 Exchanging two values:

push eax

push ecx

pop eax

pop ecx

Trang 25

Example – Exchanging values

 Exchanging two values:

Trang 26

Example – Exchanging values

 Exchanging two values:

Trang 27

Example – Exchanging values

 Exchanging two values:

Trang 28

Example – Exchanging values

 Exchanging two values:

Trang 29

Example – Exchanging values

 Exchanging two values:

Trang 30

Example – Exchanging values

 Exchanging two values:

Trang 31

Example – Saving and restoring

 Example: We want to keep the ecx register unchanged.

push ecx

inc ecx

pop ecx

Trang 32

Example – Saving and restoring

 Example: We want to keep the ecx register unchanged.

Trang 33

Example – Saving and restoring

 Example: We want to keep the ecx register unchanged.

Trang 34

Example – Saving and restoring

 Example: We want to keep the ecx register unchanged.

Trang 35

Example – Saving and restoring

 Example: We want to keep the ecx register unchanged.

Trang 36

Example – Saving and restoring

 Example: We want to keep the ecx register unchanged.

Trang 37

Example – Saving and restoring (cont.)

 Keeping a few registers and then restoring them:

 Note the push and pop order

push ecx push eax push ebx

; some code

pop ebx pop eax pop ecx

Trang 38

Summary

 A stack is an abstract idea for storing data

 Only PUSH and POP

 Last In First Out

 x86 stack:

 ESP points to the “top” of the stack

 PUSH decreases esp and writes to the stack

 POP reads from the stack and increases esp

 Examples:

 Exchanging values

 Saving and restoring

esp PUSH POP

Ngày đăng: 17/11/2019, 08:21