Binghamton University CS-220 Spring 2015 Binghamton University CS-220 Spring 2015 x86 Assembler.

Slides:



Advertisements
Similar presentations
Introduction to Machine/Assembler Language Noah Mendelsohn Tufts University Web:
Advertisements

Machine/Assembler Language Putting It All Together Noah Mendelsohn Tufts University Web:
COMP 2003: Assembly Language and Digital Logic
C Programming and Assembly Language Janakiraman V – NITK Surathkal 2 nd August 2014.
Department of Computer Science and Software Engineering
Introduction to Assembly Here we have a brief introduction to IBM PC Assembly Language –CISC instruction set –Special purpose register set –8 and 16 bit.
Lecture 6 Machine Code: How the CPU is programmed.
University of Washington Instruction Set Architectures ISAs Brief history of processors and architectures C, assembly, machine code Assembly basics: registers,
Instruction Set Architectures
PC hardware and x86 3/3/08 Frans Kaashoek MIT
1 ICS 51 Introductory Computer Organization Fall 2006 updated: Oct. 2, 2006.
ICS312 Set 3 Pentium Registers. Intel 8086 Family of Microprocessors All of the Intel chips from the 8086 to the latest pentium, have similar architectures.
1 Machine-Level Programming I: Basics Computer Systems Organization Andrew Case Slides adapted from Jinyang Li, Randy Bryant and Dave O’Hallaron.
CEG 320/520: Computer Organization and Assembly Language ProgrammingIntel Assembly 1 Intel IA-32 vs Motorola
6.828: PC hardware and x86 Frans Kaashoek
64-Bit Architectures Topics 64-bit data New registers and instructions Calling conventions CS 105 “Tour of the Black Holes of Computing!”
Low Level Programming Lecturer: Duncan Smeed Overview of IA-32 Part 1.
INSTRUCTION SET AND ASSEMBLY LANGUAGE PROGRAMMING
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);
The ISA Level The Instruction Set Architecture (ISA) is positioned between the microarchtecture level and the operating system level.  Historically, this.
The x86 Architecture Lecture 15 Fri, Mar 4, 2005.
Module 3 Instruction Set Architecture (ISA): ISA Level Elements of Instructions Instructions Types Number of Addresses Registers Types of Operands.
Assembly תרגול 5 תכנות באסמבלי. Assembly vs. Higher level languages There are NO variables’ type definitions.  All kinds of data are stored in the same.
Computer Architecture and Operating Systems CS 3230 :Assembly Section Lecture 4 Department of Computer Science and Software Engineering University of Wisconsin-Platteville.
Computer Architecture and Organization
1 ICS 51 Introductory Computer Organization Fall 2009.
26-Nov-15 (1) CSC Computer Organization Lecture 6: Pentium IA-32.
Oct. 25, 2000Systems Architecture I1 Systems Architecture I (CS ) Lecture 9: Alternative Instruction Sets * Jeremy R. Johnson Wed. Oct. 25, 2000.
University of Washington Basics of Machine Programming The Hardware/Software Interface CSE351 Winter 2013.
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.
Chapter 2 Parts of a Computer System. 2.1 PC Hardware: Memory.
Carnegie Mellon 1 Machine-Level Programming I: Basics Lecture, Feb. 21, 2013 These slides are from website which accompanies the.
Compiler Construction Code Generation Activation Records
X86 Assembly Language We will be using the nasm assembler (other assemblers: MASM, as, gas)
Introduction to Intel IA-32 and IA-64 Instruction Set Architectures.
1 x86 Programming Model Microprocessor Computer Architectures Lab Components of any Computer System Control – logic that controls fetching/execution of.
Microprocessors CSE- 341 Dr. Jia Uddin Assistant Professor, CSE, BRAC University Dr. Jia Uddin, CSE, BRAC University.
Intel MP Organization. Registers - storage locations found inside the processor for temporary storage of data 1- Data Registers (16-bit) AX, BX, CX, DX.
Spring 2016Assembly Review 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);
Instruction Set Architecture
Homework Reading Lab with your assigned section starts next week
Assembly language.
Credits and Disclaimers
Format of Assembly language
IA32 Processors Evolutionary Design
Part of the Assembler Language Programmers Toolbox
16.317: Microprocessor System Design I
Roadmap C: Java: Assembly language: OS: Machine code: Computer system:
Introduction to Compilers Tim Teitelbaum
Microprocessor Systems Design I
Assembly IA-32.
University of Gujrat Department of Computer Science
Homework Reading Continue work on mp1
Assembly Language for x86 Processors
BIC 10503: COMPUTER ARCHITECTURE
Introduction to Intel IA-32 and IA-64 Instruction Set Architectures
CS 301 Fall 2002 Computer Organization
MIPS Procedure Calls CSE 378 – Section 3.
Computer Architecture CST 250
X86 Assembly Review.
Machine-Level Programming II: Basics Comp 21000: Introduction to Computer Organization & Systems Instructor: John Barr * Modified slides from the book.
Machine-Level Programming I: Basics
Other Processors Having learnt MIPS, we can learn other major processors. Not going to be able to cover everything; will pick on the interesting aspects.
Machine-Level Programming I: Basics Comp 21000: Introduction to Computer Organization & Systems Instructor: John Barr * Modified slides from the book.
Introduction to Assembly
The von Neumann Machine
Credits and Disclaimers
Computer Architecture and System Programming Laboratory
Part I Data Representation and 8086 Microprocessors
Low level Programming.
Presentation transcript:

Binghamton University CS-220 Spring 2015 Binghamton University CS-220 Spring 2015 x86 Assembler

Binghamton University CS-220 Spring 2015 Binghamton University CS-220 Spring 2015 Disclaimer I am not an x86 assembler expert. I have never written an x86 assembler program. (I am proficient in IBM S/360 Assembler and LC3 Assembler.) You will NOT be expected to WRITE x86 assembler. You WILL be expected to be able to READ x86 assembler!

Binghamton University CS-220 Spring 2015 Binghamton University CS-220 Spring 2015 Instruction Set Architecture (ISA) Contract between Hardware Designer and Programmer Which parts of the hardware the programmer is allowed to see and use Many machines may have the same architecture E.g. x86 supported by Intel, AMD, HP, Sun, IBM, Motorola, … A single machine sometimes supports multiple architectures E.g. x86 / x86-64 Usually for downward compatability

Binghamton University CS-220 Spring 2015 Binghamton University CS-220 Spring 2015 The architecture compatibility dilemma Over time, things evolve : hardware, software, new uses Customers hate architectural changes Lose investment in software Architecture changes introduce new bugs Customers love the latest new feature Can’t wait for googleplex address space, … Resolution: Architecture Supersets

Binghamton University CS-220 Spring 2015 Binghamton University CS-220 Spring 2015 Intel Milestones DateChipData WidthTransistorsClock RateUsage K0.8 MHzMonitors, Controllers (some 16)6K2 MHz+ Calculators K10 MHzIBM PC/DOS – First x K40 MHzWindows+Linux 1993Pentium P5323.1M66 MHzditto 2004Pentium 4F64125M3.8 GHzditto 2008Core i764731M3.33 GHzditto 2014Core i7 extreme641.4B3.5 GHzditto

Binghamton University CS-220 Spring 2015 Binghamton University CS-220 Spring Years of Evolution X86-64 / EM64t X86-32/IA32 X Pentium Pentium MMX Pentium III Pentium 4 Pentium 4E Pentium 4F Core 2 Duo Core i7 ArchitecturesProcessors MMX SSE SSE2 SSE3 SSE4

Binghamton University CS-220 Spring 2015 Binghamton University CS-220 Spring 2015 x86 Clones: Advanced Micro Devices Historically AMD has followed just behind Intel A little bit slower, a lot cheaper Then Recruited top circuit designers from Digital Equipment Corp. and other downward trending companies Built Opteron: tough competitor to Pentium 4 Developed x86-64, their own extension to 64 bits

Binghamton University CS-220 Spring 2015 Binghamton University CS-220 Spring 2015 CPU Assembly Programmer’s View of x86 Memory Byte addressable array Code, user data, (some) OS data Includes stack used to support procedures Programmer-Visible State PC: Program counter Address of next instruction Called “EIP” (IA32) or “RIP” (x86-64) Register file Heavily used program data Condition codes Store status information about most recent arithmetic operation Used for conditional branching Arithmetic/Logic Unit (ALU) Performs Instructions PC Registers Memory Object Code Program Data OS Data Addresses Data Instructions Stack Condition Codes ALU

Binghamton University CS-220 Spring 2015 Binghamton University CS-220 Spring 2015 x86 Generalizations Designed to be Compiler Friendly Stack manipulation instructions ALU uses data from memory as well as registers! Downward Compatible Newer versions are supersets of older versions CISC (Complex Instruction Set Computing)

Binghamton University CS-220 Spring 2015 Binghamton University CS-220 Spring 2015 CISC Concept IMULT X,Y Micro-code … IMULT -> SHIFTL 1,X ADD ACCUM,Y SHIFTL 1, X … ADD ACCUM,Y

Binghamton University CS-220 Spring 2015 Binghamton University CS-220 Spring 2015 RISC Concept ADD ACCUM,Y

Binghamton University CS-220 Spring 2015 Binghamton University CS-220 Spring 2015 Origin Accumulate Counter Data Base Source Index Destination Index Stack Pointer base Pointer x86 Integer Registers %rdi %rax %rcx %rdx %rsi %rbx %rbp %rsp %eax %ecx %edx %ebx %esi %edi %esp %ebp %ax %cx %dx %bx %si %di %sp %bp %ah%al%ch%cl%dh%dl%bh%bl

Binghamton University CS-220 Spring 2015 Binghamton University CS-220 Spring 2015 x86 Data “Types” No type checking - Instruction and/or context implies data type Arithmetic instructions treat operands as numbers Either signed or unsigned! Instruction suffix used to identify precision of arguments b – 1 byte (8 bits) w – word (2 bytes, 16 bits) l – long word (4 bytes, 32 bits) q – quad word (8 bytes, 64 bits) With no suffix, register type implies precision of arguments ah/al – b – 8 bits ax – w – 16 bits eax – l – 32 bits rax – q – 64 bits Floating point – 4, 8, or 10 bytes

Binghamton University CS-220 Spring 2015 Binghamton University CS-220 Spring 2015 x86 Assembler Syntax [ :] arg1[,arg2…] [; comment] Label optional – identifies start of this line mnemonic – See for a complete listhttp://ref.x86asm.net/ Up to 4 arguments Comment ends at the end of this line

Binghamton University CS-220 Spring 2015 Binghamton University CS-220 Spring 2015 Assembler Argument Generalities Direction: LEFT to RIGHT ⇒ (AT&T syntax… INTEL syntax is RtoL) mov 5,eax; eax=5 (move 5 into register eax) add bx, ax ; ax = ax + bx or ax+=bx (add bx to ax and store in ax) Optional argument prefixes % - register e.g. “movl 5,%eax” $ - immediate value e.g. “movl $5,%eax” Arguments may be: register, immediate value, memory reference One (but not both) argument may be a memory reference! at least one argument must be a register or immediate value

Binghamton University CS-220 Spring 2015 Binghamton University CS-220 Spring 2015 Immediate (literal) values Similar to C Conventions…. Numbers are decimal by default, octal if preceded by 0, hex if preceded by 0x Single characters are enclosed in single quotes, including special characters such as ‘\n’, ‘\t’ Strings are arrays of characters enclosed in double quotes

Binghamton University CS-220 Spring 2015 Binghamton University CS-220 Spring 2015 Basic x86 addressing modes Normal: Register contains address of target in memory Parenthesis indicate “Use Value at this address” movl (%ecx),%eax ; Put the value at memory[ecx] into eax Displacement: Register is near address of target in memory Offset from register specified before parenthesis movl 8(%ebp),%edx ; Put the value at 8 past the base pointer into edx See if you need the entire story – but it’s complicatedhttp://en.wikipedia.org/wiki/X86#Addressing_modes

Binghamton University CS-220 Spring 2015 Binghamton University CS-220 Spring 2015 The MOV instruction Most often used instruction! More “copy” than “move” Copies 1,2,4, or 8 bytes from ARG1 to ARG2 mov $-12,%eax ; put -12 into 4 byte eax register mov $0xffff,(%esp) ; put -1 at top of stack mov 12(%ebp),%eax ; copy data at 12 past base pointer into eax

Binghamton University CS-220 Spring 2015 Binghamton University CS-220 Spring 2015 Logic Instructions Standard 2 arg: and or xor shl shr and %ebx,%eax ; eax=eax & ebx shr $4,%eax; eax = (unsigned)eax>>4 Single argument: not neg not %eax ; flip bits in eax neg %ebx; take two’s complement (flip bits and add 1) of ebx

Binghamton University CS-220 Spring 2015 Binghamton University CS-220 Spring 2015 Arithmetic Instructions Standard integer arithmetic: add sub add $10,(%eax); (*eax)=(*eax)+10 sub $4,%esp ; esp=esp-4 (move stack pointer down) “Special” integer arithmetic: imul idiv imul cannot write to memory idiv divides register pair (EDX:EAX) and puts quotient/remainder back Single argument: inc dec inc %eax; eax=eax+1 – same as add eax,1 dec (%esp) ; decrement the value at the top of the stack by 1 Floating Point Instructions

Binghamton University CS-220 Spring 2015 Binghamton University CS-220 Spring 2015 Dealing with Pointers Load effective address: lea Used for implicit arrays/structures, etc. lea (array),%eax mov $0,%edx loop: add (%eax),%edx add $4,%eax cmp endarray,%eax jle loop mov %eax,(sum)

Binghamton University CS-220 Spring 2015 Binghamton University CS-220 Spring 2015 Not done yet… Next – x86 control instructions…