Lecture 6: Instruction sets

Similar documents
Instruction Set. Instruction Sets Ch Instruction Representation. Machine Instruction. Instruction Set Design (5) Operation types

Instruction Sets Ch 9-10

Instruction Sets Ch 9-10

Introduction to IA-32. Jo, Heeseung

INTRODUCTION TO IA-32. Jo, Heeseung

Complex Instruction Set Computer (CISC)

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

Code segment Stack segment

Instruction Set II. COMP 212 Computer Organization & Architecture. COMP 212 Fall Lecture 7. Instruction Set. Quiz. What is an Instruction Set?

Module 3 Instruction Set Architecture (ISA)

Addressing Modes on the x86

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

The x86 Architecture

Reverse Engineering II: The Basics

CS241 Computer Organization Spring 2015 IA

Scott M. Lewandowski CS295-2: Advanced Topics in Debugging September 21, 1998

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

X86 Addressing Modes Chapter 3" Review: Instructions to Recognize"

The Microprocessor and its Architecture

T Reverse Engineering Malware: Static Analysis I

The Instruction Set. Chapter 5

Hardware and Software Architecture. Chapter 2

SPRING TERM BM 310E MICROPROCESSORS LABORATORY PRELIMINARY STUDY

Basic Execution Environment

Chapter 2. lw $s1,100($s2) $s1 = Memory[$s2+100] sw $s1,100($s2) Memory[$s2+100] = $s1

Lecture 3: Instruction Set Architecture

CS24: INTRODUCTION TO COMPUTING SYSTEMS. Spring 2018 Lecture 4

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

x86 Assembly Tutorial COS 318: Fall 2017

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

Assembler Programming. Lecture 2

Memory Models. Registers

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

IA32 Intel 32-bit Architecture

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

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

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

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

Reverse Engineering II: The Basics

UNIT 2 PROCESSORS ORGANIZATION CONT.

Dr. Ramesh K. Karne Department of Computer and Information Sciences, Towson University, Towson, MD /12/2014 Slide 1

Instruction Set Architecture (ISA) Data Types

Systems Architecture I

17. Instruction Sets: Characteristics and Functions

Instruction Set Architectures

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

Real instruction set architectures. Part 2: a representative sample

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

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

History of the Intel 80x86

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

CSC 2400: Computer Systems. Towards the Hardware: Machine-Level Representation of Programs

William Stallings Computer Organization and Architecture 8 th Edition. Chapter 11 Instruction Sets: Addressing Modes and Formats

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

CS241 Computer Organization Spring Introduction to Assembly

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

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

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

CSE2421 FINAL EXAM SPRING Name KEY. Instructions: Signature

Assembly Language: IA-32 Instructions

Assembly Language. Lecture 2 x86 Processor Architecture

Instruction Set Architectures

CSC 8400: Computer Systems. Machine-Level Representation of Programs

EC-333 Microprocessor and Interfacing Techniques

Lecture 4: Instruction Set Architecture

Intel 8086: Instruction Set

COMPUTER ARCHITECTURE

Lecture 8: RISC Ch 13 [Sta06] Instruction analysis RISC vs. CISC Register use. Computer Organization II. Pentium

Chapter 11. Addressing Modes

Machine and Assembly Language Principles

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

Lecture 8. CPU Examples & RISC. Ch [Sta10] Ch 13 [Sta10] Instruction analysis RISC vs. CISC Register use. x86/arm

16.317: Microprocessor Systems Design I Spring 2014

Instruction Set Architectures

Instruction-set Design Issues: what is the ML instruction format(s) ML instruction Opcode Dest. Operand Source Operand 1...

UMBC. contain new IP while 4th and 5th bytes contain CS. CALL BX and CALL [BX] versions also exist. contain displacement added to IP.

Computer Organization & Assembly Language Programming

iapx Systems Electronic Computers M

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

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

Grundlagen Microcontroller Processor Core. Günther Gridling Bettina Weiss

Instruction Set Principles and Examples. Appendix B

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

Lecture 8. CPU Examples & Ch 13 [Sta06] Instruction analysis RISC vs. CISC Register use. Ch [Sta06] Pentium/ARM

EEM336 Microprocessors I. The Microprocessor and Its Architecture

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

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

Chapter 2: The Microprocessor and its Architecture

Advanced Microprocessors

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

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

Microprocessor and Assembly Language Week-5. System Programming, BCS 6th, IBMS (2017)

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

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

Credits and Disclaimers

Computer System Architecture

CMSC Lecture 03. UMBC, CMSC313, Richard Chang

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

8086 INTERNAL ARCHITECTURE

Transcription:

Lecture 6 Instruction cycle Instruction sets (Käskykannat) CPU executes instructions one after another Execution of one instruction has several phases (see state diagram). The CPU repeats these phases Ch 10-11 [Sta09] Operations Operands Operand references (osoitustavat) Pentium / ARM (Sta06 Fig 10.1) 29.1.2010 2 Computer Instructions (konekäskyt) Instructions and data (käskyt ja data) Instruction set (käskykanta) = Set of instructions CPU knows Operation code (käskykoodi) What does the instruction do? Data references (viitteet) one, two, several? Where does the data come for the instruction? - Registers, memory, disk, I/O Where is the result stored? - Registers, memory, disk, I/O What instruction is executed next? I/O? Implicit? Explicit? Memory-mapped I/O references as if in memory Covered on Comp. Org I Access rate? 29.1.2010 3 data instructions value address (Sta06 Fig 10.11) Symbolic name (Sta09 Fig 11.11) 29.1.2010 4 Instruction types? Sta06 Table 10.3 What happens during instruction execution? Transfer between memory and registers LOAD, STORE, MOVE, PUSH, POP, Controlling I/O Memory-mapped I/O - same as I/O not memory-mapped own instructions to control Arithmetic and logical operations ADD, MUL, CLR, SET, COMP, AND, SHR, NOP, Conversions (esitystapamuunnokset) TRANS, CONV, 16bTo32b, IntToFloat, Transfer of control (käskyjen suoritusjärjestyksen ohjaus), conditional, unconditional JUMP, BRANCH, JEQU, CALL, EXIT, HALT, Service requests (palvelupyyntö) SVC, INT, IRET, SYSENTER, SYSEXIT, Privileged instructions (etuoikeutetut käskyt) DIS, IEN, flush cache, invalidate TLB, (Sta06 Table 10.4) 29.1.2010 5 29.1.2010 6 Comp. Org II, Spring 2010 1

What kind of data? Instruction representation (käskyformaatti) Integers, floating-points Boolean (totuusarvoja) Characters, strings IRA (aka ASCII), EBCDIC Vectors, tables N elements in sequence Memory references How many bits for each field in the instruction? How many different instructions? Maximum number of operands per instruction? Operands in registers or in memory? How many registers? Fixed or variable size (vakio vai vaihteleva koko)? Different sizes 8 /16/32/ 64b, Each type and size has its own operation code IBM S/390 (Sta06 Table 10.5) (Sta06 Table 10.1) 29.1.2010 7 29.1.2010 8 How many registers? Architectures Minimum 16 to 32 Work data in registers Different register (sets) for different purpose? Integers vs floating points, indices vs data, code vs. data All sets can start register numbering from 0 Opcode determines the set that is used More registers than can be referenced? CPU allocates them internally - Register window Example subprogram parameters always in registers - Programmer thing that registers are always r8-r15, - CPU used register set of 8-132 - (We ll come back to this later) Accumulator-based architecture (akkukone) Just one register, accumulator, implicit reference to it Stack-based (pinokone) See : Appendix 10A Operands in stack, implicit reference PUSH, POP Register-based (yleisrekisterikone) All registers of the same size Instructions have 2 or 3 operands Load/Store architecture Only LOAD/STORE have memory refs ALU-operations have 3 regs Example: JVM LOAD R3, C LOAD R2,B ADD R1,R2,R3 STORE R1,A 29.1.2010 9 29.1.2010 10 Byte ordering (tavujärjestys): Big vs. Little Endian How to store a multibyte scalar value? 0x1200: (sanaosoite) Word Byte (tavuosoitteet) Isoimmassa lopputavu Big-Endian: Most significant byte in lowest byte addr Little-Endian: Least signifant byte in lowest byte addr Pienimmässä lopputavu See : Appendix 10B STORE 0x11223344,0x1200??? 0x11 0x22 0x33 0x44 0x44 0x33 0x22 0x11 0x00000044 = 0x44 0x00 0x00 0x00 29.1.2010 11 Big vs. Little Endian ALU uses only one of them Little-endian: x86, Pentium, VAX Big-endian: IBM 370/390, Motorola 680x0 (Mac), most RISC-architectures ARM, a bi-endian machine, accepts both - System control register has 1 bit (E-bit) to incidate the endian mode - Program controls which to use Byte order must be known, when transfering data from one machine to another Internet uses big-endian format Socket library (pistokekirjasto) has routines htoi() and itoh() (Host to Internet & Internet to Host) ARM: (Sta09 Fig 10.5) 29.1.2010 12 Comp. Org II, Spring 2010 2

0010 10010 Data alignment (kohdentaminen) 0010 10100 0010 11000 16b data starts with even (parillinen) (byte)address 32b data starts with address divisible (jaollinen) by 4 64b data starts with address divisible by 8 Aligned data is easier to access 32b data can be loaded by one operation accessing the word address (sanaosoite) Unaligned data would contain no wasted bytes, but load r1, 0(r4) For example, loading 32b unaligned data requires two loads from memory (word address) and combining it load r1, 0(r4) shl r1, =16 load r2, 1(r4) shr r2, =16 or r1, r2 11 22 33 44 33 44 11 22 29.1.2010 13 Computer Organization II Memory references (Muistin osoitustavat) Ch 11 [Sta06] 29.1.2010 14 Where are the operands? Addressing modes (osoitusmuodot) In the memory Variable of the program, stack (pino), heap (keko) In the registers During the instruction execution, for speed Directly in the instruction Small constant values How does CPU know the specific location? Bits in the operation code Several alternative addressing modes allowed (Sta06 Fig 11.1) 29.1.2010 15 29.1.2010 16 Addressing modes (Sta06 Table 11.1) Displacement Address (siirtymä) Effective address = (R1) + A (tehollinen muistiosoite) Operand = (R) EA = Effective Address (A) = content of memory location A (R) = content of register R One register for the top-most stack item s address Register (or two) for the top stack item (or two) register content + constant in the instruction Constant relative small (8 b, 16 b?) Usage JUMP *+5 Relational to PC Relational to Base Indexing a table CALL SP, Summation(BX) ADDF F2,F2, Table(R5) Ref to record field MUL F4,F6, Salary(R8) Stack content STORE F2, -4(FP) (aktivointitietue) 29.1.2010 17 29.1.2010 18 Comp. Org II, Spring 2010 3

More addressing modes Autoincrement (before/after) Example CurrIndex=i++; Autodecrement (before/after) Example CurrIndex=--i; Autoincrement deferred Example Sum = Sum + (*ptrx++); Autoscale Example Double X; X=Tbl[i][j]; EA = (R), R (R) + S R (R) - S, EA = (R) Size of operand EA = Mem(R), R (R) + S EA = A + (R j ) + (R i ) * S Computer Organization II Pentium 29.1.2010 19 29.1.2010 20 Not aligned Pentium: Registers Little Endian General registers (yleisrekisterit), 32-b EAX, EBX, ECX, EDX accu, base, count, data ESI, EDI source & destination index ESP, EBP stack pointer, base pointer Part of them can be used as16-bit registers AX, BX, CX, DX, SI, DI, SP, BP Or even as 8-bit registers AH, AL, BH, BL, CH, CL, DH, DL Segment registers 16b CS, SS, DS, ES, FS, GS - code, stack, data, stack, extra data Program counter (käskynosoitin) EIP Extended Instruction Pointer Status register EFLAGS - overflow, sign, zero, parity, carry, Single / Double / Extended precision x86: Data types IEEE 754 standard (Sta09Table 10.2) 29.1.2010 21 29.1.2010 22 Pentium: Operations (just part of) Data transfers, arithmetics, moves, jumps, stricts, etc Pentium: MMX Operations (just part of) SIMD No under/overflow. Use closest representation (Sta06 Table 10.8) (Sta06 Table 10.11) 29.1.2010 23 29.1.2010 24 Comp. Org II, Spring 2010 4

x86 Addressing Pentium: Addressing modes (osoitustavat) Operand = (R) 1, 2, 4, 8B Registers: 1, 2, 4, 8B For indexing arrays For arrays in stack or for two dimensional arrays Pentium: Addressing Mode Calculation LA = (SR)+(I)*S+(B)+A different element size (Sta06 Table 11.2) (Sta06 Fig 11.2) 29.1.2010 25 29.1.2010 26 CISC Complex Instruction Set Computer Lot of alternative fields op-code only one always! Part may be present or absent in the bit sequence Prefix 0-4 bytes Interpretation of the rest of the bit sequence depends on the content of the preceding fields Plenty of alternative addressing modes (osoitustapa) At most one operand can be in the memory 24 different Backward compatibility OLD 16-bit 8086-programs must still work - How to handle old instructions: emulate, simulate? Addressing (Sta09 Fig 11.9) (Sta06 Fig 11.8) 29.1.2010 27 1. Operand (register) 2. operand (register) or form part of the addressing-mode 29.1.2010 28 Instruction prefix (optional) LOCK exclusive use of shared memory in multiprocessor env. REP repeat operation to all characters of a string Segment override (optional) Use the segment register explicitly specified in the instruction Else use the default segment register (implicit assumption) Operand size override (optional) Switch between 16 or 32 bit operand, override default size Address size override (optional) Switch between 16 or 32 bit addressing. Override the default, which could be either Opcode Each instruction has its own bit sequence (incl. opcode) Bits specify the size of the operand (8/16/32b) ModR/m(optional) Indicate, whether operand is in a register or in memory What addressing mode (osoitusmuoto) to be used Sometimes enhance the opcode information (with 3 bits) SIB = Scale/Index/Base (optional) Some addressing modes need extra information Scale: scale factor for indexing (element size) Index: index register (number) Base: base register (number) 29.1.2010 29 29.1.2010 30 Comp. Org II, Spring 2010 5

Computer Organization II Displacement (optional) Certain addressing modes need this 0, 1, 2 or 4 bytes (0, 8, 16 or 32 bits) Immediate (optional) Certain addressing modes need this, value for operand 0, 1, 2 or 4 bytes ARM 29.1.2010 31 29.1.2010 32 ARM: Instruction set (käskykanta) ARM Data Types RISC Reduced Instruction Set Computer Fixed instruction length (32b), regular format All instructions have the condition code (4 bits) Small number of different instructions Instruction type (3 bit) and additional opcode /modifier (5 bit) Easier hardware implementation, faster execution Longer programs? Load/Store-architecture 16 visible general registers (4 bits in the instruction) Fixed data size 8 (byte), 16 (halfword), 32 (word) bits - word aligned Unsigned integer and twos-complement signed integer Majority of implementations do not provide floating-point hardware Little and Big Endian supported status register state bit E define Thump instruction set uses 16 bit instructions 29.1.2010 33 29.1.2010 34 ARM Addressing modes ARM Addressing mode Load/Store Indirect base reg + offset Indexing alternatives Offset - Address is base + offset Preindex - Form address - Write address to base Postindex - Use base as address - Calculate new address to base Data Processing instructions Register addressing - Value in register operands may be scaled using a shift operator Or mixture of register and immediate addressing Branch instructions Immediate Instruction contains 24 bit value Shifted 2 bits left - On word boundary - Effective range +/-32MB from PC. 29.1.2010 35 29.1.2010 36 Comp. Org II, Spring 2010 6

ARM Load/Store Multiple Addressing ARM Instruction Formats Load/store subset of general-purpose registers 16-bit instruction field specifies list of registers Sequential range of memory addresses Base register specifies main memory address S = For data processing instructions, updates condition codes S = For load/store multiple instructions, execution restricted to supervisor mode P, U, W = distinguish between different types of addressing mode B = Unsigned byte (B==1) or word (B==0) access L = For load/store instructions, Load (L==1) or Store (L==0) L = For branch instructions, is return address stored in link register 29.1.2010 37 ARM Condition codes for conditional execution of any instruction RISC vs. CISC We ll return to this later (lecture 8) Condition flags: N, Z, C and V N Negative Z Zero C Carry V overflow High-level programming language RISC easy to execute High-level programming language CISC support high-level languages difficult to execute High-level programming language CISC support high-level lang difficult to execute HW (Pentium) SW (Crusoe) RISC easy to execute HW HW HW 29.1.2010 39 29.1.2010 40 Review Questions / Kertauskysymyksiä Fields of the instruction? How does CPU know if the integer is 16 b or 32 b? Meaning of Big-Endian? Benefits of fixed instruction size vs variable size instruction format? Millaisista osista konekielinen käsky muodostuu? Miten CPU tietää onko sen käsittelemä kokonaisluku 16- bittinen vai 32-bittinen? Mitä tarkoittaa Big-Endian? Mitä hyötyä on kiinteästä käskyformaatista verrattuna vaihtelevanpituiseen formaattiin? 29.1.2010 41 Comp. Org II, Spring 2010 7