Computer Systems Architecture I. CSE 560M Lecture 3 Prof. Patrick Crowley

Similar documents
Instruction Set Architectures

Instruction Set Architectures

Systems I. Machine-Level Programming I: Introduction

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 Programmer s View Lecture 4A Machine-Level Programming I: Introduction

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

Machine-Level Programming I: Introduction Jan. 30, 2001

MACHINE-LEVEL PROGRAMMING I: BASICS COMPUTER ARCHITECTURE AND ORGANIZATION

CISC 360. Machine-Level Programming I: Introduction Sept. 18, 2008

Last Time: Floating Point. Intel x86 Processors. Lecture 4: Machine Basics Computer Architecture and Systems Programming ( )

Page # CISC 360. Machine-Level Programming I: Introduction Sept. 18, IA32 Processors. X86 Evolution: Programmerʼs View.

MACHINE-LEVEL PROGRAMMING I: BASICS

Carnegie Mellon. 5 th Lecture, Jan. 31, Instructors: Todd C. Mowry & Anthony Rowe

The course that gives CMU its Zip! Machine-Level Programming I: Introduction Sept. 10, 2002

Giving credit where credit is due

Roadmap. Java: Assembly language: OS: Machine code: Computer system:

Today: Machine Programming I: Basics

IA32 Processors The course that gives CMU its Zip! Machine-Level Programming I: Introduction Sept. 10, X86 Evolution: Programmer s View

Today: Machine Programming I: Basics. Machine Level Programming I: Basics. Intel x86 Processors. Intel x86 Evolution: Milestones

! Starting in 1978 with ! Added more features as time goes on. ! Still support old features, although obsolete

Machine Level Programming I: Basics. Credits to Randy Bryant & Dave O Hallaron

Machine-Level Programming Introduction

Compila(on, Disassembly, and Profiling

Machine Programming 1: Introduction

+ Machine Level Programming: x86-64 History

Machine Level Programming I: Basics

The Hardware/Software Interface CSE351 Spring 2015

University*of*Washington*

X86 Assembly -Data II:1

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

CS429: Computer Organization and Architecture

Machine- level Programming

The Hardware/Software Interface CSE351 Spring 2015

55:132/22C:160, HPCA Spring 2011

Lecture 4: Instruction Set Architecture

Machine Programming I: Basics

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

Machine-Level Programming I Introduction

Machine-Level Programming I Introduction

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

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

Machine-Level Programming Introduction

Today: Machine Programming I: Basics. Machine-Level Programming I: Basics. Intel x86 Processors. Intel x86 Evolution: Milestones

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

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

COSC 6385 Computer Architecture. Instruction Set Architectures

Instruction Set Principles and Examples. Appendix B

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

Typical Processor Execution Cycle

Machine Language, Assemblers and Linkers"

Topics Power tends to corrupt; absolute power corrupts absolutely. Computer Organization CS Data Representation

Chapter 3 Machine-Level Programming I: Basics. Bryant and O Hallaron, Computer Systems: A Programmer s Perspective, Third Edition

Page 1. Structure of von Nuemann machine. Instruction Set - the type of Instructions

Representation of Information

Announcements HW1 is due on this Friday (Sept 12th) Appendix A is very helpful to HW1. Check out system calls

Machine Level Programming: Basics

W4118: PC Hardware and x86. Junfeng Yang

Compilation, Disassembly, and Profiling (in Linux)

EC-801 Advanced Computer Architecture

Instruction Set Design

Machine Level Programming: Basics

Systems I. Machine-Level Programming V: Procedures

Machine-Level Programming I: Basics

Math 230 Assembly Programming (AKA Computer Organization) Spring 2008

Instruction Set Architecture

Instruction Set Architecture

Machine- Level Programming I: Basics

ECE 486/586. Computer Architecture. Lecture # 7

CS429: Computer Organization and Architecture

Instruction Set Architecture (ISA)

Today: Machine Programming I: Basics. Machine-Level Programming I: Basics. Intel x86 Processors. Intel x86 Evolution: Milestones

CSCE 5610: Computer Architecture

Chapter 2A Instructions: Language of the Computer

Machine-level Representation of Programs

CENG3420 Lecture 03 Review

Lecture 4: Instruction Set Design/Pipelining

Slides for Lecture 6

CS4617 Computer Architecture

EITF20: Computer Architecture Part2.1.1: Instruction Set Architecture

COSC 6385 Computer Architecture - Instruction Set Principles

Instruction Set Architecture

CISC 360 Instruction Set Architecture

CS429: Computer Organization and Architecture

ISA and RISCV. CASS 2018 Lavanya Ramapantulu

CS241 Computer Organization Spring Introduction to Assembly

CSE 141 Computer Architecture Spring Lecture 3 Instruction Set Architecute. Course Schedule. Announcements

Instruction Set Architecture. "Speaking with the computer"

2.7 Supporting Procedures in hardware. Why procedures or functions? Procedure calls

Lecture 3: Instruction Set Architecture

CSCI 402: Computer Architectures. Instructions: Language of the Computer (1) Fengguang Song Department of Computer & Information Science IUPUI

Practical Malware Analysis

Chapter 2: Instructions How we talk to the computer

CSIS1120A. 10. Instruction Set & Addressing Mode. CSIS1120A 10. Instruction Set & Addressing Mode 1

ENGN1640: Design of Computing Systems Topic 03: Instruction Set Architecture Design

ECE 486/586. Computer Architecture. Lecture # 8

EC 413 Computer Organization

Lecture 4: MIPS Instruction Set

Y86 Processor State. Instruction Example. Encoding Registers. Lecture 7A. Computer Architecture I Instruction Set Architecture Assembly Language View

Virtual Machines and Dynamic Translation: Implementing ISAs in Software

Lecture Topics. Branch Condition Options. Branch Conditions ECE 486/586. Computer Architecture. Lecture # 8. Instruction Set Principles.

Transcription:

Computer Systems Architecture I CSE 560M Lecture 3 Prof. Patrick Crowley

Plan for Today Announcements Readings are extremely important! No class meeting next Monday Questions Commentaries A few remaining thoughts from last week Instruction set architecture discussion Assignment

Commentaries Are brief essays that: Demonstrate that you ve read and understood the assigned reading Ideally: express a strong opinion, either critical or supportive Should be approximately one page in length Need to be submitted to discussion site before class

ISA: The Programmer s Interface Designer s Question: what does the programmer need? Instruction/command Set Available operations (RISC vs. CISC) Branching behavior Valid instruction sequences Registers Sizes Data types Organization (flat, windows, hierarchical) Addressing Modes Register, Immediate, Indirect Offset, scaling

Interface vs. Implementation ISA: the programmer s interface Implementation: the underlying resources and organization Ideally: Programmer needs only ISA to write good programs In reality: Programmers look into the implementation to improve performance Consequences?

Assembly Programmer s View CPU Memory Addresses E I P Registers Condition Codes Data Instructions Object Code Program Data OS Data Programmer-Visible State EIP Program Counter Address of next instruction Register File Heavily used program data Condition Codes Store status information about most recent arithmetic operation Used for conditional branching Memory Stack Byte addressable array Code, user data, (some) OS data Includes stack used to support procedures

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 text C program (p1.c p2.c) Compiler (gcc -S) text Asm program (p1.s p2.s) Assembler (gcc or as) binary binary Object program (p1.o p2.o) Linker (gcc or ld) Executable program (p) Static libraries (.a)

Compiling Into Assembly C Code int sum(int x, int y) { int t = x+y; return t; } Generated Assembly _sum: pushl %ebp movl %esp,%ebp movl 12(%ebp),%eax addl 8(%ebp),%eax movl %ebp,%esp popl %ebp ret Obtain with command gcc -O -S code.c Produces file code.s

Assembly Characteristics Minimal Data Types Integer data of 1, 2, or 4 bytes Data values Addresses (untyped pointers) Floating point data of 4, 8, or 10 bytes No aggregate types such as arrays or structures Just contiguously allocated bytes in memory Primitive Operations Perform arithmetic function on register or memory data Transfer data between memory and register Load data from memory into register Store register data into memory Transfer control Unconditional jumps to/from procedures Conditional branches

Code for sum 0x401040 <sum>: 0x55 0x89 0xe5 0x8b 0x45 0x0c 0x03 0x45 0x08 0x89 0xec 0x5d 0xc3 Object Code Total of 13 bytes Each instruction 1, 2, or 3 bytes Starts at address 0x401040 Assembler Translates.s into.o Binary encoding of each instruction Nearly-complete image of executable code Missing linkages between code in different files Linker Resolves references between files Combines with static run-time libraries E.g., code for malloc, printf Some libraries are dynamically linked Linking occurs when program begins execution

x86 Machine Instruction Example int t = x+y; C Code Add two signed integers addl 8(%ebp),%eax Similar to expression: x += y Or int eax; int *ebp; eax += ebp[2] 0x401046: 03 45 08 Assembly Add 2 4-byte integers Long words in GCC parlance Same instruction whether signed or unsigned Operands: x: Register %eax y: Memory M[%ebp+8] t: Register %eax Object Code Return function value in %eax 3-byte instruction Stored at address 0x401046

Disassembling Object Code Disassembled 00401040 <_sum>: 0: 55 push %ebp 1: 89 e5 mov %esp,%ebp 3: 8b 45 0c mov 0xc(%ebp),%eax 6: 03 45 08 add 0x8(%ebp),%eax 9: 89 ec mov %ebp,%esp b: 5d pop %ebp c: c3 ret d: 8d 76 00 lea 0x0(%esi),%esi Disassembler objdump -d p Useful tool for examining object code Analyzes bit pattern of series of instructions Produces approximate rendition of assembly code Can be run on either a.out (complete executable) or.o file

Object 0x401040: 0x55 0x89 0xe5 0x8b 0x45 0x0c 0x03 0x45 0x08 0x89 0xec 0x5d 0xc3 Alternate Disassembly with gdb Disassembled 0x401040 <sum>: push %ebp 0x401041 <sum+1>: mov %esp,%ebp 0x401043 <sum+3>: mov 0xc(%ebp),%eax 0x401046 <sum+6>: add 0x8(%ebp),%eax 0x401049 <sum+9>: mov %ebp,%esp 0x40104b <sum+11>: pop %ebp 0x40104c <sum+12>: ret 0x40104d <sum+13>: lea 0x0(%esi),%esi Within gdb Debugger gdb p disassemble sum Disassemble procedure x/13b sum Examine the 13 bytes starting at sum

What Can be Disassembled? % objdump -d WINWORD.EXE WINWORD.EXE: file format pei-i386 No symbols in "WINWORD.EXE". Disassembly of section.text: 30001000 <.text>: 30001000: 55 push %ebp 30001001: 8b ec mov %esp,%ebp 30001003: 6a ff push $0xffffffff 30001005: 68 90 10 00 30 push $0x30001090 3000100a: 68 91 dc 4c 30 push $0x304cdc91 Anything that can be interpreted as executable code Disassembler examines bytes and reconstructs assembly source

ALU-centric ISA Taxonomy

Simple vs. Complex Operations RISC: reduced instruction set computer (plus load/store arch) Small number of instructions Easy to encode Poor code density Compiler and implementation friendly CISC: complex instruction set computer Many instructions Good for special, hand-coded cases Good code density Complicates compilation and implementation

Framing Your Perspective If you were to design an ISA of your own, what decisions must be made?

Operation Types Type Examples ALU Arithmetic, logic Memory Loads and stores Control Branch, jump, calls returns, traps System OS call, privileged system management F.P. Floating point arithmetic Decimal Decimal ops String Copy, compare, search Multimedia Pixel and vertex ops

Encoding Instructions Flexibility Many registers Multiple addressing options Compactness Small instructions Ease of implementation Instructions represent control

Encoding Examples

To design and encode, consider Characteristics of representative programs What operations get used most? What data types are most common? What branch and displacement distances are used?

x86 SPECInt92 Operation Frequency Operation Avg Int % Load 22 Cond branch 20 Compare 16 Store 12 Add 8 And 6 Sub 5 Move 4 Call 1 Return 1 Total 96

Control Flow Operations Conditional branches (usually PC-relative) Condition codes Condition register Compare and branch Jumps (e.g., unconditional branches) Procedure calls and returns Who saves what (return address, registers, params, etc.), where (stack, register) and when (caller, callee) Combination of HW and SW conventions

Control Flow Op. Frequency

Addressing for Control Flow Register indirect (for dynamic targets) PC-relative displacement

Unconventional Operations Decimal operations (HP-PA, F-P is used in x86) String operations (x86) Lack of byte instructions (early Alpha) Synchronization (atomic swap, fence ) Predicated execution (conditional moves) Cache hints (prefetch, flush) TLB instructions (TLB miss handled by software in MIPS) Multimedia (Sparc, MMX) Bit manipulation (Intel IXP) Thread management (SMT)

Registers Types of registers Integer (often 32 in number) Floating-point (often 32) Special GPRs Stack pointer, frame pointer, the PC (VAX) Special purpose registers Control registers, segment registers (x86) Organization Flat Windows (Sparc) Hierarchy (Cray)

Addressing and Byte Ordering How are bytes ordered in multi-byte data objects? Example: 32-bit integer at address 0x100 [x 31, x 30,, x 0 ] when broken into bytes, [x 31,,x 24 ], [x 23,,x 16 ], [x 15,,x 8 ], [x 7,,x 0 ] 0x100 0x101 0x102 0x103 Big-endian [x 31,,x 24 ] [x 23,,x 16 ] [x 15,,x 8 ] [x 7,,x 0 ] Little-endian [x 7,,x 0 ] [x 15,,x 8 ] [x 23,,x 16 ] [x 31,,x 24 ] Big-endian: most significant byte at lower address.

Taxonomy of Addressing Modes General purpose Register, immediate, absolute and displacement Often useful Indexed, scaled-index Special purpose or obsolete Memory indirect, auto - increment and decrement Mode Example Use Register Add R4,R3 Values in registers Immediate Add R4,#3 Static constants Displacement Add R4,100(R1) Local variables Reg indirect Add R4,(R1) Pointers, calc addresses Indexed Add R3,(R1+R2) R1 array base, R2 index Absolute Add R1,(1001) Static data Immediate, displacement, and absolute have a distinct cost i.e., occupy bits in instruction

Addressing Modes (from VAX)

Displacement Distance for Data

Frequency of Immediates

Size of Immediates

New Architectures Memory addressing Modes: Immediate of 8-16 bits displacement (subsumes register indirect) of 12-16 bits Instructions Simple: load, store, add, subtract, move register-register and shift Operand types Integer: 8-, 16-, 32- and 64-bit Floating point: 32- and 64-bit Control flow: PC-relative branch displacement of 8 bits, register indirect for procedure calls and returns

Additional Topics VLIW very long instruction word architectures Multithreading Exception handling

Assignment No class meeting next Monday Readings For Wednesday H&P: Appendix A, sections A1- A.2 V&L: Ch. 3 For Monday (Sept 14) HW1 will be assigned, available on the course calendar Revisit VHDL materials