The x86 Instruction Set

Similar documents
The x86 Architecture

Lecture 15 Intel Manual, Vol. 1, Chapter 3. Fri, Mar 6, Hampden-Sydney College. The x86 Architecture. Robb T. Koether. Overview of the x86

Stack Applications. Lecture 27 Sections Robb T. Koether. Hampden-Sydney College. Wed, Mar 29, 2017

Building the Abstract Syntax Trees

Stack Applications. Lecture 25 Sections Robb T. Koether. Hampden-Sydney College. Mon, Mar 30, 2015

The x87 Floating-Point Unit

EECE.3170: Microprocessor Systems Design I Summer 2017 Homework 4 Solution

List Iterator Implementation

Recursive Descent Parsers

Function Definition Syntax Tree

Stacks and their Applications

Recursive Sequences. Lecture 24 Section 5.6. Robb T. Koether. Hampden-Sydney College. Wed, Feb 27, 2013

The Critical-Path Algorithm

Recursive Sequences. Lecture 24 Section 5.6. Robb T. Koether. Hampden-Sydney College. Wed, Feb 26, 2014

Abstract Syntax Trees Synthetic and Inherited Attributes

Minimal Spanning Trees

Integer Overflow. Lecture 8 Section 2.5. Robb T. Koether. Hampden-Sydney College. Mon, Jan 27, 2014

Computer Systems Organization V Fall 2009

Scheduling and Digraphs

Pointers. Lecture 2 Sections Robb T. Koether. Hampden-Sydney College. Mon, Jan 20, 2014

The Pairwise-Comparison Method

Recursive Linked Lists

Operators. Lecture 12 Section Robb T. Koether. Hampden-Sydney College. Fri, Feb 9, 2018

Programming Languages

Friends and Unary Operators

Scope and Parameter Passing

Sampling Distribution Examples Sections 15.4, 15.5

LR Parsing - Conflicts

Pointers. Lecture 2 Sections Robb T. Koether. Hampden-Sydney College. Fri, Jan 18, 2013

Assembly Language Programming: Procedures. EECE416 uc. Charles Kim Howard University. Fall

Binary Tree Applications

CNIT 127: Exploit Development. Ch 1: Before you begin. Updated

The Traveling Salesman Problem Nearest-Neighbor Algorithm

Practical Malware Analysis

complement) Multiply Unsigned: MUL (all operands are nonnegative) AX = BH * AL IMUL BH IMUL CX (DX,AX) = CX * AX Arithmetic MUL DWORD PTR [0x10]

Microprocessors ( ) Fall 2010/2011 Lecture Notes # 15. Stack Operations. 10 top

The Decreasing-Time Algorithm

Program Exploitation Intro

Recursion. Lecture 26 Sections , Robb T. Koether. Hampden-Sydney College. Mon, Apr 6, 2015

Programming Languages

The Traveling Salesman Problem Brute Force Method

Digital Forensics Lecture 3 - Reverse Engineering

Introduction to Compiler Design

Lecture 20 Sections Wed, Apr 1, 2009

while Loops Lecture 13 Sections Robb T. Koether Wed, Sep 26, 2018 Hampden-Sydney College

Binghamton University. CS-220 Spring x86 Assembler. Computer Systems: Sections

Pointer Arithmetic. Lecture 4 Chapter 10. Robb T. Koether. Hampden-Sydney College. Wed, Jan 25, 2017

Intel assembly language using gcc

Computer Architecture Prof. Smruti Ranjan Sarangi Department of Computer Science and Engineering Indian Institute of Technology, Delhi

Solving Recursive Sequences by Iteration

Compiler construction. x86 architecture. This lecture. Lecture 6: Code generation for x86. x86: assembly for a real machine.

Density Curves Sections

Rotations and Translations

administrivia today start assembly probably won t finish all these slides Assignment 4 due tomorrow any questions?

CSC 8400: Computer Systems. Machine-Level Representation of Programs

Islamic University Gaza Engineering Faculty Department of Computer Engineering ECOM 2125: Assembly Language LAB. Lab # 7. Procedures and the Stack

Computer Systems Lecture 9

Assignment 11: functions, calling conventions, and the stack

UW CSE 351, Winter 2013 Midterm Exam

Recognition of Tokens

SOEN228, Winter Revision 1.2 Date: October 25,

Boolean Expressions. Lecture 31 Sections 6.6, 6.7. Robb T. Koether. Hampden-Sydney College. Wed, Apr 8, 2015

The Model Stack. Lecture 8. Robb T. Koether. Hampden-Sydney College. Wed, Sep 6, 2017

LR Parsing - The Items

Procedure Calls. Young W. Lim Mon. Young W. Lim Procedure Calls Mon 1 / 29

CS412/CS413. Introduction to Compilers Tim Teitelbaum. Lecture 21: Generating Pentium Code 10 March 08

The Class Construct Part 1

Webpage Navigation. Lecture 27. Robb T. Koether. Hampden-Sydney College. Mon, Apr 2, 2018

Ambient and Diffuse Light

X86 Addressing Modes Chapter 3" Review: Instructions to Recognize"

Total Orders. Lecture 41 Section 8.5. Robb T. Koether. Hampden-Sydney College. Mon, Apr 8, 2013

Function Usage. Lecture 15 Sections 6.3, 6.4. Robb T. Koether. Hampden-Sydney College. Mon, Oct 1, 2018

Winter Compiler Construction T11 Activation records + Introduction to x86 assembly. Today. Tips for PA4. Today:

Magnification and Minification

Scope and Parameter Passing

Low-Level Essentials for Understanding Security Problems Aurélien Francillon

The Graphics Pipeline

Procedure Calls. Young W. Lim Sat. Young W. Lim Procedure Calls Sat 1 / 27

Stack -- Memory which holds register contents. Will keep the EIP of the next address after the call

Islamic University Gaza Engineering Faculty Department of Computer Engineering ECOM 2125: Assembly Language LAB

Recursion. Lecture 2 Sections Robb T. Koether. Hampden-Sydney College. Wed, Jan 17, 2018

The Graphics Pipeline

Compiler Construction D7011E

Assembly Language Lab # 9

Linked Lists. Lecture 16 Sections Robb T. Koether. Hampden-Sydney College. Wed, Feb 22, 2017

Sample Exam I PAC II ANSWERS

History of the Intel 80x86

List Iterators. Lecture 27 Section Robb T. Koether. Hampden-Sydney College. Wed, Apr 8, 2015

Fundamental Data Types

4) C = 96 * B 5) 1 and 3 only 6) 2 and 4 only

An Introduction to x86 ASM

Street-Routing Problems

Chapter 3: Addressing Modes

Implementing Linked Lists

XPath Lecture 34. Robb T. Koether. Hampden-Sydney College. Wed, Apr 11, 2012

Credits and Disclaimers

CS241 Computer Organization Spring 2015 IA

Inline Assembler. Willi-Hans Steeb and Yorick Hardy. International School for Scientific Computing

Array Lists. Lecture 15. Robb T. Koether. Hampden-Sydney College. Mon, Feb 22, 2016

Pointers. Lecture 1 Sections Robb T. Koether. Hampden-Sydney College. Wed, Jan 14, 2015

Transcription:

The x86 Instruction Set Lecture 25 Intel Manual, Vols. 2A & 2B Robb T. Koether Hampden-Sydney College Mon, Mar 23, 2015 Robb T. Koether (Hampden-Sydney College) The x86 Instruction Set Mon, Mar 23, 2015 1 / 32

1 The x86 Instruction Set Push and Pop 2 Processing the AST NUM Nodes Nodes DEREF Nodes PLUS Nodes ASSIGN Nodes TIMES Nodes 3 Assignment Robb T. Koether (Hampden-Sydney College) The x86 Instruction Set Mon, Mar 23, 2015 2 / 32

Outline 1 The x86 Instruction Set Push and Pop 2 Processing the AST NUM Nodes Nodes DEREF Nodes PLUS Nodes ASSIGN Nodes TIMES Nodes 3 Assignment Robb T. Koether (Hampden-Sydney College) The x86 Instruction Set Mon, Mar 23, 2015 3 / 32

The Runtime Stack The runtime stack is a portion of memory that is used as a stack during program execution. The address of the top of the stack is stored in the register esp, called the stack pointer. The stack grows in a downward direction. When values are pushed, esp is decremented. When values are popped, esp is incremented. Robb T. Koether (Hampden-Sydney College) The x86 Instruction Set Mon, Mar 23, 2015 4 / 32

The Runtime Stack esp points to the top of the stack. Stack esp Robb T. Koether (Hampden-Sydney College) The x86 Instruction Set Mon, Mar 23, 2015 5 / 32

The Runtime Stack Push the value 100 and decrement esp. Stack 100 esp Robb T. Koether (Hampden-Sydney College) The x86 Instruction Set Mon, Mar 23, 2015 5 / 32

The Runtime Stack Push the value 200 and decrement esp again. Stack 100 200 esp Robb T. Koether (Hampden-Sydney College) The x86 Instruction Set Mon, Mar 23, 2015 5 / 32

The Runtime Stack Pop a value and increment esp. Stack 100 esp Robb T. Koether (Hampden-Sydney College) The x86 Instruction Set Mon, Mar 23, 2015 5 / 32

The Runtime Stack Pop another value and increment esp again. Stack esp Robb T. Koether (Hampden-Sydney College) The x86 Instruction Set Mon, Mar 23, 2015 5 / 32

Outline 1 The x86 Instruction Set Push and Pop 2 Processing the AST NUM Nodes Nodes DEREF Nodes PLUS Nodes ASSIGN Nodes TIMES Nodes 3 Assignment Robb T. Koether (Hampden-Sydney College) The x86 Instruction Set Mon, Mar 23, 2015 6 / 32

The Push and Pop Instructions push and pop Instructions push source pop destination where source is a register, a memory address, or an immediate value. destination is a register or a memory address. Robb T. Koether (Hampden-Sydney College) The x86 Instruction Set Mon, Mar 23, 2015 7 / 32

The Push and Pop Instructions The push instruction will decrement the stack pointer and then move source to the stack. The pop instruction will move the value on the stack to destination and then increment the stack pointer. Robb T. Koether (Hampden-Sydney College) The x86 Instruction Set Mon, Mar 23, 2015 8 / 32

Outline 1 The x86 Instruction Set Push and Pop 2 Processing the AST NUM Nodes Nodes DEREF Nodes PLUS Nodes ASSIGN Nodes TIMES Nodes 3 Assignment Robb T. Koether (Hampden-Sydney College) The x86 Instruction Set Mon, Mar 23, 2015 9 / 32

Processing the Syntax Tree The syntax tree is processed in a left-to-right post-order traversal. At each node Process the left subtree. Process the right subtree. Process the node. Robb T. Koether (Hampden-Sydney College) The x86 Instruction Set Mon, Mar 23, 2015 10 / 32

Using the Stack As each node of the syntax tree is executed, it will leave its result on the run-time stack. The next node will pop that result off the stack (if it needs it) and then push its own result onto the stack (if there is one), and so on. Robb T. Koether (Hampden-Sydney College) The x86 Instruction Set Mon, Mar 23, 2015 11 / 32

Example The syntax tree for a = b + c - 5 is ASSIGN a MINUS PLUS NUM 5 DEREF DEREF b c Robb T. Koether (Hampden-Sydney College) The x86 Instruction Set Mon, Mar 23, 2015 12 / 32

ASSIGN a MINUS PLUS NUM 5 DEREF DEREF b c Robb T. Koether (Hampden-Sydney College) The x86 Instruction Set Mon, Mar 23, 2015 13 / 32

- Push the address of a. ASSIGN a MINUS PLUS NUM 5 DEREF DEREF b c addr(a) Robb T. Koether (Hampden-Sydney College) The x86 Instruction Set Mon, Mar 23, 2015 13 / 32

ASSIGN - Push the address of a. - Push the address of b. a MINUS PLUS NUM 5 DEREF DEREF b c addr(a) addr(a), addr(b) Robb T. Koether (Hampden-Sydney College) The x86 Instruction Set Mon, Mar 23, 2015 13 / 32

a ASSIGN MINUS - Push the address of a. - Push the address of b. DEREF - Pop the address of b, push the value of b. PLUS NUM 5 DEREF DEREF b c addr(a) addr(a), addr(b) addr(a), 10 Robb T. Koether (Hampden-Sydney College) The x86 Instruction Set Mon, Mar 23, 2015 13 / 32

- Push the address of a. a ASSIGN MINUS - Push the address of b. DEREF - Pop the address of b, push the value of b. - Push the address of c. PLUS NUM 5 DEREF DEREF b c addr(a) addr(a), addr(b) addr(a), 10 addr(a), 10, addr(c) Robb T. Koether (Hampden-Sydney College) The x86 Instruction Set Mon, Mar 23, 2015 13 / 32

- Push the address of a. a ASSIGN PLUS MINUS NUM 5 - Push the address of b. DEREF - Pop the address of b, push the value of b. - Push the address of c. DEREF - Pop the address of c, push the value of c. DEREF DEREF b c addr(a) addr(a), addr(b) addr(a), 10 addr(a), 10, addr(c) addr(a), 10, 20 Robb T. Koether (Hampden-Sydney College) The x86 Instruction Set Mon, Mar 23, 2015 13 / 32

- Push the address of a. a ASSIGN PLUS MINUS NUM 5 - Push the address of b. DEREF - Pop the address of b, push the value of b. - Push the address of c. DEREF - Pop the address of c, push the value of c. PLUS - Pop two values, add them, push the result. DEREF DEREF b c addr(a) addr(a), addr(b) addr(a), 10 addr(a), 10, addr(c) addr(a), 10, 20 addr(a), 30 Robb T. Koether (Hampden-Sydney College) The x86 Instruction Set Mon, Mar 23, 2015 13 / 32

- Push the address of a. a ASSIGN MINUS PLUS DEREF DEREF NUM 5 - Push the address of b. DEREF - Pop the address of b, push the value of b. - Push the address of c. DEREF - Pop the address of c, push the value of c. PLUS - Pop two values, add them, push the result. NUM - Push 5. b c addr(a) addr(a), addr(b) addr(a), 10 addr(a), 10, addr(c) addr(a), 10, 20 addr(a), 30 addr(a), 30, 5 Robb T. Koether (Hampden-Sydney College) The x86 Instruction Set Mon, Mar 23, 2015 13 / 32

- Push the address of a. a ASSIGN MINUS PLUS DEREF DEREF NUM 5 - Push the address of b. DEREF - Pop the address of b, push the value of b. - Push the address of c. DEREF - Pop the address of c, push the value of c. PLUS - Pop two values, add them, push the result. NUM - Push 5. MINUS - Pop two values, subtract them, push the result. b c addr(a) addr(a), addr(b) addr(a), 10 addr(a), 10, addr(c) addr(a), 10, 20 addr(a), 30 addr(a), 30, 5 addr(a), 25 Robb T. Koether (Hampden-Sydney College) The x86 Instruction Set Mon, Mar 23, 2015 13 / 32

- Push the address of a. a ASSIGN MINUS PLUS DEREF DEREF b c NUM 5 - Push the address of b. DEREF - Pop the address of b, push the value of b. - Push the address of c. DEREF - Pop the address of c, push the value of c. PLUS - Pop two values, add them, push the result. NUM - Push 5. MINUS - Pop two values, subtract them, push the result. ASSIGN - Pop the value and the address, store the value at the address, push the result. addr(a) addr(a), addr(b) addr(a), 10 addr(a), 10, addr(c) addr(a), 10, 20 addr(a), 30 addr(a), 30, 5 addr(a), 25 25 Robb T. Koether (Hampden-Sydney College) The x86 Instruction Set Mon, Mar 23, 2015 13 / 32

Outline 1 The x86 Instruction Set Push and Pop 2 Processing the AST NUM Nodes Nodes DEREF Nodes PLUS Nodes ASSIGN Nodes TIMES Nodes 3 Assignment Robb T. Koether (Hampden-Sydney College) The x86 Instruction Set Mon, Mar 23, 2015 14 / 32

A NUM Node Example (A NUM Node) push $5 A NUM node loads the integer whose value is stored in the node. For example, to load 5. Robb T. Koether (Hampden-Sydney College) The x86 Instruction Set Mon, Mar 23, 2015 15 / 32

Outline 1 The x86 Instruction Set Push and Pop 2 Processing the AST NUM Nodes Nodes DEREF Nodes PLUS Nodes ASSIGN Nodes TIMES Nodes 3 Assignment Robb T. Koether (Hampden-Sydney College) The x86 Instruction Set Mon, Mar 23, 2015 16 / 32

An Node Example (An Node) lea a,%eax push %eax A node pushes the address of the name that is stored in the node. For example, to push the address a. The actual address of a is not known when the program is assembled. Thus, the object code does not contain the correct address of a. The address becomes known when the program is loaded into main memory to be executed. At that time, lea will produce the actual address. Robb T. Koether (Hampden-Sydney College) The x86 Instruction Set Mon, Mar 23, 2015 17 / 32

Outline 1 The x86 Instruction Set Push and Pop 2 Processing the AST NUM Nodes Nodes DEREF Nodes PLUS Nodes ASSIGN Nodes TIMES Nodes 3 Assignment Robb T. Koether (Hampden-Sydney College) The x86 Instruction Set Mon, Mar 23, 2015 18 / 32

A DEREF Node Example (The DEREF Node) pop %eax push (%eax) A DEREF node expects to find a memory address on top of the stack. It pushes the value stored at that address. The parentheses mean the value at the address in the register. This is the indirect addressing mode. Robb T. Koether (Hampden-Sydney College) The x86 Instruction Set Mon, Mar 23, 2015 19 / 32

Outline 1 The x86 Instruction Set Push and Pop 2 Processing the AST NUM Nodes Nodes DEREF Nodes PLUS Nodes ASSIGN Nodes TIMES Nodes 3 Assignment Robb T. Koether (Hampden-Sydney College) The x86 Instruction Set Mon, Mar 23, 2015 20 / 32

The add Instruction The add Instruction add source,destination where source is a register, a memory address, or an immediate value. destination is a register or a memory address. The value at source is added to the value at destination and the result is stored at destination Robb T. Koether (Hampden-Sydney College) The x86 Instruction Set Mon, Mar 23, 2015 21 / 32

A PLUS Node Example (A PLUS Node) pop %edx pop %eax add %edx,%eax push %eax A PLUS node expects to find two numbers on the stack. The right operand should be on top. It pops the values, adds them, and pushes the result. Robb T. Koether (Hampden-Sydney College) The x86 Instruction Set Mon, Mar 23, 2015 22 / 32

Outline 1 The x86 Instruction Set Push and Pop 2 Processing the AST NUM Nodes Nodes DEREF Nodes PLUS Nodes ASSIGN Nodes TIMES Nodes 3 Assignment Robb T. Koether (Hampden-Sydney College) The x86 Instruction Set Mon, Mar 23, 2015 23 / 32

An ASSIGN Node Example (An ASSIGN Node) pop %eax pop %edx mov %eax,(%edx) push %eax An ASSIGN node expects to find an address and a value on the stack. The value should be on top. It pops the value and the address, stores the value at the address, and pushes the value. Robb T. Koether (Hampden-Sydney College) The x86 Instruction Set Mon, Mar 23, 2015 24 / 32

Outline 1 The x86 Instruction Set Push and Pop 2 Processing the AST NUM Nodes Nodes DEREF Nodes PLUS Nodes ASSIGN Nodes TIMES Nodes 3 Assignment Robb T. Koether (Hampden-Sydney College) The x86 Instruction Set Mon, Mar 23, 2015 25 / 32

The imul Instruction The imul instruction performs multiplication of signed integers. There are three formats. For each format, the destination is edx:eax, which holds a 64-bit value. Robb T. Koether (Hampden-Sydney College) The x86 Instruction Set Mon, Mar 23, 2015 26 / 32

The imul Instruction The imul Instruction (Type 1) imul source where source is one operand. eax is the other operand. Robb T. Koether (Hampden-Sydney College) The x86 Instruction Set Mon, Mar 23, 2015 27 / 32

The imul Instruction The imul Instruction (Type 2) imul register,source where source is a register, a memory address, or an immediate value. register is the destination. Robb T. Koether (Hampden-Sydney College) The x86 Instruction Set Mon, Mar 23, 2015 28 / 32

The imul Instruction The imul Instruction (Type 3) imul register,source,immediate where register is the destination. source is a register, a memory address, or an immediate value. immediate is a number. Robb T. Koether (Hampden-Sydney College) The x86 Instruction Set Mon, Mar 23, 2015 29 / 32

A TIMES Node Example (A TIMES Node) pop %eax pop %ecx imul %ecx push %eax A TIMES node expects to find two values on the stack. It pops them, multiplies them, and pushes the result. Robb T. Koether (Hampden-Sydney College) The x86 Instruction Set Mon, Mar 23, 2015 30 / 32

Outline 1 The x86 Instruction Set Push and Pop 2 Processing the AST NUM Nodes Nodes DEREF Nodes PLUS Nodes ASSIGN Nodes TIMES Nodes 3 Assignment Robb T. Koether (Hampden-Sydney College) The x86 Instruction Set Mon, Mar 23, 2015 31 / 32

Assignment Assignment Read the descriptions of the above operations in the Intel Manual, Vols. 2A and 2B. Also, look up and read about subtraction and division. Robb T. Koether (Hampden-Sydney College) The x86 Instruction Set Mon, Mar 23, 2015 32 / 32