Computer Processors. Part 2. Components of a Processor. Execution Unit The ALU. Execution Unit. The Brains of the Box. Processors. Execution Unit (EU)

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

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

Instruction Set Architectures

CS 16: Assembly Language Programming for the IBM PC and Compatibles

Instruction Set Architecture (ISA) Data Types

EEM336 Microprocessors I. The Microprocessor and Its Architecture

Lecture (02) The Microprocessor and Its Architecture By: Dr. Ahmed ElShafee

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

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

Credits and Disclaimers

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

Hardware and Software Architecture. Chapter 2

Addressing Modes on the x86

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

Assembly Language Programming 64-bit environments

Introduction to Machine/Assembler Language

The von Neumann Machine

Program controlled semiconductor device (IC) which fetches (from memory), decodes and executes instructions.

RISC I from Berkeley. 44k Transistors 1Mhz 77mm^2

UNIT 2 PROCESSORS ORGANIZATION CONT.

Chapter 02: Computer Organization. Lesson 02: Functional units and components in a computer organization- Part 1: Processor

Advanced Microprocessors

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

The von Neumann Machine

CS24: INTRODUCTION TO COMPUTING SYSTEMS. Spring 2018 Lecture 4

EEM336 Microprocessors I. Addressing Modes

CSE351 Spring 2018, Midterm Exam April 27, 2018

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

Introduction to IA-32. Jo, Heeseung

INTRODUCTION TO IA-32. Jo, Heeseung

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

Instruction Set Architectures

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

Assembly Language Programming Introduction

Chapter 2: The Microprocessor and its Architecture

x86 Programming I CSE 351 Winter

Machine/Assembler Language Putting It All Together

Code segment Stack segment

The Microprocessor and its Architecture

Assembler Programming. Lecture 2

The x86 Architecture. ICS312 - Spring 2018 Machine-Level and Systems Programming. Henri Casanova

Reverse Engineering II: The Basics

Assembly Language for Intel-Based Computers, 4 th Edition. Chapter 2: IA-32 Processor Architecture Included elements of the IA-64 bit

CHAPTER 3 BASIC EXECUTION ENVIRONMENT

The x86 Architecture

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

CS Bootcamp x86-64 Autumn 2015

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

EC-333 Microprocessor and Interfacing Techniques

Complex Instruction Set Computer (CISC)

IA32 Intel 32-bit Architecture

CS241 Computer Organization Spring 2015 IA

Basic Execution Environment

Binary Numbers. The Basics. Base 10 Number. What is a Number? = Binary Number Example. Binary Number Example

Module 3 Instruction Set Architecture (ISA)

x86 Assembly Tutorial COS 318: Fall 2017

Assembly Language for x86 Processors 7 th Edition. Chapter 2: x86 Processor Architecture

MACHINE-LEVEL PROGRAMMING I: BASICS COMPUTER ARCHITECTURE AND ORGANIZATION

C to Assembly SPEED LIMIT LECTURE Performance Engineering of Software Systems. I-Ting Angelina Lee. September 13, 2012

Chapter 11. Addressing Modes

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

System calls and assembler

Operating Systems. Part 8. Operating Systems. What is an operating system? Interact with Applications. Vector Tables. The master software

Moodle WILLINGDON COLLEGE SANGLI (B. SC.-II) Digital Electronics

ADVANCED PROCESSOR ARCHITECTURES AND MEMORY ORGANISATION Lesson-11: 80x86 Architecture

Credits and Disclaimers

Microcomputer Architecture..Second Year (Sem.2).Lecture(2) مدرس المادة : م. سندس العزاوي... قسم / الحاسبات

Microprocessor (COM 9323)

A4 Sample Solution Ch3

8086 INTERNAL ARCHITECTURE

The Instruction Set. Chapter 5

Assembly Language. Lecture 2 - x86 Processor Architecture. Ahmed Sallam

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

x86 Programming I CSE 351 Autumn 2016 Instructor: Justin Hsia

Do not turn the page until 5:10.

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

Chapter 3: Addressing Modes

CMSC Lecture 03. UMBC, CMSC313, Richard Chang

Reverse Engineering II: The Basics

How Software Executes

Intel 8086 MICROPROCESSOR ARCHITECTURE

Assembly Language. Lecture 2 x86 Processor Architecture

Real instruction set architectures. Part 2: a representative sample

x64 Cheat Sheet Fall 2014

CC411: Introduction To Microprocessors

ADVANCE MICROPROCESSOR & INTERFACING

Lecture 5:8086 Outline: 1. introduction 2. execution unit 3. bus interface unit

1. Introduction to Assembly Language

x86 architecture et similia

Lab 2: Introduction to Assembly Language Programming

Intel 8086 MICROPROCESSOR. By Y V S Murthy

icroprocessor istory of Microprocessor ntel 8086:

MICROPROCESSOR PROGRAMMING AND SYSTEM DESIGN

Memory Models. Registers

Practical Malware Analysis

CS 261 Fall Machine and Assembly Code. Data Movement and Arithmetic. Mike Lam, Professor

iapx Systems Electronic Computers M

CMSC 313 COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE PROGRAMMING LECTURE 03, SPRING 2013

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

Von Neumann Architecture. Machine Languages. Context of this Lecture. High-Level Languages. Assembly Language: Part 1. Princeton University.

Transcription:

Part 2 Computer Processors Processors The Brains of the Box Computer Processors Components of a Processor The Central Processing Unit (CPU) is the most complex part of a computer In fact, it is the computer It works far different from a high-level language Execution Unit (EU) performs calculations & logic registers hold data Control Logic Unit (CLU) reads and decodes instructions talks to other components 2/13/2018 Sacramento State - Cook - CSc 35 - Spring 2018 3 2/13/2018 Sacramento State - Cook - CSc 35 - Spring 2018 4 Execution Unit Execution Unit The ALU Contains the hardware that executes tasks (your programs) Different in many processors Modern processors often use multiple execution units to execute instructions in parallel to improve performance The Arithmetic Logic Unit performs all calculations and comparisons Processor often contains special hardware for integer and floating point 2/13/2018 Sacramento State - Cook - CSc 35 - Spring 2018 5 2/13/2018 Sacramento State - Cook - CSc 35 - Spring 2018 6 1

Control Logic Unit (CLU) CLU Over Time Controls the processor Determines when instructions can be executed Controls internal operations fetch and execute each instruction and store result of each instruction In early processors CLU was a very small fraction of the hardware EU and the registers took most of the space New processors complex control unit one of the more difficult parts of a processor to design has increased in its percentage of the processor hardware 2/13/2018 Sacramento State - Cook - CSc 35 - Spring 2018 7 2/13/2018 Sacramento State - Cook - CSc 35 - Spring 2018 8 Computer Processors Over time, thousands of processors were developed Examples: Intel x86 IBM PowerPC MOS 6502 ARM Registers Where the work is done 2/13/2018 Sacramento State - Cook - CSc 35 - Spring 2018 9 Registers What are registers used for? In high level languages, you put active data into variables However, it works quite different on processors All computations performed are done in registers Registers are used to store anything the processor needs to keep to track of Examples: the result of calculations status information memory location of the running program and much more 2/13/2018 Sacramento State - Cook - CSc 35 - Spring 2018 11 2/13/2018 Sacramento State - Cook - CSc 35 - Spring 2018 12 2

What exactly is a register? General Purpose Registers A register is a memory location located on the processor itself Think of it as a special "variable" Designed to be fast Some are accessible and usable by a programs, but many are hidden. General Purpose Registers (GPR) don't have a specific purpose They are designed to be used by programs however they are needed Often, you must use registers to perform calculations 2/13/2018 Sacramento State - Cook - CSc 35 - Spring 2018 13 2/13/2018 Sacramento State - Cook - CSc 35 - Spring 2018 14 Some Special Registers Register Files Program counter controls the current memory location of the running program privileged only the processor and OS can change it Stack pointer tracks the top of the system stack you can modify this with care All the related registers are grouped into a register file Different processors access and use their register files in very different ways Some processors support multiple files 2/13/2018 Sacramento State - Cook - CSc 35 - Spring 2018 15 2/13/2018 Sacramento State - Cook - CSc 35 - Spring 2018 16 Instructions Instructions Your programs are simple Processors do not have the constructs you find in highlevel languages Examples: Blocks If Statements While Statements etc 2/13/2018 Sacramento State - Cook - CSc 35 - Spring 2018 18 3

Instructions Instructions Processors can only a series of simple tasks These are called instructions Examples: add two values together move a value jump to a memory location These instructions are used to create all logic needed by a program We will cover how to do this during the semester 2/13/2018 Sacramento State - Cook - CSc 35 - Spring 2018 19 2/13/2018 Sacramento State - Cook - CSc 35 - Spring 2018 20 Processor Instruction Set What exactly is an instruction? A processor's instruction set defines all the available instructions The instructions and their respective formats are very different for each processor An instruction is a series of bytes that contain everything the processor needs to know to do something An instruction must specify: operation what to do operands what data is to be used 2/13/2018 Sacramento State - Cook - CSc 35 - Spring 2018 21 2/13/2018 Sacramento State - Cook - CSc 35 - Spring 2018 22 Operation Codes Instruction Encoding Each instruction has an operation code (Opcode) This a unique value that specifies the exact operation to be performed by the processor Assemblers use friendly names for called mnemonics Each instruction on a computer is encoded into 1's and 0's All information that needs to be stored, has to be converted to bits 2/13/2018 Sacramento State - Cook - CSc 35 - Spring 2018 23 2/13/2018 Sacramento State - Cook - CSc 35 - Spring 2018 24 4

Typical Instruction Format Machine Code Example (not x86) The opcode contains a unique value that indicates the operation to be performed It is typically followed by various fields containing register codes, addressing data, etc ADD %r1, %r2 0 1 0 0 0 1 1 0 Opcode for ADD r1 r2 2/13/2018 Sacramento State - Cook - CSc 35 - Spring 2018 25 2/13/2018 Sacramento State - Cook - CSc 35 - Spring 2018 26 Types of Operations (Opcodes) Operations: Data Transfer Data Transfer Program Flow Control Arithmetic and Logic operations Input and Output Instructions One of the most common tasks is moving data to and from registers Classified into three categories: loading a register with data in memory storing data in a register into memory transferring data between registers 2/13/2018 Sacramento State - Cook - CSc 35 - Spring 2018 27 2/13/2018 Sacramento State - Cook - CSc 35 - Spring 2018 28 Operations: Control Flow Operations: Arithmetic and Logic Processors do not support blocks, If Statements, etc Instead, you must jump around code you don't want to execute This is the same of idea of GoTo Statements Many operations are used to modify data such as arithmetic, comparisons, and shifting Comparison is in this category when two operands are compared often one is subtracted from the other result sets Boolean flags more on this later! 2/13/2018 Sacramento State - Cook - CSc 35 - Spring 2018 29 2/13/2018 Sacramento State - Cook - CSc 35 - Spring 2018 30 5

Operations: Input and Output There are also a instructions that are designed to talk to ports, hard drives and other components However, in modern systems, these are privileged and only usable by the operating system You will use interrupts to tell the operating system to input/output data Original x86 Registers It was simple at first 2/13/2018 Sacramento State - Cook - CSc 35 - Spring 2018 31 Original x86 Registers Intel x86 Registers First "x86" was the Intel 8086 released in 1978 Attributes: 16-bit processor (registers were 16-bit) 16 registers can access of 1MB of RAM 8 Registers can be used by your programs Four General Purpose: AX, BX, CX, DX Four pointer index: SI, DI, BP, SP The remaining 8 are restricted Six segment: CS, DS, ES, FS, GS, SS One instruction pointer: IP One status register used in computations 2/13/2018 Sacramento State - Cook - CSc 35 - Spring 2018 33 2/13/2018 Sacramento State - Cook - CSc 35 - Spring 2018 34 Original General Purpose Registers Original General Purpose Registers However, back then (and now too) it is very useful to store 8-bit values So, Intel chopped 4 of the registers in half These registers have generic names of A, B, C, D The first and second byte can be used separately or used together Naming convention high byte has the suffix "H" low byte has the suffix "L" for both bytes, the suffix is "X" 2/13/2018 Sacramento State - Cook - CSc 35 - Spring 2018 35 2/13/2018 Sacramento State - Cook - CSc 35 - Spring 2018 36 6

Original General Purpose Registers Last the 4 Registers This essentially doubled the number of registers So, there are: four 16-bit registers or eight 8-bit registers (and any combination you can think off) The remaining 4 registers were not cut in half Used for storing indexes (for arrays) and pointers Their purpose DI destination index SI source index BP base pointer SP stack pointer 2/13/2018 Sacramento State - Cook - CSc 35 - Spring 2018 37 2/13/2018 Sacramento State - Cook - CSc 35 - Spring 2018 38 Original 16-Bit Registers Evolution to 64 Bit Registers This is going to hurt 2/13/2018 Sacramento State - Cook - CSc 35 - Spring 2018 39 Original x86 Registers Evolution to 32-bit The x86 processor has evolved continuously over the last (nearly) 4 decades It jumped to 32-bit, and then finally 64-bit The result is many of the registers have strange names When the x86 moved into the 32-bit era, Intel expanded the registers to 32-bit the 16-bit ones still exist but also have a 32-bit version they have the prefix "e" for extended New instructions were added (to use them) 2/13/2018 Sacramento State - Cook - CSc 35 - Spring 2018 41 2/13/2018 Sacramento State - Cook - CSc 35 - Spring 2018 42 7

Original Registers Expansion to 32-bit 2/13/2018 Sacramento State - Cook - CSc 35 - Spring 2018 43 2/13/2018 Sacramento State - Cook - CSc 35 - Spring 2018 44 Original Registers Expansion to 32-bit 2/13/2018 Sacramento State - Cook - CSc 35 - Spring 2018 45 2/13/2018 Sacramento State - Cook - CSc 35 - Spring 2018 46 Evolution to 64-bit Expansion to 64-bit Once again, the processor evolved now to 64-bit The registers were extended again the 64-bit have the prefix "r" for register 8 additional registers were added also, it is now possible to get 8-bit values from all registers (hardware is more consistent!) 2/13/2018 Sacramento State - Cook - CSc 35 - Spring 2018 47 2/13/2018 Sacramento State - Cook - CSc 35 - Spring 2018 48 8

Expansion to 64-bit Expansion to 64-bit 2/13/2018 Sacramento State - Cook - CSc 35 - Spring 2018 49 2/13/2018 Sacramento State - Cook - CSc 35 - Spring 2018 50 Expansion to 64-bit New 64-bit Registers: R8 R15 2/13/2018 Sacramento State - Cook - CSc 35 - Spring 2018 51 2/13/2018 Sacramento State - Cook - CSc 35 - Spring 2018 52 64-Bit Register Table 64-Bit Register Table Register 32-bit 16-bit 8-bit High 8-bit Low rax eax ax ah al rbx ebx bx bh bl rcx ecx cx ch cl rdx edx dx dh dl rsi esi si sil rdi edi di dil rbp ebp bp bpl rsp esp sp spl Register 32-bit 16-bit 8-bit High 8-bit Low r8 r8d r8w r8b r9 r9d r9w r9b r10 r10d r10w r10b r11 r11d r11w r11b r12 r12d r12w r12b r13 r13d r13w r13b r14 r14d r14w r14b r15 r15d r15w r15b 2/13/2018 Sacramento State - Cook - CSc 35 - Spring 2018 53 2/13/2018 Sacramento State - Cook - CSc 35 - Spring 2018 54 9

Basic Intel x86 Instructions Basic Intel x86 Instructions Feel the pow-wah of the x86! Each x86 instruction can have up to 2 operands Operands in x86 instructions are very versatile Often each argument can be either a memory address, register or an immediate value 2/13/2018 Sacramento State - Cook - CSc 35 - Spring 2018 56 Types of Operands Intel x86 Instruction Limits Registers Memory address Register pointing to memory A constant stored with the instruction this is called an immediate There are some limitations Some instructions must use an immediate Some instructions require a specific register to perform calculations 2/13/2018 Sacramento State - Cook - CSc 35 - Spring 2018 57 2/13/2018 Sacramento State - Cook - CSc 35 - Spring 2018 58 Intel x86 Instruction Limits Instruction: Move A register must always be involved processors use registers for all activity both operands cannot access memory at the same time the processor has to have it at some point! Also, obviously, the receiving field cannot be an immediate value The x86 Move Instruction combines load, store, and register transfer logic It is one of the most common instructions used in programs (true of all processors) Remember how often you use the assignment statement in C / Java? 2/13/2018 Sacramento State - Cook - CSc 35 - Spring 2018 59 2/13/2018 Sacramento State - Cook - CSc 35 - Spring 2018 60 10

Instruction: Move Example: Move immediate Immediate, Register, Memory Source is a immediate constant MOV source, destination MOV $42, %rax rax = 42; Register, Memory Destination is rax 2/13/2018 Sacramento State - Cook - CSc 35 - Spring 2018 61 2/13/2018 Sacramento State - Cook - CSc 35 - Spring 2018 62 Example: "A" Register Example: Move register to register # So many options! Source is rax mov $42, %al mov $13, %ah #low byte #high byte MOV %rax, %rbx rbx = rax; mov $47, %ax #both bytes Destination is rbx 2/13/2018 Sacramento State - Cook - CSc 35 - Spring 2018 63 2/13/2018 Sacramento State - Cook - CSc 35 - Spring 2018 64 Example: Move register to memory Instruction: Add & Subtract Source is rax MOV %rax, counter Memory location named 'Counter' The Add and Subtract instructions take two operands and store the result in the second operand This is the same as the += and -= operators used in Visual Basic.NET, C, C++, Java, etc 2/13/2018 Sacramento State - Cook - CSc 35 - Spring 2018 65 2/13/2018 Sacramento State - Cook - CSc 35 - Spring 2018 66 11

Instruction: Add Example: Move register to memory Immediate, Register, Memory ADD value, target Register, Memory Move memory into rax MOV counter, %rax ADD $2, %rax rax += 2; 2/13/2018 Sacramento State - Cook - CSc 35 - Spring 2018 67 2/13/2018 Sacramento State - Cook - CSc 35 - Spring 2018 68 Instruction: And & Or Instruction: Logical And The Logical And and Logical Or instructions take two operands and stores the result in the second operand This is the same as the ^= and = operators used in C, C++, Java, etc AND value, target 2/13/2018 Sacramento State - Cook - CSc 35 - Spring 2018 69 2/13/2018 Sacramento State - Cook - CSc 35 - Spring 2018 70 Example: Logical Or Instruction: Call #Convert 5 to ASCII '5' MOV $5, %rax OR $0x30, %rax 0011 0000 The Call Instruction transfers control to a memory location (a subroutine) Subroutines are analogous to the functions you wrote in Java Once it completes, execution continues after the call 2/13/2018 Sacramento State - Cook - CSc 35 - Spring 2018 71 2/13/2018 Sacramento State - Cook - CSc 35 - Spring 2018 72 12

Instruction: Call Example: Print an integer CALL address Usually a label an constant that holds an address #This is using the CSC35 library MOV $42, %rax CALL PrintInt This name is an address 2/13/2018 Sacramento State - Cook - CSc 35 - Spring 2018 73 2/13/2018 Sacramento State - Cook - CSc 35 - Spring 2018 74 13