Access. Young W. Lim Fri. Young W. Lim Access Fri 1 / 18

Similar documents
Access. Young W. Lim Sat. Young W. Lim Access Sat 1 / 19

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

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

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

The x86 Architecture

CS241 Computer Organization Spring 2015 IA

Link 4. Relocation. Young W. Lim Thr. Young W. Lim Link 4. Relocation Thr 1 / 26

Stack Tutorial. Young W. Lim Sat. Young W. Lim Stack Tutorial Sat 1 / 15

MODE (mod) FIELD CODES. mod MEMORY MODE: 8-BIT DISPLACEMENT MEMORY MODE: 16- OR 32- BIT DISPLACEMENT REGISTER MODE

Arrays. Young W. Lim Mon. Young W. Lim Arrays Mon 1 / 17

Arrays. Young W. Lim Wed. Young W. Lim Arrays Wed 1 / 19

UMBC. A register, an immediate or a memory address holding the values on. Stores a symbolic name for the memory location that it represents.

Credits and Disclaimers

Turning C into Object Code Code in files p1.c p2.c Compile with command: gcc -O p1.c p2.c -o p Use optimizations (-O) Put resulting binary in file p

Assembly Language Each statement in an assembly language program consists of four parts or fields.

Assembly Language: Function Calls

Credits and Disclaimers

Assembly Language: Function Calls" Goals of this Lecture"

Assembly level Programming. 198:211 Computer Architecture. (recall) Von Neumann Architecture. Simplified hardware view. Lecture 10 Fall 2012

Assembly Language: Function Calls" Goals of this Lecture"

Assembly Language: Function Calls. Goals of this Lecture. Function Call Problems

CS 31: Intro to Systems ISAs and Assembly. Martin Gagné Swarthmore College February 7, 2017

x86 Assembly Tutorial COS 318: Fall 2017

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

CSE2421 FINAL EXAM SPRING Name KEY. Instructions: Signature

Software. Hardware. x86 basics. ISA View. a brief history of x86 10/6/15. Program, Application. Programming Language. Compiler/Interpreter

EXPERIMENT WRITE UP. LEARNING OBJECTIVES: 1. Get hands on experience with Assembly Language Programming 2. Write and debug programs in TASM/MASM

Registers. Ray Seyfarth. September 8, Bit Intel Assembly Language c 2011 Ray Seyfarth

Addressing Modes on the x86

CS165 Computer Security. Understanding low-level program execution Oct 1 st, 2015

Machine-Level Programming Introduction

The von Neumann Machine

Module 3 Instruction Set Architecture (ISA)

Instruction Set Architectures

Assembly Language Lab # 9

Assembly Language: IA-32 Instructions

This is a medical robot, guided by a skilled surgeon and designed to get to places doctors are unable to reach without opening a pacent up.

The Microprocessor and its Architecture

Stack Debugging. Young W. Lim Sat. Young W. Lim Stack Debugging Sat 1 / 40

X86 Review Process Layout, ISA, etc. CS642: Computer Security. Drew Davidson

Function Calls COS 217. Reading: Chapter 4 of Programming From the Ground Up (available online from the course Web site)

CS241 Computer Organization Spring Introduction to Assembly

MACHINE-LEVEL PROGRAMMING I: BASICS COMPUTER ARCHITECTURE AND ORGANIZATION

Assembler Programming. Lecture 2

Control. Young W. Lim Mon. Young W. Lim Control Mon 1 / 16

Hardware and Software Architecture. Chapter 2

Interfacing Compiler and Hardware. Computer Systems Architecture. Processor Types And Instruction Sets. What Instructions Should A Processor Offer?

CS642: Computer Security

CS 31: Intro to Systems ISAs and Assembly. Kevin Webb Swarthmore College February 9, 2016

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

Introduction to IA-32. Jo, Heeseung

CS 31: Intro to Systems ISAs and Assembly. Kevin Webb Swarthmore College September 25, 2018

Instruction Set Architectures

Assembly I: Basic Operations. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

INTRODUCTION TO IA-32. Jo, Heeseung

Intro to GNU Assembly Language on Intel Processors

CPEG421/621 Tutorial

Link 4. Relocation. Young W. Lim Wed. Young W. Lim Link 4. Relocation Wed 1 / 22

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

x86 Programming I CSE 351 Winter

Chapter 3: Addressing Modes

Machine-Level Programming Introduction

ADDRESSING MODES. Operands specify the data to be used by an instruction

Machine-Level Programming II: Control and Arithmetic

Question 4.2 2: (Solution, p 5) Suppose that the HYMN CPU begins with the following in memory. addr data (translation) LOAD 11110

Code segment Stack segment

Sungkyunkwan University

Reverse Engineering II: Basics. Gergely Erdélyi Senior Antivirus Researcher

Reverse Engineering II: The Basics

x86 architecture et similia

Link 2. Object Files

Link 2. Object Files

Machine/Assembler Language Putting It All Together

Instruction Set Architecture (ISA) Data Types

Machine-level Programming (3)

x86 64 Programming I CSE 351 Autumn 2018 Instructor: Justin Hsia

Introduction to Machine/Assembler Language

The von Neumann Machine

Meet & Greet! Come hang out with your TAs and Fellow Students (& eat free insomnia cookies) When : TODAY!! 5-6 pm Where : 3rd Floor Atrium, CIT

Chapter 11. Addressing Modes

EEM336 Microprocessors I. Addressing Modes

Machine-level Representation of Programs. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

x86 Programming I CSE 351 Autumn 2016 Instructor: Justin Hsia

Homework. In-line Assembly Code Machine Language Program Efficiency Tricks Reading PAL, pp 3-6, Practice Exam 1

We can study computer architectures by starting with the basic building blocks. Adders, decoders, multiplexors, flip-flops, registers,...

Complex Instruction Set Computer (CISC)

CMSC Lecture 03. UMBC, CMSC313, Richard Chang

CS 31: Intro to Systems Functions and the Stack. Martin Gagne Swarthmore College February 23, 2016

6/20/2011. Introduction. Chapter Objectives Upon completion of this chapter, you will be able to:

Instruction Set Architectures

CSC 2400: Computer Systems. Towards the Hardware: Machine-Level Representation of Programs

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

AS08-C++ and Assembly Calling and Returning. CS220 Logic Design AS08-C++ and Assembly. AS08-C++ and Assembly Calling Conventions

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

Introduction to 8086 Assembly

Assembly III: Procedures. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

Scott M. Lewandowski CS295-2: Advanced Topics in Debugging September 21, 1998

Lecture 3: Instruction Set Architecture

x86 assembly CS449 Spring 2016

1 /* file cpuid2.s */ 4.asciz "The processor Vendor ID is %s \n" 5.section.bss. 6.lcomm buffer, section.text. 8.globl _start.

Transcription:

Access Young W. Lim 2017-01-27 Fri Young W. Lim Access 2017-01-27 Fri 1 / 18

Outline 1 Introduction References IA32 Operand Forms Data Movement Instructions Young W. Lim Access 2017-01-27 Fri 2 / 18

Based on "Self-service Linux: Mastering the Art of Problem Determination", Mark Wilding "Computer Architecture: A Programmer s Perspective", Bryant & O Hallaron I, the copyright holder of this work, hereby publish it under the following licenses: GNU head Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A copy of the license is included in the section entitled GNU Free Documentation License. CC BY SA This file is licensed under the Creative Commons Attribution ShareAlike 3.0 Unported License. In short: you are free to share and make derivative works of the file under the conditions that you appropriately attribute it, and that you distribute it only under a license compatible with this one. Young W. Lim Access 2017-01-27 Fri 3 / 18

Operand Types 1 Immediate Operand Type 2 Register Operand Type 3 Memory Reference Type Young W. Lim Access 2017-01-27 Fri 4 / 18

1) Immediate Operand Type constant values $ followed by integer number only one or two bytes of 4 bytes integer Young W. Lim Access 2017-01-27 Fri 5 / 18

2) Register Operand Type denote the content of a register 8 32-bit registers for double word operations 8 8-bit registers for a byte operation Ea : an arbitrary register a R[Ea] the value of an Ea register view the set of registers as an array R indexed by register identifiers Young W. Lim Access 2017-01-27 Fri 6 / 18

3) Memory Reference Type access some memory location according to the computed address effective address view the memory as a large array of bytes Mb[Addr] : the by b-byte value stored in memory starting at Addr addressing modes : allowing different forms of memory references Imm : immediate offset Eb : a base register Ei : an index register s : a scale factor (1, 2, 4, 8) Young W. Lim Access 2017-01-27 Fri 7 / 18

Addressing Modes Imm (Ea) Imm (Eb) (Eb, Ei) Imm (Eb, Ei) (, Ei, s) Imm (, Ei, s) (Eb, Ei, s) Imm (Eb, Ei, s) M[Imm] M[R[Ea]] M[Imm + R[Eb]] M[R[Eb]+R[Ei]] M[Imm + R[Eb] + R[Ei]] M[R[Ei]*s] M[Imm + R[Ei]*s] M[R[Eb] + R[Ei]*s] M[Imm + R[Eb] + R[Ei]*s] Absolute Indirect Base + displace Indexed Indexed Scaled Indexed Scaled Indexed Scaled Indexed Scaled Indexed Young W. Lim Access 2017-01-27 Fri 8 / 18

IA32 Integer Registers (1) (a, c, d, b, si, di) a: %eax(32), %ax(16), %ah(8), %al(8) c: %ecx(32), %cx(16), %ch(8), %cl(8) d: %edx(32), %dx(16), %dh(8), %dl(8) b: %ebx(32), %bx(16), %bh(8), %bl(8) si: %esi(32), %si(16) di: %edi(32), %di(16) sp: %esp(32), %sp(16) (stack pointer) bp: %ebp(32), %bp(16) (frame pointer) Young W. Lim Access 2017-01-27 Fri 9 / 18

IA32 Integer Registers (2) 32-bit Registers Caller Save Registers %eax, %ecx, %edx Callee Save Registers %ebx, %esi, %edi Stack Frame Registers %esp, %ebp 16-bit Registers %ax, %cx, %dx, %bx, %si, %di, %sp, %bp 8-bit Registers %ah, %al, %ch, %cl, %dh, %dl, %bh, %bl Young W. Lim Access 2017-01-27 Fri 10 / 18

Data Movement Instructions movl S, D ; S -> D ; move double word movw S, D ; S -> D ; move word movb S, D ; S -> D ; move byte movsbl S, D ; SignExt(S) -> D ; move sign-extended byte movzbl S, D ; ZeroExt(S) -> D ; move zero-extended byte pushl S ; R[%esp]-4 -> R[%esp]; S -> M[R[%esp]] ; push popl D ; M[R[%esp]] -> D; R[%esp]+4 -> R[%esp] ; pop Young W. Lim Access 2017-01-27 Fri 11 / 18

movl eamples movl $0x4050, %eax ; immediate -> register movl %ebp, %esp ; register -> register movl (%edi, %ecx), %eax ; memory -> register movl $-17,m (%esp) ; immediate -> memory movl %eax, -12(%ebp) ; register -> memory Young W. Lim Access 2017-01-27 Fri 12 / 18

stack eamples pushl %ebp subl $4, %esp movl %ebp, (%esp) push %eax movl (%esp), %eax addl $4, %esp Young W. Lim Access 2017-01-27 Fri 13 / 18

Comparing byte movements movb %dh, %al movsbl %dh, %eax movzbl %dh, %eax Young W. Lim Access 2017-01-27 Fri 14 / 18

pointer eamples (1) int exchange(int *xp, int y) { int x = *xp; *xp = y; return x; } movl 8(%ebp), %eax ; get xp movl 12(%ebp), %edx ; get y movl (%eax), %ecx ; get x at *xp movl %edx, (%eax) ; store y at *p movl %ecx, %eax ; set x as return address Young W. Lim Access 2017-01-27 Fri 15 / 18

pointer eamples (2) movl movl movl movl movl 8(%ebp), %eax 12(%ebp), %edx (%eax), %ecx %edx, (%eax) %ecx, %eax xp parameter at offset 8 y parameter at offset 12 relative the address in %ebp xp to %eax y to %edx (%eax) dereferences xp : *xp any function returning an integer or pointer value by placing the value in register %3ax Young W. Lim Access 2017-01-27 Fri 16 / 18

pointer eamples (3) pointers are simply addresses derefencing a pointer store that pointer in a register using this register, perform indirect memory reference local variables are kept in registers rather than stored in memory location Register access is much faster Young W. Lim Access 2017-01-27 Fri 17 / 18

function prototype movl 8(%ebp), %edi movl 12(%ebp), %ebx movl 16(%ebp), %esi movl (%edi), %eax movl (%ebx), %edx movl (%esi), %ecx movl %eax, (%ebx) movl %edx, (%esi) movl %ecx, (%edi) Young W. Lim Access 2017-01-27 Fri 18 / 18