Machine-Level Programming I Basics, Lecture Slide - Computer Science, Slides of Computer System Design and Architecture

History of Intel Processor and Architectures , C ,Assembly and Machine Code ,Assembly Basics, Registers ,Operands, Move , Introduction to X86-64

Typology: Slides

2010/2011

Uploaded on 10/08/2011

rolla45
rolla45 šŸ‡ŗšŸ‡ø

4

(6)

133 documents

1 / 47

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Carnegie Mellon
1
Machine(Level,Programming,I:,Basics,
15#213/18#243:*Introduc3on*to*Computer*Systems**
4th*Lecture,*Sep.*2,*2010*
Instructors:,,
Randy*Bryant*and*Dave*O’Hallaron*
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f

Partial preview of the text

Download Machine-Level Programming I Basics, Lecture Slide - Computer Science and more Slides Computer System Design and Architecture in PDF only on Docsity!

Machine-­‐Level Programming I: Basics

15-­‐213/18-­‐243: Introduc3on to Computer Systems 4 th Lecture, Sep. 2, 2010 Instructors: Randy Bryant and Dave O’Hallaron

Today: Machine Programming I: Basics

ļ‚¢ History of Intel processors and architectures

ļ‚¢ C, assembly, machine code

ļ‚¢ Assembly Basics: Registers, operands, move

ļ‚¢ Intro to x86-­‐

Intel x86 EvoluJon: Milestones

Name Date Transistors MHz

ļ‚¢ 8086 1978 29K 5-­‐

ļ‚§ First 16-­‐bit processor. Basis for IBM PC & DOS

ļ‚§ 1MB address space

ļ‚¢ 386 1985 275K 16-­‐

ļ‚§ First 32 bit processor , referred to as IA

ļ‚§ Added ā€œflat addressingā€

ļ‚§ Capable of running Unix

ļ‚§ 32-­‐bit Linux/gcc uses no instruc3ons introduced in later models

ļ‚¢ PenJum 4F 2004 125M 2800-­‐

ļ‚§ First 64-­‐bit processor, referred to as x86-­‐

ļ‚¢ Core i7 2008 731M 2667-­‐

ļ‚§ Our shark machines

Intel x86 Processors: Overview

X86-­‐64 / EM64t

X86-­‐32/IA

X86-­‐16 8086

286 386 486 PenJum PenJum MMX PenJum III PenJum 4 PenJum 4E PenJum 4F Core 2 Duo Core i

IA: o[en redefined as latest Intel architecture

Jme

Architectures Processors

MMX SSE SSE SSE SSE

More InformaJon

ļ‚¢ Intel processors (Wikipedia)

ļ‚¢ Intel microarchitectures

New Species: ia64, then IPF, then Itanium,…

Name Date Transistors

ļ‚¢ Itanium 2001 10M

ļ‚§ First shot at 64-­‐bit architecture: first called IA

ļ‚§ Radically new instruc3on set designed for high performance

ļ‚§ Can run exis3ng IA32 programs

ļ‚§ On-­‐board ā€œx86 engineā€

ļ‚§ Joint project with Hewlef-­‐Packard

ļ‚¢ Itanium 2 2002 221M

ļ‚§ Big performance boost

ļ‚¢ Itanium 2 Dual-­‐Core 2006 1.7B

ļ‚¢ Itanium has not taken off in marketplace

ļ‚§ Lack of backward compa3bility, no good compiler support, Pen3um

4 got too good

Intel’s 64-­‐Bit

ļ‚¢ Intel Adempted Radical Shi[ from IA32 to IA

ļ‚§ Totally different architecture (Itanium)

ļ‚§ Executes IA32 code only as legacy

ļ‚§ Performance disappoin3ng

ļ‚¢ AMD Stepped in with EvoluJonary SoluJon

ļ‚§ x86-­‐64 (now called ā€œAMD64ā€)

ļ‚¢ Intel Felt Obligated to Focus on IA

ļ‚§ Hard to admit mistake or that AMD is befer

ļ‚¢ 2004: Intel Announces EM64T extension to IA

ļ‚§ Extended Memory 64-­‐bit Technology

ļ‚§ Almost iden3cal to x86-­‐64!

ļ‚¢ All but low-­‐end x86 processors support x86-­‐

ļ‚§ But, lots of code s3ll runs in 32-­‐bit mode

Our Coverage

ļ‚¢ IA

ļ‚§ The tradi3onal x

ļ‚¢ x86-­‐64/EM64T

ļ‚§ The emerging standard

ļ‚¢ PresentaJon

ļ‚§ Book presents IA32 in Sec3ons 3.1—3.

ļ‚§ Covers x86-­‐64 in 3.

ļ‚§ We will cover both simultaneously

ļ‚§ Some labs will be based on x86-­‐64, others on IA

DefiniJons

ļ‚¢ Architecture: (also instrucJon set architecture: ISA) The

parts of a processor design that one needs to understand

to write assembly code.

ļ‚§ Examples: instruc3on set specifica3on, registers.

ļ‚¢ Microarchitecture: ImplementaJon of the architecture.

ļ‚§ Examples: cache sizes and core frequency.

ļ‚¢ Example ISAs (Intel): x86, IA, IPF

CPU

Assembly Programmer’s View

ļ‚¢ Programmer-­‐Visible State ļ‚§ PC: Program counter ļ‚§ Address of next instruc3on ļ‚§ Called ā€œEIPā€ (IA32) or ā€œRIPā€ (x86-­‐64) ļ‚§ Register file ļ‚§ Heavily used program data ļ‚§ Condi3on codes ļ‚§ Store status informa3on about most recent arithme3c opera3on ļ‚§ Used for condi3onal branching

PC

Registers

Memory

Object Code Program Data OS Data Addresses Data Instruc3ons

Stack

CondiJon

Codes

ļ‚§ Memory

ļ‚§ Byte addressable array ļ‚§ Code, user data, (some) OS data ļ‚§ Includes stack used to support procedures

Compiling Into Assembly

C Code

int sum(int x, int y) { int t = x+y; return t; }

Generated IA32 Assembly

sum: pushl %ebp movl %esp,%ebp movl 12(%ebp),%eax addl 8(%ebp),%eax popl %ebp ret

Obtain with command

/usr/local/bin/gcc –O1 -S code.c

Produces file code.s

Some compilers use

instrucJon ā€œleaveā€

Assembly CharacterisJcs: Data Types

ļ‚¢ ā€œIntegerā€ data of 1, 2, or 4 bytes

ļ‚§ Data values

ļ‚§ Addresses (untyped pointers)

ļ‚¢ FloaJng point data of 4, 8, or 10 bytes

ļ‚¢ No aggregate types such as arrays or structures

ļ‚§ Just con3guously allocated bytes in memory

Code for sum

0x401040 : 0x 0x 0xe 0x8b 0x 0x0c 0x 0x 0x 0x5d 0xc

Object Code

ļ‚¢ Assembler

ļ‚§ Translates .s into .o

ļ‚§ Binary encoding of each instruc3on

ļ‚§ Nearly-­‐complete image of executable code

ļ‚§ Missing linkages between code in different

files

ļ‚¢ Linker

ļ‚§ Resolves references between files

ļ‚§ Combines with sta3c run-­‐3me libraries

ļ‚§ E.g., code for malloc, printf

ļ‚§ Some libraries are dynamically linked

ļ‚§ Linking occurs when program begins execu3on

  • Total of 11 bytes
  • Each instrucJon 1, 2, or 3 bytes
  • Starts at address 0x

Machine InstrucJon Example

ļ‚¢ C Code

ļ‚§ Add two signed integers

ļ‚¢ Assembly

ļ‚§ Add 2 4-­‐byte integers

ļ‚§ ā€œLongā€ words in GCC parlance ļ‚§ Same instruc3on whether signed or unsigned

ļ‚§ Operands:

x: Register %eax y: Memory M[%ebp+8] t: Register %eax

  • Return func3on value in %eax

ļ‚¢ Object Code

ļ‚§ 3-­‐byte instruc3on

ļ‚§ Stored at address 0x80483ca

*int t = x+y; addl 8(%ebp),%eax 0x80483ca: 03 45 08 Similar to expression: x += y More precisely: int eax; int ebp; eax += ebp[2]