A Bit of History. Program Mem Data Memory. CPU (Central Processing Unit) I/O (Input/Output) Von Neumann Architecture. CPU (Central Processing Unit)

Similar documents
Instruction Set Architecture (ISA)

Behind the Curtain. Introduce TA Friday 1 st lab! (1:30-3:30) (Do Prelab before) 1 st Problem set on Thurs. Comp 411 Fall /16/13

Concocting an Instruction Set

Concocting an Instruction Set

A General-Purpose Computer The von Neumann Model. Concocting an Instruction Set. Meaning of an Instruction. Anatomy of an Instruction

Concocting an Instruction Set

Concocting an Instruction Set

Basic ARM InstructionS

6.004 Computation Structures Spring 2009

STEVEN R. BAGLEY ARM: PROCESSING DATA

Writing ARM Assembly. Steven R. Bagley

Designing an Instruction Set

Designing an Instruction Set

Comparison InstruCtions

Processor Status Register(PSR)

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

Chapter 15. ARM Architecture, Programming and Development Tools

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

Chapter 2 Instructions Sets. Hsung-Pin Chang Department of Computer Science National ChungHsing University

Branch Instructions. R type: Cond

Programmable Machines

Programmable Machines

Chapters 3. ARM Assembly. Embedded Systems with ARM Cortext-M. Updated: Wednesday, February 7, 2018

Assembly Language. CS2253 Owen Kaser, UNBSJ

ECE 486/586. Computer Architecture. Lecture # 7

ARM Cortex-A9 ARM v7-a. A programmer s perspective Part 2

ARM Instruction Set. Computer Organization and Assembly Languages Yung-Yu Chuang. with slides by Peng-Sheng Chen

ARM Assembly Programming

ECE 471 Embedded Systems Lecture 5

VE7104/INTRODUCTION TO EMBEDDED CONTROLLERS UNIT III ARM BASED MICROCONTROLLERS

ARM Instruction Set. Introduction. Memory system. ARM programmer model. The ARM processor is easy to program at the

CS 310 Embedded Computer Systems CPUS. Seungryoul Maeng

Hi Hsiao-Lung Chan, Ph.D. Dept Electrical Engineering Chang Gung University, Taiwan

Chapter 15. ARM Architecture, Programming and Development Tools

ARM Cortex M3 Instruction Set Architecture. Gary J. Minden March 29, 2016

ARM Instruction Set Architecture. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

Lecture 15 ARM Processor A RISC Architecture

ARM. Assembly Language and Machine Code. Goal: Blink an LED

ARM Assembly Language. Programming

Computer Architecture Prof. Smruthi Ranjan Sarangi Department of Computer Science and Engineering Indian Institute of Technology, Delhi

18-349: Introduction to Embedded Real- Time Systems Lecture 3: ARM ASM

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

COS 140: Foundations of Computer Science

CPE 323 MSP430 INSTRUCTION SET ARCHITECTURE (ISA)

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

LAB 1 Using Visual Emulator. Download the emulator Answer to questions (Q)

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

ISA and RISCV. CASS 2018 Lavanya Ramapantulu

ARM. Assembly Language and Machine Code. Goal: Blink an LED

Compilers and Interpreters

Lecture 5: Instruction Set Architectures II. Take QUIZ 2 before 11:59pm today over Chapter 1 Quiz 1: 100% - 29; 80% - 25; 60% - 17; 40% - 3

I ve been getting this a lot lately So, what are you teaching this term? Computer Organization. Do you mean, like keeping your computer in place?

ARM Ltd. ! Founded in November 1990! Spun out of Acorn Computers

CSEE 3827: Fundamentals of Computer Systems

Chapter 2. Instructions: Language of the Computer

The PAW Architecture Reference Manual

Computer Organization CS 206 T Lec# 2: Instruction Sets

Architecture. Digital Computer Design

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

EC 413 Computer Organization

CMSC Computer Architecture Lecture 2: ISA. Prof. Yanjing Li Department of Computer Science University of Chicago

ARM Processors ARM ISA. ARM 1 in 1985 By 2001, more than 1 billion ARM processors shipped Widely used in many successful 32-bit embedded systems

Worksheet #4 Condition Code Flag and Arithmetic Operations

ARM Cortex-M4 Architecture and Instruction Set 2: General Data Processing Instructions

University of California, San Diego CSE 30 Computer Organization and Systems Programming Winter 2014 Midterm Dr. Diba Mirza

The ARM processor. Morgan Kaufman ed Overheads for Computers as Components

ARM Architecture and Instruction Set

MNEMONIC OPERATION ADDRESS / OPERAND MODES FLAGS SET WITH S suffix ADC

9. Programmable Machines

COSC 122 Computer Fluency. Computer Organization. Dr. Ramon Lawrence University of British Columbia Okanagan

Raspberry Pi / ARM Assembly. OrgArch / Fall 2018

Slides for Lecture 6

CMPSCI 201 Fall 2004 Midterm #2 Answers

Architectures & instruction sets R_B_T_C_. von Neumann architecture. Computer architecture taxonomy. Assembly language.

Topic 10: Instruction Representation

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

COMP2121: Microprocessors and Interfacing. Instruction Set Architecture (ISA)

The ARM Instruction Set

ECE 498 Linux Assembly Language Lecture 5

Lecture 4: MIPS Instruction Set

are Softw Instruction Set Architecture Microarchitecture are rdw

The Assembly Language of the Boz 5

Instruction Set. ARM810 Data Sheet. Open Access - Preliminary

Lecture 4: Instruction Set Architecture

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

COMPUTER ORGANIZATION & ARCHITECTURE

What Are The Main Differences Between Program Counter Pc And Instruction Register Ir

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

ARM Assembly Language

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

UNIT 2 (ECS-10CS72) VTU Question paper solutions

Advanced processor designs

Grundlagen Microcontroller Processor Core. Günther Gridling Bettina Weiss

ARM ARCHITECTURE. Contents at a glance:

Cortex M3 Programming

Instruction Set Architecture. "Speaking with the computer"

Pipelined CPUs. Study Chapter 4 of Text. Where are the registers?

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

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

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

Transcription:

Memory COncepts Address Contents Memory is divided into addressable units, each with an address (like an array with indices) Addressable units are usually larger than a bit, typically 8, 16, 32, or 64 bits Each address has variable contents Memory contents might be: Integers in 2 s complement Floats in IEEE format Strings in ASCII or Unicode Data structure de jour ADDRESSES Nothing distinguishes the difference 0 0x0000002a 1 0x40490fd8 2 0x2065654C 3 0x74726148 4 0x20647542 5 0x6976654c 6 0x0020656c 7 0x00000002 8 0xe3a00000 9 0xe3a0100a 10 0xe0800001 11 0xe2511001 12 0x1afffffc 13 0xeafffffe 14 0x00004020 15 0x20090001 1

One More Thing INSTRUCTIONS for the CPU are stored in memory along with data CPU fetches instructions, decodes them and then performs their implied operation Mechanism inside the CPU directs which instruction to get next. They appear in memory as a string of bits that are typically uniform in size Their encoding as bits is called machine language. ex: 0c3c1d7fff We assign mnemonics to particular bit patterns to indicate meanings. These mnemonics are called Assembly language. ex: mov r1, #10 Address Contents 0 42 1 3.141592 2 Lee 3 Hart 4 Bud 5 Levi 6 le 7 2 8 mov r0, #0 9 mov r1, #10 10 add r0, r0, r1 11 subs r1, r1, #1 12 bne.-2 13 b. 14 0x00004020 15 0x20090001 2

A Bit of History There is a commonly recurring debate over whether data and instructions should be mixed. Leads to two common flavors of computer architectures Harvard Architecture I/O (Input/Output) CPU (Central Processing Unit) Program Mem Data Memory Von Neumann Architecture I/O (Input/Output) CPU (Central Processing Unit) Unified Memory 3

Harvard Architecture Instructions and data do not/should not interact. They can have different word sizes and exist in different address spaces - Advantages: No self-modifying code (a common hacker trick) Optimize word-lengths of instructions for control and data for applications Higher Throughput (i.e. you can fetch data and instructions from their memories simultaneously) - Disadvantages: The H/W designer decides the trade-off between how big of a program and how large are data Hard to write Native programs that generate new programs (i.e. assemblers, compilers, etc.) Hard to write Operating Systems which are programs that at various points treat other programs as data (i.e. loading them from disk into memory, swapping out processes that are idle) Howard Aiken: Architect of the Harvard Mark 1 4

Von Neumann Architecture Instructions are just a type of data that share a common word size and address space with other types. John Von Neumann: Proponent of unified memory architecture - Most common model used today, and what we assume in 411 - Advantages: S/W designer decides how to allocate memory between data and programs Can write programs to create new programs (assemblers and compilers) Programs and subroutines can be loaded, relocated, and modified by other programs (dangerous, but powerful) - Disadvantages: Word size must suit both common data types and instructions Slightly lower performance due to memory bottleneck (mediated in modern computers by the use of separate program and data caches) We need to be very careful when treading on memory. Folks have taken advantage of the program-data unification to introduce viruses. 5

Computer Systems At what level of abstraction can we understand a computer? Computing? Compiler for (i = 0; i < 3; i++) m += i*i; Assembler and Linker add r0, r0, #1 CPU Module A ALU B Cells Gates A B FA CO CI S Transistors 6

Concocting an Instruction Set Nerd Chef at work. move flour,bowl add milk,bowl add egg,bowl move bowl,mixer rotate mixer... Your first problem set is posted 7

INstructions are Simple Computers interpret programs by translating them from the high-level language where into low-level simple instructions that it understands High-Level Languages Compilers Interpreters Assembly Language int x, y; y = (x-3)*(y+123456) x:.word 0 y:.word 0 c:.word 123456 LDR R0, [R10, #0] ; get x SUB R0, R0, #3 LDR R1, [R10, #4] ; get y LDR R2, [R10, #8] ; get c ADD R1, R1, R2 MUL R0, R0, R1 STR R0, [R10, #4] ; save y 8

INstructions are Binary Computers interpret assembly programs by translating them from their mnemonic simple instructions into strings of bits Assembly Language Machine Language Note the one-to-one correspondence between lines of assembly code and Lines of machine code x:.word 0 y:.word 0 c:.word 123456... LDR R0, [R10, #0] ; get x SUB R0, R0, #3 LDR R1, [R10, #4] ; get y LDR R2, [R10, #8] ; get c ADD R1, R1, R2 MUL R0, R0, R1 STR R0, [R10, #4] ; save y 0x00000000 0x00000000 0x0001E240... 0xE59A0000 0xE2400003 0xE59A1004 0xE59A2008 0xE0811002 0xE0000190 0xE58A0004 9

A general-purpose COmputer The von Neumann Model Many architectural approaches to the general purpose computer have been explored. The one upon which nearly all modern computers is based was proposed by John von Neumann in the late 1940s. Its major components are: Input/ Output Central Processing Unit Main Memory My dog knows how to fetch! He s said bit before, but not too much about words Central Processing Unit (CPU): A device which fetches, interprets, and executes a specified set of operations called Instructions. Memory: storage of N words of W bits each, where W is a fixed architectural parameter, and N can be expanded to meet needs. I/O: Devices for communicating with the outside world. 10

Anatomy of an Instruction Computers execute a set of primitive operations called instructions Instructions specify an operation and its operands (arguments of the operation) Types of operands: destination, source, and immediate Why do all of the variables start with R? CPU s have a small number (16-32) of registers that are used for a small number of holding variables ADD R0, R1, R2 ADD R0, R1, #1 Operands (variables, arguments, etc.) Source Operands Destination Operand Immediate Operand 11

Meaning of an Instruction Operations are abbreviated into opcodes (1-4 letters) Instructions are specified with a very regular syntax Opcodes are followed by arguments Usually the destination is next, then one or more source arguments (This is not strictly the case, but it is generally true) Why this order? Analogy to high-level language like Java or C add R0, R1, R2 The instruction syntax provides operands in the same order as you would expect in a statement from a high level language. int r0, r1, r2; r0 = r1 + r2; Instead of: r1 + r2 = r0; 12

A Series of Instructions Generally Instructions are retrieved sequentially from memory An instruction executes to completion before the next instruction is started But, there are exceptions to these rules Instructions ADD R0, R1, R1 ADD R0, R0, R0 ADD R0, R0, R0 SUB R1, R0, R1 What does this program do? Variables R0:0 X 12X 24X 48 R1:6 X 42 R2:8 R3:10 13

Program Analysis Repeat the process treating the variables as unknowns or formal variables Knowing what the program does allows us to write down its specification, and give it a meaningful name The instruction sequence then becomes a general-purpose tool Instructions ADD R0, R1, R1 ADD R0, R0, R0 ADD R0, R0, R0 What does this program do? R0:w X 2xX 4xX 8x R1:x X 7x R2:y Variables SUB R1, R0, R1 R3:z 14

Looping the Flow Repeat the process treating the variables as unknowns or formal variables Knowing what the program does allows us to write down its specification, and give it a meaningful name The instruction sequence then becomes a general-purpose tool times7: Instructions ADD R0, R1, R1 ADD R0, R0, R0 An infinite loop Variables R0:w X 8x X 56x X 392x R1:x X 7x X 49x X 343x ADD R0, R0, R0 SUB R1, R0, R1 R2:y R3:z B times7 15

Open Issues in our Simple Model WHERE in memory are INSTRUCTIONS stored? HOW are instructions represented? WHERE are VARIABLES stored? What are LABELs? How do they relate to where instructions are stored? How about more complicated data types? Arrays? Data Structures? Objects? Where does a program start executing? When does it stop? 16

The Stored-Program Computer The von Neumann architecture addresses these issues as follows: Instructions and Data are stored in a common memory Sequential semantics: To the PROGRAMMER Memory all instructions appear to execute in an order, or sequentially Instruction Key idea: Memory holds not only data, but coded instructions that make up a program. Central Processing Unit CPU fetches and executes instructions from memory The CPU is a H/W interpreter Program IS simply DATA for this interpreter Main memory: Single expandable resource pool - constrains both data and program size - don t need to make separate decisions of how large of a program or data memory to buy Instruction Instruction Instruction data data data 17

Anatomy of a von Neumann Computer Internal storage Data Paths CPU control status Control Unit address data MEMORY address instructions dest registers asel operations fn ALU Cc s bsel More about this stuff later! +1 PC 1101000111011 R1 R2+R3 INSTRUCTIONS coded as binary data PROGRAM COUNTER or PC: Address of next instruction to execute logic to translate instructions into control signals for data path 18

Instruction Set Architecture (ISA) Encoding of instructions raises some interesting choices Tradeoffs: performance, compactness, programmability Uniformity. Should different instructions Be the same size (number of bits)? Take the same amount of time to execute? Trend: Uniformity. Affords simplicity, speed, pipelining. Complexity. How many different instructions? What level operations? Level of support for particular software operations: array indexing, procedure calls, polynomial evaluate, etc Reduced Instruction Set Computer (RISC) philosophy: simple instructions, optimized for speed Mix of Engineering & Art 19

ARM7 Programming Model A representative RISC machine Processor State (inside the CPU) R0 R1 R2 R3 R4 R5 R6 R7 R8 R9 R10 R11 R12 R13 (SP) R14 (LR) R15 (PC) CPSR Addresses 0 4 8 16 20 Main Memory 31 3 2 (4 bytes) 1 0 32 bit words next instruction 0 In Comp 411 we ll use a subset of the ARM7 core Instruction set as an example ISA. Fetch/Execute loop: fetch Mem[PC] PC = PC + 4 execute fetched instruction (may change PC!) repeat! ARM7 uses byte memory addresses. However, each instruction is 32-bits wide, and *must* be aligned on a multiple of 4 (word) address. Each word contains four 8-bit bytes. Addresses of consecutive instructions (words) differ by 4. 20

ARM Memory Nits Memory locations are addressable in different sized chunks 8-bit chunks (bytes) short2 short0 16-bit chunks (shorts) 32-bit chunks (words) byte3 byte2 byte1 byte0 64-bit chunks 2 1 0 (longs/doubles) 3 word Addr 0: 4: 8: 12: We also frequently need access to individual bits! (Instructions help with this) Every BYTE has a unique address (ARM is a byte-addressable machine) Most instructions are one word 31 30 29 4 3 2 1 0 7 11 15 6 10 14 5 9 13 4 8 12 long0 long8 21

ARM Register Nits There are 16 named registers [R0, R1,. R15] The operands of most instructions are registers This means to operate on a variables in memory you must: Load the value/values from memory into a register Perform the instruction Store the result back into memory Going to and from memory can be expensive (4x to 20x slower than operating on a register) Net effect: Keep variables in registers as much as possible! 3 registers are dedicated to specific tasks (SP, LR, PC) 13 are available for general use 22

Basic ARM InstructionS Instructions include various fields that encode combinations of OPCODES and arguments special fields enable extended functions several 4-bit OPERAND fields, for specifying the sources and destination of the operation, usually one of the 16 registers Embedded constants ( immediate values) of various sizes, The basic data-processing instruction formats: 4 3 4 1 4 4 8 4 R type: 1110 000 Opcode 0 Rn Rd 00000000 Rm 4 3 4 1 4 4 4 8 I type: 1110 001 Opcode 0 Rn Rd Shift Imm 23

R-type Data Processing Instructions that process three-register arguments: 4 3 4 1 4 4 8 4 R type: 1110 000 Opcode 0 Rn Rd 00000000 Rm Simple R-type instructions follow the following template: OP Rd, Rn, Rm Later on we ll introduce more complex variants of these simple R-type instructions. 0000 - AND 0001 - EOR 0010 - SUB 0011 - RSB 0100 - ADD 0101 - ADC 0110 - SBC 0111 - RSC 1000 - TST 1001 - TEQ 1010 - CMP 1011 - CMN 1100 - ORR 1101 - MOV 1110 - BIC 1111 - MVN ADD R0, R1, R3 Is encoded as: 1110 0000 1000 0001 0000 0000 0000 0011 0xE0810003 24

I-type Data Processing Instructions that process one register and a constant: 4 3 4 1 4 4 4 8 R type: 1110 001 Opcode 0 Rn Rd Rotate Imm8 Simple I-type instructions follow the following template: OP Rd, Rn, #constant In the I-type instructions the second register operand is replaced by a constant that is encoded in the instruction 0000 - AND 0001 - EOR 0010 - SUB 0011 - RSB 0100 - ADD 0101 - ADC 0110 - SBC 0111 - RSC 1000 - TST 1001 - TEQ 1010 - CMP 1011 - CMN 1100 - ORR 1101 - MOV 1110 - BIC 1111 - MVN RSB R7, R10, #49 Is encoded as: 1110 0010 0110 1010 0111 0000 0011 0001 0xE26A7031 25

I-type constants ARM7 provides only 8-bits for specifying an immediate constant value. Given that ARM7 is a 32-bit architecture, this may appear to be a severe limitation. However, by allowing for a rotating shift to be applied to the constant. imm32 = (imm8 >> (2 * rotate)) (imm8 << (32 - (2 * rotate))) Example: 1920 is encoded as: Rotate Imm8 1101 00011110 = (30 >> (2*13)) (30 << (32 - (2*23))) = 0 30 * 128 = 1920 26

Next Time We will examine more instruction types and capabilities Branching Loading from and storing to memory Special instructions Result flags Processor Status Registers 27