Reconfigurable Computing Systems ( L) Fall 2012 Tiny Register Machine (TRM)

Similar documents
Reconfigurable Computing Systems ( L) Fall 2012 Microarchitecture: Single Cycle Implementation of TRM

Architecture. Digital Computer Design

CISC 662 Graduate Computer Architecture. Lecture 4 - ISA MIPS ISA. In a CPU. (vonneumann) Processor Organization

CISC 662 Graduate Computer Architecture. Lecture 4 - ISA

COMPSCI 313 S Computer Organization. 7 MIPS Instruction Set

10-1 C D Pearson Education, Inc. M. Morris Mano & Charles R. Kime LOGIC AND COMPUTER DESIGN FUNDAMENTALS, 4e

EE 3170 Microcontroller Applications

ELEC / Computer Architecture and Design Fall 2013 Instruction Set Architecture (Chapter 2)

Instructions: MIPS ISA. Chapter 2 Instructions: Language of the Computer 1

Chapter 04: Instruction Sets and the Processor organizations. Lesson 08: Processor Instructions - Part 1

CprE 288 Introduction to Embedded Systems ARM Assembly Programming: Translating C Control Statements and Function Calls

Computer Organization MIPS ISA

Instructions: Language of the Computer

CS3350B Computer Architecture

Chapter 3. Instructions:

Programmable Machines

Programmable Machines

Chapter 2A Instructions: Language of the Computer

CprE 288 Introduction to Embedded Systems Course Review for Exam 3. Instructors: Dr. Phillip Jones

1 5. Addressing Modes COMP2611 Fall 2015 Instruction: Language of the Computer

Computer Architecture

EC 413 Computer Organization

Control Instructions. Computer Organization Architectures for Embedded Computing. Thursday, 26 September Summary

Control Instructions

Processor Status Register(PSR)

MIPS R-format Instructions. Representing Instructions. Hexadecimal. R-format Example. MIPS I-format Example. MIPS I-format Instructions

Unsigned and signed integer numbers

Stored Program Concept. Instructions: Characteristics of Instruction Set. Architecture Specification. Example of multiple operands

Lecture 2. Instructions: Language of the Computer (Chapter 2 of the textbook)

Topic Notes: MIPS Instruction Set Architecture

Assembly language Simple, regular instructions building blocks of C, Java & other languages Typically one-to-one mapping to machine language

Machine Language Instructions Introduction. Instructions Words of a language understood by machine. Instruction set Vocabulary of the machine

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

Computer Science and Engineering 331. Midterm Examination #1. Fall Name: Solutions S.S.#:

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

Course Administration

ARM Assembly Language. Programming

Lectures 3-4: MIPS instructions

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

Assembly language Simple, regular instructions building blocks of C, Java & other languages Typically one-to-one mapping to machine language

Course Administration

ECE232: Hardware Organization and Design. Computer Organization - Previously covered

Instructions: Language of the Computer

Comparison InstruCtions

Chapter 2. Instruction Set Architecture (ISA)

The Assembly Language of the Boz 5

CENG3420 Lecture 03 Review

Overview. Introduction to the MIPS ISA. MIPS ISA Overview. Overview (2)

Chapter 2. Instructions:

Introduction to the MIPS. Lecture for CPSC 5155 Edward Bosworth, Ph.D. Computer Science Department Columbus State University

Computer Organization and Structure. Bing-Yu Chen National Taiwan University

Chapter 2. Computer Abstractions and Technology. Lesson 4: MIPS (cont )

Microcontroller Systems

Instructions: MIPS arithmetic. MIPS arithmetic. Chapter 3 : MIPS Downloaded from:

COMP MIPS instructions 2 Feb. 8, f = g + h i;

Chapter 2. Instructions: Language of the Computer. HW#1: 1.3 all, 1.4 all, 1.6.1, , , , , and Due date: one week.

Computer Organization and Components

Chapter 2: Instructions:

Basic Processor Design

Chapter 3 MIPS Assembly Language. Ó1998 Morgan Kaufmann Publishers 1

Lecture VIII: Branching and Control Statements. Xuan Guo. CSC 3210 Computer Organization and Programming Georgia State University.

Systems Architecture I

Thomas Polzer Institut für Technische Informatik

Exam 1 Fun Times. EE319K Fall 2012 Exam 1A Modified Page 1. Date: October 5, Printed Name:

ECE 486/586. Computer Architecture. Lecture # 8

EEM870 Embedded System and Experiment Lecture 4: ARM Instruction Sets

Chapter 2. Instructions: Language of the Computer. Adapted by Paulo Lopes

Assembly Language. Prof. Dr. Antônio Augusto Fröhlich. Sep 2006

Computer Organization and Structure. Bing-Yu Chen National Taiwan University

Exam 1. Date: Oct 4, 2018

COMPUTER HARDWARE. Instruction Set Architecture

EEC 581 Computer Architecture Lecture 1 Review MIPS

Math 230 Assembly Programming (AKA Computer Organization) Spring 2008

EE319K Exam 1 Summer 2014 Page 1. Exam 1. Date: July 9, Printed Name:

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

Computer Science 324 Computer Architecture Mount Holyoke College Fall Topic Notes: MIPS Instruction Set Architecture

Instructions: Assembly Language

ECE260: Fundamentals of Computer Engineering

ECE232: Hardware Organization and Design

TABLE 9-1. Symbolic Convention for Addressing Modes. Register indirect LDA (R1) ACC M[ R1] Refers to Figure 9-4. Addressing mode. Symbolic convention

ARM Shift Operations. Shift Type 00 - logical left 01 - logical right 10 - arithmetic right 11 - rotate right. Shift Amount 0-31 bits

Design of Digital Circuits 2017 Srdjan Capkun Onur Mutlu (Guest starring: Frank K. Gürkaynak and Aanjhan Ranganathan)

Elementos de Lógica Digital II

Instructions: Language of the Computer

EE319K Fall 2013 Exam 1B Modified Page 1. Exam 1. Date: October 3, 2013

Chapter 1. Computer Abstractions and Technology. Lesson 3: Understanding Performance

are Softw Instruction Set Architecture Microarchitecture are rdw

CS222: MIPS Instruction Set

ISA and RISCV. CASS 2018 Lavanya Ramapantulu

MIPS (SPIM) Assembler Syntax

ece4750-tinyrv-isa.txt

Format. 10 multiple choice 8 points each. 1 short answer 20 points. Same basic principals as the midterm

MIPS PROJECT INSTRUCTION SET and FORMAT

COMPUTER ORGANIZATION AND DESIGN. 5 th Edition. The Hardware/Software Interface. Chapter 4. The Processor

COMPUTER ORGANIZATION AND DESIGN. 5 th Edition. The Hardware/Software Interface. Chapter 4. The Processor

Stored Program Concept. Instructions: Characteristics of Instruction Set. Architecture Specification. Example of multiple operands

Chapter 4. Instruction Execution. Introduction. CPU Overview. Multiplexers. Chapter 4 The Processor 1. The Processor.

(2) Part a) Registers (e.g., R0, R1, themselves). other Registers do not exists at any address in the memory map

(Refer Slide Time: 1:40)

CS3350B Computer Architecture MIPS Instruction Representation

Transcription:

Reconfigurable Computing Systems (252-2210-00L) Fall 2012 Tiny Register Machine (TRM) L. Liu Department of Computer Science, ETH Zürich Fall semester, 2012 1

Introduction Jumping up a few levels of abstraction. Architecture: the programmer s view of the computer Defined by instructions (operations) and operand locations Microarchitecture: how to implement an architecture in hardware Application Software O perating System s Architecture M icroarchitecture Logic D igital Circuits Analog Circuits Devices program s device drivers instructions registers datapaths controllers adders m em ories AND gates N O T gates am plifiers filte rs transistors diodes Physics electrons Adapted from Digital Design and Computer Architecture, David Money Harris & Sarah L. Harris @2007 Elsevier 2

Assembly Language To command a computer, you must understand its language. Instructions: words in a computer s language Instruction set: the vocabulary of a computer s language Instructions indicate the operation to perform and the operands to use. Assembly language: human-readable format of instructions Machine language: computer-readable format (1 s and 0 s) Assembler: a tool to translate assembly code into machine code TRM (Tiny Register Machine) architecture: Designed by Prof. Niklaus Wirth and implemented on Xilinx Spartan-3, Virtex-5 and Spartan-6 by Ling Liu. A RISC processor that only contains the necessary instructions to run an application written in a high-level language. Once you ve learned one architecture, it s easy to learn others. 3

Architecture Design Principles Underlying design principles, as articulated by Hennessy and Patterson: 1.Simplicity favors regularity 2.Make the common case fast 3.Smaller is faster 4.Good design demands good compromises 4

Design Principle 1 Simplicity favors regularity - Consistent instruction format - Same number of operands, easier to encode and handle in hardware TRM instruction encoding 5

Design Principle 2 Make the common case fast - ALU operations are performed on registers and constants - TRM is a reduced instruction set computer (RISC), with a small number of simple instructions. - The main characteristic of RISC architecture is to allow most instructions to be executed in one clock cycle. 6

Design Principle 3 Smaller is Faster - TRM includes only a small number of registers - Just as retrieving data from a few books on your table is faster than sorting through 1000 books, retrieving data from 32 registers is faster than retrieving it from 1000 registers or a large memory. 7

Design Principle 4 Good design demands good compromises - Multiple instruction formats allow flexibility - ADD, SUB: use 2 register operands - LD, ST: use 2 register operands and a constant - Number of instruction formats kept small - to adhere to design principles 1 and 3 (simplicity favors regularity and smaller is faster). 8

TRM Machine Language Computers only understand 1 s and 0 s Machine language: binary representation of instructions 18-bit instructions Three instruction types: Type a: arithmetical and logical operations Type b: load and store instructions Type c: branch instructions (for jumping) 9

Type a: Arithmetical and Logical Instructions 1 or 2 register operands: Rs: source registers Rd: destination register n: immediate, zero-extended Other fields: op: the operation code or opcode regsel: bit 10 (1 means source operand comes from Rs register) 10

The TRM Registers Name R0~R7 R7 R6 PC C N Z V Register Number 0 ~ 7 7 6 Usage Working register Normally used as link register Normally used as stack pointer Program pointer Carry flag (1 bit) Sign flag (1 bit) Zero flag (1 bit) Overflow flag (1 bit) 11

can be ignored

The Power of the Stored Program 18-bit instructions and 32-bit data stored in memory Sequence of instructions: only difference between two applications (for example, a text editor and a video game) To run a new program: No rewiring required Simply store new program in memory The processor hardware executes the program: fetches (reads) the instructions from instruction memory in sequence performs the specified operation The program counter (PC) keeps track of the current instruction In TRM, programs start at memory address 0x000 13

The Stored Program Assembly Code LD R2, [R0+32] ADD R1, R2 SUB R0, 12 SUB R0, R5 Machine Code 0x31100 0x08C02 0x0C00C 0x0C405 Stored Program Address Instructions 003 0C405 002 0C00C 001 08C02 000 31100 PC Instruction Memory 14

Type b: Load and Store Instructions memory base address register (Rs) 7-bit offset (n), zero-extended Bit 10 is always 0 for TRM, 1 for VTRM 15

op instruction operation code (binary) 1100 LD Rd, Rs, n If Rs = R7 then Rd := mem[n] else Rd := mem[rs+n] 1101 ST Rd, Rs, n If Rs = R7 then Mem[n] := Rd else Mem[Rs+n] := Rd 1100ddd0nnnnnnnsss 1101ddd0nnnnnnnsss

Type c: Branch Instructions Jump conditions (cond) 10/14-bit address offset operand (off) 17

Branch Instructions op instruction operation code (binary) 1110 Bc n PC := PC + 1 + n, on condition c 1111 BL n R7 := PC + 1; PC := PC +1+n 1110ccccnnnnnnnnnn 1111nnnnnnnnnnnnnn 18

Branching Allows a program to execute instructions out of sequence. Types of branches: Conditional branches branch if equal (BEQ) branch if not equal (BNE) Unconditional branches BT jump register (BR) jump and link (BL, BLR) 19

cond condition meaning Mnemonic 0000 Z Zero / equal BEQ (BZS) 0001 ~Z Non-zero / unequal BNE (BZC) 0010 C Carry / above or equal (unsigned) BAE (BCS) 0011 ~C No carry / below (unsigned) BB (BCC) 0100 N Negative BN (BNS) 0101 ~N Not negative BNN (BNC) 0110 V Overflow BO (BVS) 0111 ~V No overflow BNO (BVC) 1000 ~(~C Z) Carry and no zero / above (unsigned) BA 1001 ~C Z No carry or zero / below or equal (unsigned) BBE 1010 ~(N V) N=V / greater or equal (signed) BGE 1011 N V N V / less (signed) BLT 1100 ~((N V) Z) greater or equal and ~ZF / greater (signed) BGT 1101 (N V) Z less or Z / less or equal (signed) BLE 1110 TRUE Always BT (B) 1111 FALSE Never BF N = bit 31 of result Z = all 32 bits are zero C = carry V = overflow

Conditional Branching (*TRM assembly*) MOV R0, 4 (*R0 = 4*) MOV R1, 1 (*R1 = 1*) SUB R0, R1 (*R0 = R0 R1 = 3*) BNE target (*branch is taken*) ADD R1, 3 (*not executed*) target: (*label*) ADD R1, R1 (*R1 = 1+1 = 2*) Labels indicate instruction locations in a program. 21

The Branch Not Taken (*TRM assembly*) MOV R0, 4 (*R0 = 4*) MOV R1, 1 (*R1 = 1*) SUB R0, R1 (*R0 = R0 R1 = 3*) BEQ target (*branch is not taken*) ADD R1, 3 (*executed*) target: (*label*) ADD R1, R1 (*R1 = 1+1 = 2*) 22

Unconditional Branching / Jumping (BT) (*TRM assembly*) MOV R0, 4 (*R0 = 4*) MOV R1, 1 (*R1 = 1*) BT target (*jump to target*) ROR R1 2 (*not executed*) target: ADD R1, R0 (*R1 = 1 + 4 = 5*) 23

Review: Instruction Formats 24

High-Level Code Constructs if statements if/else statements while loops for loops 25

If Statement High-level code IF i = j THEN f := g + h; TRM assembly code (* R0 = f, R1 = g, R2 = h R3 = i, R4 = j*) f := f i; 26

If Statement High-level code IF i = j THEN f := g + h; f := f i; TRM assembly code (* R0 = f, R1 = g, R2 = h R3 = i, R4 = j*) SUB R4, R3 BNE L1 ADD R1, R2 MOV R0, R1 L1: SUB R0, R3 Done: BT Done Notice that the assembly tests for the opposite case (i!= j) than the test in the high-level code (i == j). 27

If / Else Statement High-level code IF i = j THEN f := g + h; ELSE f := f i; TRM assembly code (* R0 = f, R1 = g, R2 = h R3 = i, R4 = j *) 28

If / Else Statement High-level code IF i = j THEN f := g + h; ELSE f := f i; TRM assembly code (* R0 = f, R1 = g, R2 = h R3 = i, R4 = j*) SUB R4, R3 BNE L1 ADD R1, R2 MOV R0, R1 BT Done L1: SUB R0, R3 Done: BT Done 29

While Loops High-level code (* determines the power of x such that 2 x = 128*) TRM assembly code (*R0 = pow, R1 = x*) VAR pow, x: INTEGER; BEGIN pow := 1; x := 0; END WHILE pow # 128 DO pow := pow * 2; x := x + 1; END 30

While Loops High-level code (* determines the power of x such that 2 x = 128*) VAR pow, x: INTEGER; BEGIN pow := 1; x := 0; END WHILE pow # 128 DO pow := pow * 2; x := x + 1; END TRM assembly code (*R0 = pow, R1 = x*) MOV R0, 1 MOV R1, 0 while: MOV R2, R0 SUB R2, 128 BEQ done ADD R0, R0 ADD R1, 1 BT while done: BT done Notice that the assembly tests for the opposite case (pow == 128) than the test in the high-level code (pow!= 128). 31

For Loops The general form of a for loop is: FOR initialization TO condition BY loop operation DO loop body END initialization: executes before the loop begins condition: is tested at the beginning of each iteration loop operation: executes at the end of each iteration loop body: executes each time the condition is met 32

For Loops High-level code (* add the numbers from 0 to 9*) VAR sum, i: INTEGER BEGIN sum := 0; TRM assembly code (*R0 = i, R1 = sum*) END FOR i:=0 TO 9 BY 1 DO sum := sum + i; END 33

For Loops High-level code (* add the numbers from 0 to 9*) VAR sum, i: INTEGER BEGIN sum := 0; END FOR i:=0 TO 9 BY 1 DO sum := sum + i; END TRM assembly code (*R0 = i, R1 = sum*) MOV R1, 0 MOV R0, 0 for: MOV R2, R0 SUB R2, 10 BEQ done ADD R1, R0 ADD R0, 1 BT for done: BT done Notice that the assembly tests for the opposite case (i == 10) than the test in the high-level code (i!= 10). 34

Arrays Useful for accessing large amounts of similar data Array element: accessed by index Array size: number of elements in the array 35

Arrays 5-element array Base address = 0x010 (address of the first array element, array[0]) First step in accessing an array: load base address into a register 36

Arrays // high-level code int array[5]; array[0] = 5; array[0] = array[0] * 2; array[1] = array[1] * 2; ; TRM assembly code ; Array base address = R0 37

Arrays (*high-level code*) VAR array: ARRAY 5 OF INTEGER; array[0] := 5; array[0] := array[0] * 2; array[1] := array[1] * 2; (* TRM assembly code array base address = R0*) MOV R0, 0 (*put 0x00 in R0*) MOV R1, 5 ST R1, [R0] (*array[0] = 5*) LD R1, [R0] (*R1 = array[0]*) ROR R1, 31 BIC R1, 1 (*array[0] = array[0] * 2*) ST R1, [R0] LD R1, [R0+1] (*R1 = array[1]*) ROR R1, 31 BIC R1, 1 ST R1 [R0+1] 38

Arrays Using For Loops (*high-level code*) VAR array : ARRAY 1000 OF INTEGER; i: INTEGER; BEGIN FOR i:=0 TO 999 DO array[i] = array[i] * 8; END END (* TRM assembly code R0 = array base address, R3 = i*) 39

Arrays Using For Loops (* TRM assembly code R0 = array base address, R3 = i*) MOV R0, 0 (*R0 = 0x00*) MOV R3, 0 (*i = 0*) loop: MOV R2, R3 SUB R2, 1000 BAE done (*if i >= 1000 then done*) MOV R2, R3 ADD R2, R0 LD R1, [R2] (*R0 = array[i]*) ROR R1, 29 BIC R1, 7 ST R1, [R2] ADD R3, 1 (*i = i + 1*) BT loop (*repeat*) done: BT done 40

Procedure Calls Definitions Caller: calling procedure (in this case, main) Callee: called procedure (in this case, sum) High-level code VAR y: INTEGER PROCEDURE sum(a, b: INTEGER):INTEGER; BEGIN RETURN (a + b); END BEGIN y := sum(42, 7);... END 41

Procedure Calls Procedure calling conventions: Caller: Callee: passes arguments to callee. jumps to the callee performs the procedure returns the result to caller returns to the point of call must not overwrite registers or memory needed by the caller TRM conventions: Call procedure: branch and link (BL) Return from procedure: jump register (BR) Argument values: can be passed via stack or registers Return value: passed via register R0 42

Procedure Calls TRM assembly code -------- code Proc.sum @00000001 --- BR R7 code Proc.@Body @00000010 --- 0x019 BL -25 --> 00000001 [Proc.sum] 0x020... BL: jumps to sum and saves PC+1 in the return address register (R7). In this case, R7 = 0x020 after BL executes. BR R7: jumps to address in R7, in this case 0x011. 43

Looking Ahead Microarchitecture building TRM processor in hardware! Bring colored pencils 44