COMP3221 lec23-decode.1 Saeid Nooshabadi COMP 3221 Microprocessors and Embedded Systems Lectures 23: Instruction Representation; Assembly and Decoding.

Slides:



Advertisements
Similar presentations
Machine cycle.
Advertisements

DAP teaching computer architecture at Berkeley since 1977
COMP3221 lec16-function-II.1 Saeid Nooshabadi COMP 3221 Microprocessors and Embedded Systems Lectures 16 : Functions in C/ Assembly - II
Instructor: Tor Aamodt
The Microprocessor and its Architecture
CEG3420 L1 Intro.1 Copyright (C) 1998 UCB CEG3420 Computer Design Lecture 1 Philip Leong.
1 Datapath and Control (Multicycle datapath) CDA 3101 Discussion Section 11.
CS3350B Computer Architecture Winter 2015 Lecture 4
COMP3221 lec9-logical-I.1 Saeid Nooshabadi COMP 3221 Microprocessors and Embedded Systems Lecture 9: C/Assembler Logical and Shift - I
COMP3221 lec-12-mem-II.1 Saeid Nooshabadi COMP 3221 Microprocessors and Embedded Systems Lecture 12: Memory Access - II
CPU Design. CS252/Culler Lec 1.2 1/22/02 Levels of Representation (61C Review) High Level Language Program Assembly Language Program Machine Language.
Welcome Class: IX-B.Std Subject: Computer Studies Conducted by Rashedul Islam Lecturer in Computer Science.
September, 2003 Saeid Nooshabadi
COMP3221 lec05-numbers-I.1 Saeid Nooshabadi COMP 3221 Microprocessors and Embedded Systems Lecture 5: Number Systems – I
CS 61C L13 Combinational Logic (1) A Carle, Summer 2005 © UCB inst.eecs.berkeley.edu/~cs61c/su05 CS61C : Machine Structures Lecture #13: Combinational.
COMP3221 lec06-numbers-II.1 Saeid Nooshabadi COMP 3221 Microprocessors and Embedded Systems Lecture 6: Number Systems - II
COMP3221 lec42-final-review.1 Saeid Nooshabadi COMP 3221 Microprocessors and Embedded Systems Lecture 42: End Episode
Elec2041 lec-11-mem-I.1 Saeid Nooshabadi COMP 3221 Microprocessors and Embedded Systems Lecture 11: Memory Access - I
COMP3221 lec04--prog-model.1 Saeid Nooshabadi COMP 3221 Microprocessors and Embedded Systems Lecture 4: Programmer’s Model of Microprocessors
ECE 232 L2 Basics.1 Adapted from Patterson 97 ©UCBCopyright 1998 Morgan Kaufmann Publishers ECE 232 Hardware Organization and Design Lecture 2 Computer.
CPEN Digital System Design Chapter 10 – Instruction SET Architecture (ISA) © Logic and Computer Design Fundamentals, 4 rd Ed., Mano Prentice Hall.
CS1104 Assembly Language: Part 1
CS / Schlesinger Lec1.1 1/20/99©UCB Spring 1999 Computer Architecture Lecture 1 Introduction and Five Components of a Computer Spring, 1999 Arie Schlesinger.
CS 61C L20 Introduction to Synchronous Digital Systems (1) Garcia, Fall 2004 © UCB Lecturer PSOE Dan Garcia inst.eecs.berkeley.edu/~cs61c.
Shift Instructions (1/4)
CS61C L20 Introduction to Synchronous Digital Systems (1) Garcia © UCB Lecturer PSOE Dan Garcia inst.eecs.berkeley.edu/~cs61c.
COMP3221 lec07-numbers-III.1 Saeid Nooshabadi COMP 3221 Microprocessors and Embedded Systems Lecture 7: Number Systems - III
Computer ArchitectureFall 2007 © Sep 10 th, 2007 Majd F. Sakr CS-447– Computer Architecture.
Lecture 7: Instruction Set Architecture CSE 30: Computer Organization and Systems Programming Winter 2014 Diba Mirza Dept. of Computer Science and Engineering.
CS2100 Computer Organisation Introduction (AY2015/6 Semester 1)
An Introduction Chapter Chapter 1 Introduction2 Computer Systems  Programmable machines  Hardware + Software (program) HardwareProgram.
Cs 152 L1 Intro.1 Patterson Fall 97 ©UCB What is “Computer Architecture” Computer Architecture = Instruction Set Architecture + Machine Organization.
Computer Architecture And Organization UNIT-II Multilevel View Point Of A Machine.
COMP3221 lec04--prog-model.1 Saeid Nooshabadi COMP 3221 Microprocessors and Embedded Systems Lecture 4: Programmer’s Model of Microprocessors
Computer Organization and Design Computer Abstractions and Technology
Computer Architecture Mehran Rezaei
Chapter 1 — Computer Abstractions and Technology — 1 The Computer Revolution Progress in computer technology – Underpinned by Moore’s Law Makes novel applications.
J. Stover, CSD-HS.  A computer is an electronic device that is programmed to accept data (input), process it into useful information (output), and store.
Introduction to Computer Organization
Computer Architecture CPSC 350
1 Computer Architecture Part II-B: CPU Instruction Set.
Princes Nora Bint Abdul Rahman University Dept. of Computer & Information Sciences CS 206D Computer Organization Course Introduction.
1 chapter 1 Computer Architecture and Design ECE4480/5480 Computer Architecture and Design Department of Electrical and Computer Engineering University.
Chapter 11: Operating System Support Dr Mohamed Menacer Taibah University
Sahar Mosleh California State University San MarcosPage 1 Assembly language and Digital Circuit By Sahar Mosleh California State University San Marcos.
CS 61C L4.1.1 Combinational Logic (1) K. Meinz, Summer 2004 © UCB CS61C : Machine Structures Lecture Logic Gates and Combinational Logic
EEL5708/Bölöni Lec 3.1 Fall 2006 Sept 1, 2006 Lotzi Bölöni EEL 5708 High Performance Computer Architecture Lecture 3 Review: Instruction Sets.
9/20/6Lecture 2 - Prog Model1 MicroBaby A simple micro-controller encompassing all the basics Start this class by organizing into groups.
1 TM 1 Embedded Systems Lab./Honam University ARM Microprocessor Programming Model.
Riyadh Philanthropic Society For Science Prince Sultan College For Woman Dept. of Computer & Information Sciences CS 251 Introduction to Computer Organization.
Computer Operation. Binary Codes CPU operates in binary codes Representation of values in binary codes Instructions to CPU in binary codes Addresses in.
CS4100: 計算機結構 Course Outline 國立清華大學資訊工程學系 九十九年度第二學期.
Computer Organization and Architecture Lecture 1 : Introduction
March, 2006 Saeid Nooshabadi
March 2006 Saeid Nooshabadi
May 2006 Saeid Nooshabadi ELEC2041 Microprocessors and Interfacing Lectures 23: Instruction Representation; Assembly and Decoding.
May 2006 Saeid Nooshabadi ELEC2041 Microprocessors and Interfacing Lectures 24: Compiler, Assembler, Linker and Loader – I
Overview Instruction Codes Computer Registers Computer Instructions
Computer Architecture CSCE 350
Computer Software CS 107 Lecture 2 September 1, :53 PM.
Figure 8.1 Architecture of a Simple Computer System.
COSC121: Computer Systems
Software comes from heaven when you have good hardware. Ken Olsen
Intro to Architecture & Organization
Systems Architecture II
Figure 8.1 Architecture of a Simple Computer System.
PIPELINING Santosh Lakkaraju CS 147 Dr. Lee.
MARIE: An Introduction to a Simple Computer
COMS 361 Computer Organization
Program Execution.
Presentation transcript:

COMP3221 lec23-decode.1 Saeid Nooshabadi COMP 3221 Microprocessors and Embedded Systems Lectures 23: Instruction Representation; Assembly and Decoding September, 2003 Saeid Nooshabadi

COMP3221 lec23-decode.2 Saeid Nooshabadi Overview °What computers really do fetch / decode / execute cycle °Assembly: action => to bits °Decoding: bits => actions °Disassembly °Conclusion

COMP3221 lec23-decode.3 Saeid Nooshabadi Review: What is Subject about? I/O systemProcessor Compiler Operating System (Windows XP) Application (Netscape) Digital Design Circuit Design Instruction Set Architecture °Coordination of many levels of abstraction Datapath & Control transistors Memory Hardware Software Assembler COMP3221

COMP3221 lec23-decode.4 Saeid Nooshabadi Review:Programming Levels of Representation High Level Language Program (e.g., C) Assembly Language Program (e.g. ARM) Machine Language Program (ARM) Control Signal Specification Compiler Assembler Machine Interpretation temp = v[k]; v[k] = v[k+1]; v[k+1] = temp; ldr r0, [r2, #0] ldr r1, [r2, #4] str r1, [r2, #0] str r0, [r2, #4] °°°° ALUOP[0:3] <= InstReg[9:11] & MASK COMP3221

COMP3221 lec23-decode.5 Saeid Nooshabadi Review: What Does a Computer Do? °Big Idea: Stored Program Concept encode instructions as numbers, data as numbers, store them all in memory Everything has an address °PC = address of current instruction to execute °Fetch instruction at PC °Decode it °Do what it tells you to do updates registers and memory updates PC

COMP3221 lec23-decode.6 Saeid Nooshabadi Review: What happens after ifetch/decode °Perform the operations that are specified in the instruction operand fetch: read values from registers execute -perform arithmetic/logic operation => reg -perform ldr (mem => reg) -perform str (reg => mem) compute next -PC <= PC + 4 for all of the above -PC <= jump, branch (if taken) °then fetch/decode the next instruction

COMP3221 lec23-decode.7 Saeid Nooshabadi Fetch/Decode/Execute Cycle inst <= Fetch MEM[ PC ] Decode( inst ) case ARITH/LOG REG inst <= REG inst OP inst REG inst PC <= PC + 4 case ARITH/LOG-immed REG inst <= REG inst OP inst IM inst PC <= PC + 4 case LOAD REG inst <= MEM[ REG inst + IM inst ] PC <= PC + 4 case STORE MEM[ REG inst + IM inst ] <= REG inst PC <= PC + 4 case CONTROL PC <= OP inst (PC, REG inst, IM inst ) MEM PC regs MEM PC regs beforeafter op + +4 inst + +4 op +4 op +4

COMP3221 lec23-decode.8 Saeid Nooshabadi Review: Instruction Set (ARM 7TDMI) °Set of instruction that a processor can execute °Instruction Categories Data Processing or Computational (Logical and Arithmetic Load/Store (Memory Access) Control Flow (Jump and Branch) Floating Point -coprocessor Memory Management Special Registers

COMP3221 lec23-decode.9 Saeid Nooshabadi ARM Data Processing Instructions All instructions 32 bits wide Immediate add r4, r5, #25 r4  r Register & Imm. Shifted Register add r4, r5, r6 r4  r5 + r6 add r4, r5, r6, lsl #2 r4  r5 + (r6 X 2 2 ) Register Shifted Register add r4, r5, r6, lsl r7 r4  r5 + (r6 X 2 r7 ) 3 types of addressing modes

COMP3221 lec23-decode.10 Saeid Nooshabadi ARM Load/Store Instructions (#1/3) All instructions 32 bits wide Imm. Shifted Register str r4, [r5, r6, lsl #2] r4  mem[r5 + (r6 X 2 2 )] 3 types of addressing modes immediate ldr r4, [r5, #25] r4  mem[r5 + 25] 1 0

COMP3221 lec23-decode.11 Saeid Nooshabadi ARM Load/Store Instructions (#2/3) All instructions 32 bits wide Imm. Shifted Register preindexed str r4, [r5, r6, lsl #2]! r4  mem[r5 + (r6 X 2 2 )] r5  r5 + r6 X types of addressing modes 1 Immediate preindexed ldr r4, [r5, #25]! r4  mem[r5 + 25] r5  r

COMP3221 lec23-decode.12 Saeid Nooshabadi ARM Load/Store Instructions (#3/3) All instructions 32 bits wide Imm. Shifted Register post indexed str r4, [r5], r6, lsl #2 r4  mem[r5] r5  r5 + r6 X types of addressing modes Immediate post indexed ldr r4, [r5], #25 r4  mem[r5] r5  r

COMP3221 lec23-decode.13 Saeid Nooshabadi ARM Branch Instructions All instructions 32 bits wide PC = PC + (SignExt(24 offset) <<00) Unconditional and Conditional Branches (L=0) here: b there... There: movs r4, r5 beq here Branch & Link (L=1) along with jump, the address of the next instruction is stored in r14. go back to instruction after bl instruction bl there add r5, r6, r7... There: mov r4, r5... mov, r15, r14 PC Relative Addressing

COMP3221 lec23-decode.14 Saeid Nooshabadi Conditional Execution Field 0000 = EQ - Z set (equal) 0001 = NE - Z clear (not equal) 0010 = HS / CS - C set (unsigned higher or same) 0011 = LO / CC - C clear (unsigned lower) 0100 = MI -N set (negative) 0101 = PL- N clear (positive or zero) 0110 = VS - V set (overflow) 0111 = VC - V clear (no overflow) 1000 = HI - C set and Z clear (unsigned higher) 1001 = LS - C clear or Z set (unsigned lower or same) 1010 = GE - N set and V set, or N clear and V clear (signed >or =) 1011 = LT - N set and V clear, or N clear and V set (signed <) 1100 = GT - Z clear, and either N set and V set, or N clear and V clear (signed >) 1101 = LE - Z set, or N set and V clear,or N clear and V set (signed <, or =) 1110 = AL - always 1111 = NV - reserved. cmp r1, r2 Instr COND

COMP3221 lec23-decode.15 Saeid Nooshabadi ARM Instruction Set Format Instruction type Data processing / PSR transfer Multiply Long Multiply (v3M / v4 only) Swap Load/Store Byte/Word Load/Store Multiple Halfword transfer:Immediate offset (v4 only) Halfword transfer: Register offset (v4 only) Branch Branch Exchange (v4T only) Coprocessor data transfer Coprocessor data operation Coprocessor register transfer Software interrupt Cond 0 0 I Opcode S Rn Rd Operand2 Cond A S Rd Rn Rs Rm Cond B 0 0 Rn Rd Rm Cond 0 1 I P U B W L Rn Rd Offset Cond P U S W L Rn Register List Cond U A S RdHi RdLo Rs Rm Cond P U 1 W L Rn Rd Offset1 1 S H 1 Offset2 Cond L Offset Cond P U N W L Rn CRd CPNum Offset Cond Op1 CRn CRd CPNum Op2 0 CRm Cond Op1 L CRn Rd CPNum Op2 1 CRm Cond SWI Number Cond Rn Cond P U 0 W L Rn Rd S H 1 Rm

COMP3221 lec23-decode.16 Saeid Nooshabadi Reading Material °Steve Furber: ARM System On-Chip; 2nd Ed, Addison-Wesley, 2000, ISBN: chapter 5 °ARM Architecture Reference Manual 2 nd Ed, Addison-Wesley, 2001, ISBN: ,, chapter A2: Programmer’s Model

COMP3221 lec23-decode.17 Saeid Nooshabadi Recall: Sample Assembly Program 0x80 0x84 0x88 0x8C 0x90 E3A02094 mov r2, #0x94 Instruction (Data proc.) Instruction (Data proc.) E3A05002 mov r5, #2 E ldr r0, [r2] 0x Instruction (Mem Access) Data 20 hex = Binary Contents E sub r0, r0, r5 E str r0, [r2] Instruction (Data proc) Instruction (Mem Access) 0x94 0x20 0x94 2 0x E C statement: k = k - 2 Location for variable k r2 0x94 r5 2 r2 r0 0x94 0x20 r0 r5 0x2 0x1E – r0 r2 r0 0x94 0x1E

COMP3221 lec23-decode.18 Saeid Nooshabadi Compilation & Assembly °How to turn notation programmers prefer into notation computer understands? °Program to translate C statements into Assembly Language instructions; called a compiler Example: compile by hand this C code: a = b + c; d = a - e; Ass: add r0, r1, r2 sub r3, r0, r4 Big Idea: compiler translates notation from 1 level of abstraction to lower level °Program to translate Assembly Language into machine instructions; called an assembler Ass: add r0, r1, r2 sub r3, r0, r4 Mach: 0xe xe Big Idea: assembler translates notation from 1 level of abstraction to lower level

COMP3221 lec23-decode.19 Saeid Nooshabadi Decoding Machine Language °How do we convert 1s and 0s to C code? °For each 32 bits: Look at bits : 00x means data processing, 01x Load/Store, 101 Branch. Use instruction type to determine which fields exist and convert each field into the decimal equivalent. Once we have decimal values, write out ARM assembly code. Logically convert this ARM code into valid C code.

COMP3221 lec23-decode.20 Saeid Nooshabadi Decoding Example (#1/7) °Here are seven machine language instructions in hex: e e3a00000 d1a0f00e e e d1a0f00e eafffffb Let the first instruction be at address 4,194, (0x ). °Next step: convert to binary

COMP3221 lec23-decode.21 Saeid Nooshabadi Decoding Example (#2/7) °Binary  Decimal  Assembly  C? °Start at program at address 4,194, = 0x (2 22 ) °What are instruction formats of these 7 instructions?

COMP3221 lec23-decode.22 Saeid Nooshabadi Decoding Example (#3/7) DPI CDPR DPI DPR CDPR BR DPI/DPR = Data Proc. immd./reg 2 nd opernd CDPR = Cond. DPRBR = Branch Inst. Type Cond. Opcode Flag setting S bit Rn Rd #rot Immd. shift Shift type #Shift Branch Offset 31 – – – 1615 – 1211 – Binary  Fields  Decimal  Assembly  C? Immd. Rm

COMP3221 lec23-decode.23 Saeid Nooshabadi Decoding Example (#4/7) Binary  Fields  Decimal  Assembly  C? DPI CDPR DPI DPR CDPR BR DPI CDPR DPI DPR CDPR BR DPI/DPR = Data Proc. immd./reg 2 nd opernd CDPR = Cond. DPRBR = Branch Opcode Rn Rd Rm

COMP3221 lec23-decode.24 Saeid Nooshabadi Decoding Example (#5/7) Binary  Fields  Decimal  Assembly  C? : cmp r2, # : mov r0, # : movle r15, r : subs r2, r2, # : add r0, r0, r : movle r15, r : b ;(pc–4*5) DPI CDPR DPI DPR CDPR BR DPI/DPR = Data Proc. immd./reg 2 nd opernd CDPR = Cond. DPRBR = Branch Rn Rd Rm Opcode

COMP3221 lec23-decode.25 Saeid Nooshabadi Decoding Example (#6/7) Binary  Fields  Decimal  Assembly  Symbolic Assembly  C? : cmp r2, # : mov r0, # : movle r15, r : subs r2, r2, # : add r0, r0, r : movle r15, r : b : : ;pc=419336–20 cmp r2, #0 mov r0, #0 movle r15, r14 Loop: subs r2, r2, #1 add r0, r0, r1 movle r15, r14 b Loop recall: branch target computed by adding offset (<<2) to address of branch inst plus 8

COMP3221 lec23-decode.26 Saeid Nooshabadi Decoding Example (#7/7) Binary  Fields  Decimal  Assembly  Symbolic Assembly  C? cmp a3, #0 mov a1, #0 movle pc, lr Loop: subs a3, a3, #1 add a1, a1, a2 movle pc, lr b Loop Mapping product:a1, mcand:a2, mlier:a3; product = 0; while (0 < mlier) { product = product + mcand; mlier = mlier - 1; } C ARMARM

COMP3221 lec23-decode.27 Saeid Nooshabadi Instruction Set Bridge °more than 1-1 encode/decode °many encoders & many decoders ARM Machine Language GCCCC ARM-elf/ARM-AXD ARM Assembly Language C JavaFortran ARM-elf PC GDB-Debug interpreter Many different implementations of ARM Machine Language (Instruction Set)

COMP3221 lec23-decode.28 Saeid Nooshabadi “And in Conclusion…” °Big Idea: fetch-decode-execute cycle °Big Idea: encoding / decoding compiler/assembler encodes instructions as numbers, computer decodes and executes them keyboard encodes characters as numbers, decoded on display °Instruction format certain fields determine how to decode the others each field has specific “decoding table” giving meaning to values highly structured and regular process