X86 ISA Compiler Baojian Hua Front End source code abstract syntax tree lexical analyzer parser tokens IR semantic analyzer.

Slides:



Advertisements
Similar presentations
Assembly Language – 1.
Advertisements

Tiling Examples for X86 ISA Slides Selected from Radu Ruginas CS412/413 Lecture on Instruction Selection at Cornell.
Introduction to Machine/Assembler Language Noah Mendelsohn Tufts University Web:
Software & Services Group, Developer Products Division Copyright© 2010, Intel Corporation. All rights reserved. *Other brands and names are the property.
1 ECE462/562 ISA and Datapath Review Ali Akoglu. 2 Instruction Set Architecture A very important abstraction –interface between hardware and low-level.
ITCS 3181 Logic and Computer Systems 2015 B. Wilkinson slides3.ppt Modification date: March 16, Addressing Modes The methods used in machine instructions.
C Programming and Assembly Language Janakiraman V – NITK Surathkal 2 nd August 2014.
CS153 Greg Morrisett. Quick overview of the MIPS instruction set.  We're going to be compiling to MIPS assembly language.  So you need to know how to.
1: Background1 System Programming ( 系統程式 ) Main goal: r What is a system software? m Compiler m Assembler m Loader and Linker m Debugger… r To design and.
PC hardware and x86 3/3/08 Frans Kaashoek MIT
1 ICS 51 Introductory Computer Organization Fall 2006 updated: Oct. 2, 2006.
Classifying Instruction Set Architectures
1 Assemblers and Linkers CS Goals of This Lecture Compilation process  Compile, assemble, archive, link, execute Assembling  Representing instructions.
Assembly Language Basic Concepts IA-32 Processor Architecture.
Code Generation Compiler Baojian Hua
CS2422 Assembly Language & System Programming September 22, 2005.
Classifying Instruction Set Architectures
4/6/08Prof. Hilfinger CS164 Lecture 291 Code Generation Lecture 29 (based on slides by R. Bodik)
CS2422 Assembly Language & System Programming September 26, 2006.
Princess Sumaya Univ. Computer Engineering Dept. Chapter 2:
Lecture 7: Instruction Set Architecture CSE 30: Computer Organization and Systems Programming Winter 2014 Diba Mirza Dept. of Computer Science and Engineering.
David Evans CS201j: Engineering Software University of Virginia Computer Science Lecture 18: 0xCAFEBABE (Java Byte Codes)
ITEC 352 Lecture 11 ISA - CPU. ISA (2) Review Questions? HW 2 due on Friday ISA –Machine language –Buses –Memory.
6.828: PC hardware and x86 Frans Kaashoek
Linked Lists in MIPS Let’s see how singly linked lists are implemented in MIPS on MP2, we have a special type of doubly linked list Each node consists.
ZONG Wen Department of Computer Science and Engineering The Chinese University of Hong Kong
Today’s topics Parameter passing on the system stack Parameter passing on the system stack Register indirect and base-indexed addressing modes Register.
Introduction: Exploiting Linux. Basic Concepts Vulnerability A flaw in a system that allows an attacker to do something the designer did not intend,
Lecture-1 Compilation process
Fall 2012 Chapter 2: x86 Processor Architecture. Irvine, Kip R. Assembly Language for x86 Processors 6/e, Chapter Overview General Concepts IA-32.
University of Washington Roadmap 1 car *c = malloc(sizeof(car)); c->miles = 100; c->gals = 17; float mpg = get_mpg(c); free(c); Car c = new Car(); c.setMiles(100);
5-1 Chapter 5 - Languages and the Machine Department of Information Technology, Radford University ITEC 352 Computer Organization Principles of Computer.
5-1 Chapter 5 - Languages and the Machine Principles of Computer Architecture by M. Murdocca and V. Heuring © 1999 M. Murdocca and V. Heuring Principles.
CBP 2009Comp 3014 The Nature of Computing 1 Choices in Designing an ISA Uniformity. Should each instruction –Be the same length (in bits or bytes?) –Take.
Today’s topics Procedures Procedures Passing values to/from procedures Passing values to/from procedures Saving registers Saving registers Documenting.
CNIT 127: Exploit Development Ch 3: Shellcode. Topics Protection rings Syscalls Shellcode nasm Assembler ld GNU Linker objdump to see contents of object.
1 ICS 51 Introductory Computer Organization Fall 2009.
Assembly Language for x86 Processors 7th Edition Chapter 13: High-Level Language Interface (c) Pearson Education, All rights reserved. You may modify.
Chapter 1 Introduction Study Goals: Master: the phases of a compiler Understand: what is a compiler Know: interpreter,compiler structure.
Exception Compiler Baojian Hua
Assembly Language. Symbol Table Variables.DATA var DW 0 sum DD 0 array TIMES 10 DW 0 message DB ’ Welcome ’,0 char1 DB ? Symbol Table Name Offset var.
Sahar Mosleh California State University San MarcosPage 1 Assembly language and Digital Circuit By Sahar Mosleh California State University San Marcos.
Functions/Methods in Assembly
The Instruction Set Architecture. Hardware – Software boundary Java Program C Program Ada Program Compiler Instruction Set Architecture Microcode Hardware.
Compiler Construction Code Generation Activation Records
X86 Assembly Language We will be using the nasm assembler (other assemblers: MASM, as, gas)
University of Amsterdam Computer Systems – the instruction set architecture Arnoud Visser 1 Computer Systems The instruction set architecture.
ISA's, Compilers, and Assembly
Introduction to Intel IA-32 and IA-64 Instruction Set Architectures.
Addressing Modes Dr. Hadi Hassan.  Two Basic Questions  Where are the operands?  How memory addresses are computed?  Intel IA-32 supports 3 fundamental.
CS 177 Computer Security Lecture 9
Instruction Set Architectures
Assembly language.
Credits and Disclaimers
IA32 Processors Evolutionary Design
Roadmap C: Java: Assembly language: OS: Machine code: Computer system:
ISA's, Compilers, and Assembly
Choices in Designing an ISA
Assembly IA-32.
Basics Of X86 Architecture
Computer Architecture and Assembly Language
Discussion Section – 11/3/2012
Lecture 30 (based on slides by R. Bodik)
MIPS Procedure Calls CSE 378 – Section 3.
Information Security - 2
CPU Structure CPU must:
Lecture 4: Instruction Set Design/Pipelining
Machine-Level Programming I: Basics Comp 21000: Introduction to Computer Organization & Systems Instructor: John Barr * Modified slides from the book.
Credits and Disclaimers
Computer Architecture and Assembly Language
Presentation transcript:

x86 ISA Compiler Baojian Hua

Front End source code abstract syntax tree lexical analyzer parser tokens IR semantic analyzer

Code Generation Before discussing code generation, we must understand what we are trying to generate virtual machines bare architecture … This course uses x86 So you’d learn how to program at the x86 level There is an online manual covering every details relatively old, but enough for understanding Linux, Windows, gcc, …

x86 Complex Instruction Set Computer (CISC) Instructions can operate on memory values e.g., add [eax], ebx Complex, multi-cycle instructions e.g., string-copy, call Many ways to do the same thing e.g., add eax,1 inc eax, sub eax,-1 Instructions are variable-length (1-10 bytes) Registers are not orthogonal

Capsule History 1978, 8086 First x86 microprocessor, 16-bit 1985, bit, protected mode 1989, , Pentium MMX 2000, Pentium 4 Deeply pipelined, high frequency 2006, Intel Core 2 Low power, multi-core

x86 ISA Instruction Set Architecture another programming language (instructions set) encoding decoding assemble, compile to … different implementations say Intel vs AMD Basis for OS, compilers, etc. hardware-software interface

x86 ISA What ’ s important here? OS and library Note: assembly program are NOT portable language syntax another CFG, read the manual assembler directives etc. think “ compiler ”, read the gas manual

OS and Library OS simplifies programming model e.g., Linux and Windows disable segmentation the so-called “ flat ” model in the manual so all segment-related details may be ignored when reading the manual OS provides protection mode e.g., Linux and Windows run user programs on ring3 so you cannot change the page table! etc.

OS and Library OS provides system calls hide many crazy details but may be still annoying Libraries another level of indirection on top of OS system calls In particular, we ’ d use C library

Syntax Syntax = data + instructions Data Immediate 4, 3.14, “ hello ” Register general-purpose eax, ebx, … segment remember? we don ’ t care

Data Memory different usage: globl stack heap but same behavior

Data Memory addressing mode seg:[base+index*scale+disp] any part can be null complex! right? e.g., int a[5][10], to read a[3][2] moveax, 30 movebx, 2 movecx, [eax+ebx*4+a] Problems with this strategy?

Instructions Manual covers all instructions in details: Data movement Arithmetic Control transfer … Rather than explain all these bit-by-bit, I ’ ll give an example next

Assembler Assembler is more than just a compiler: it costumes assembly syntax it also offers the so-called directives Two main branches: Intel syntax assembler on Windows: masm, nasm, … the Intel manual! AT&T syntax Linux assembler: gas the good news is that recent version of gas supports Intel syntax! the GCC output! This course uses as with Intel syntax So reading the Intel manual is relatively easy

Example # Sum up an array of integers # compiled by GCC: # $ gcc test.s.intel_syntax noprefix.data a:.int 1, 2, 3, 4, 5, 6, 7, 8, 9, 10.globl main.text main: comments start with “ # ”, also supports C/C++ style directive: telling that we prefer Intel syntax directive: assemble the following to data section label: the current address directive: store 10 integers start from the address “ a ” directive: globl symbol directive: assemble the following to text section label: another address

Example, cont ’ push ebp mov esp, ebp # convention: eax: the sum, ebx: index xor eax, eax mov ebx, eax L_start: add eax, dword ptr [ebx*4+a] inc ebx comp ebx, 10 jl L_start leave ret

Summary Assembly programming is fun and simple conceptually but CISC architecture is … and a compound knowledge of OS, architecture and compiler Read the online manual Essential for code generation