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

Similar documents
Chapter 15. ARM Architecture, Programming and Development Tools

VE7104/INTRODUCTION TO EMBEDDED CONTROLLERS UNIT III ARM BASED MICROCONTROLLERS

Systems Architecture The ARM Processor

Chapter 15. ARM Architecture, Programming and Development Tools

Processor Status Register(PSR)

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

Cortex M3 Programming

The ARM Instruction Set

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

ARM-7 ADDRESSING MODES INSTRUCTION SET

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

Comparison InstruCtions

CS 310 Embedded Computer Systems CPUS. Seungryoul Maeng

ARM Assembly Language

ARM Assembly Language. Programming

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

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

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

STEVEN R. BAGLEY ARM: PROCESSING DATA

Introduction to the ARM Processor Using Altera Toolchain. 1 Introduction. For Quartus II 14.0

Instruction Set Architecture (ISA)

The ARM instruction set

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

ARM Assembly Programming

Topic 10: Instruction Representation

ECE 471 Embedded Systems Lecture 5

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

EE4144: ARM Cortex-M Processor

Compilation Tools. RealView. Assembler Guide. Version 4.0. Copyright ARM. All rights reserved. ARM DUI 0204J (ID101213)

ECE 498 Linux Assembly Language Lecture 5

ECE 571 Advanced Microprocessor-Based Design Lecture 3

3 Assembly Programming (Part 2) Date: 07/09/2016 Name: ID:

Introduction to the ARM Processor Using Intel FPGA Toolchain. 1 Introduction. For Quartus Prime 16.1

Embedded Systems Ch 12B ARM Assembly Language

ARM Architecture and Instruction Set

Sneha Rajguru & Prajwal Panchmahalkar

Problem Sheet 1: ANSWERS (NOT ) (NOT ) 3. 37, ,

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

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

Assembler: Basics. Alberto Bosio October 20, Univeristé de Montpellier

The Original Instruction Pipeline

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

Writing ARM Assembly. Steven R. Bagley

Branch Instructions. R type: Cond

Outline. ARM Introduction & Instruction Set Architecture. ARM History. ARM s visible registers

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

Basic ARM InstructionS

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

Lecture 10 Exceptions and Interrupts. How are exceptions generated?

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

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

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

ARM Processor. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

Instruction Set. ARM810 Data Sheet. Open Access - Preliminary

ECE 471 Embedded Systems Lecture 6

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

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

Chapter 2. Instructions: Language of the Computer

ARM ARCHITECTURE. Contents at a glance:

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

Computer Organization MIPS ISA

EEM870 Embedded System and Experiment Lecture 4: ARM Instruction Sets

The ARM Cortex-M0 Processor Architecture Part-2

EE319K Spring 2015 Exam 1 Page 1. Exam 1. Date: Feb 26, 2015

ARM Instruction Set 1

The Assembly Language of the Boz 5

Processor Structure and Function

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

Interrupt-Driven Input/Output

William Stallings Computer Organization and Architecture 8 th Edition. Chapter 12 Processor Structure and Function

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

DHANALAKSHMI COLLEGE OF ENGINEERING, CHENNAI DEPARTMENT OF ELECTRICAL AND ELECTRONICS ENGINEERING. EE6008 Microcontroller based system design

ARM Cortex-M4 Architecture and Instruction Set 3: Branching; Data definition and memory access instructions

Lecture 15 ARM Processor A RISC Architecture

Job Posting (Aug. 19) ECE 425. ARM7 Block Diagram. ARM Programming. Assembly Language Programming. ARM Architecture 9/7/2017. Microprocessor Systems

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

Embedded Processor Cores. National Chiao Tung University Chun-Jen Tsai 5/30/2011

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

ARM Instruction Set Dr. N. Mathivanan,

Assembly Language. CS2253 Owen Kaser, UNBSJ

Worksheet #4 Condition Code Flag and Arithmetic Operations

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

A block of memory (FlashROM) starts at address 0x and it is 256 KB long. What is the last address in the block?

ARM7TDMI Instruction Set Reference

Introduction to C. Write a main() function that swaps the contents of two integer variables x and y.

ECE 3210 Lab 4: Calculator

Hercules ARM Cortex -R4 System Architecture. Processor Overview

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

The ARM Instruction Set Architecture

William Stallings Computer Organization and Architecture 10 th Edition Pearson Education, Inc., Hoboken, NJ. All rights reserved.

Introduction to Embedded Systems EE319K (Gerstlauer), Spring 2013

Exam 1. Date: Oct 4, 2018

ARM Assembly Programming

Instructions: Language of the Computer

Architecture. Digital Computer Design

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

AND SOLUTION FIRST INTERNAL TEST

Camellia Getting Started with ARM922T

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

ECE 471 Embedded Systems Lecture 9

Transcription:

ARM Programmers Model Hi Hsiao-Lung Chan, Ph.D. Dept Electrical Engineering Chang Gung University, Taiwan chanhl@maili.cgu.edu.twcgu

Current program status register (CPSR) Prog Model 2

Data processing instruction format 31 28 27 26 25 24 21 20 19 16 15 12 11 0 Cond 00 L OpCode S Rn Rd Shifter_operand <OpCode>{<Cond>}{S} Rd, Rn, <Shifter_Operand> Cond: If the condition does not satisfied (N,C,Z,C), C) the instruction acts as a NOP. Always condition is specified if it is omitted. S: Specify CPSR is updated after the execution of instruction. CPSR is unchanged if S is omitted Rd, Rn: Destination register, and 1 st operand register Shifter_operand: Immediate value (L=1), or register (L=0) Prog Model 3

Move instructions MOV{<Cond>} Rd, <Shifter operand> MOV : move 32-bit value into a register MVN : move the NOT of the 32-bit register value (1 s complement) into a register <Pre-condition> r5 = 8 MOV r6, r5 MVN r7, r5 <Post-condition> r6 = r5 = 0x00000008 r7 = 0xffffffff r5 = 0xfffffff7 Prog Model 4

ADD instructions ADDS r4, r0, r2 ;r4= r0 + r2 ADC r5, r1, r3 ; r5 = r1 + r3 + carry R1 C R0 R3 R2 (+ R5 R4 64-bit Addition Prog Model 5

SUB instructions <Pre-condition> o CPSR = nzcvqift_user r1 = 0x00000001 SUBS r1, r1, #1 <Post-condition> CPSR = nzcvqift_user r1 = 0x00000000 #1 0x00000001 0xfffffffe +1 0xffffffff 1 s complement 2 s complement 64-bit subtraction SUBS r4, r0, r2 SBC r5, r1, r3 ; R5:R4 = R1:R0 R3:R2 Prog Model 6

RSB instruction <Pre-condition> r0 = 0x00000000 r1 = 0x00000077 RSB r0, r1, #0 <Post-condition> r0 = 0 - r1 = 0xffffff89 Prog Model 7

Thumb instruction Solutions to code-size problem Hand code in assembler Improve the compiler Use compressed code (require additional system sources) ARM Thumb is a recoded subset of ARM instruction Implements 16-bit instruction on 32-bit architecture Keep 32-bit performance and address space A 30% code density improvement Prog Model 8

ARM-Thumb interworking Fetch Decode stage Execute stage 32-bit data 16 16 A[1] 16 Thumb instruction decomposition ARM instruction decode Thumb state Decompress Thumb instruction during the used phase of the clock in decode stage Prog Model 9

Registers in ARM and Thumb states Thumb state R0-R7 ARM state R0-R7 R8-R12 Low register High register Stack pointer (SP) Stack pointer (R13) Link register (LR) Link register (R14) Program counter (PC) Program counter (R15) Current program Current program status register (CPSR) status register (CPSR) Saved PSR (SPSR) Saved PSR (SPSR) Prog Model 10

Thumb instruction decoding Thumb 16-bit instruction ARM 32-bit instruction ADD rd, #Constant Decoder ADDS rd, rd, #Constant CPSR = nzcvqift_svc Prog Model 11

Thumb instruction format Example: ADD Rd, #Constant 15 3 bits 0 Thumb Code 0 0 1 1 0 Rd 8-bit immediate Major op-code Minor op-code Destination & Source register Immediate value ARM Code 31 0 1110 00 1 0100 1 0 Rd 0 Rd 0000 8-bit immediate Always condition code S Prog Model 12

Branch instructions Prog Model 13

Condition code Prog Model 14

Pipeline stall due to branch instruction (control stall) BNE foo fetch decode ex bne SUB r2, r3, r6 fetch decode foo ADD r0, r1, r2 fetch decode ex add time Prog Model 15

Conditional execution Greatest common divisor while (a!=b) if (a>b) a -=b; else b -=a; Using branch gcd CMP r1, r2 BEQ complete BLT lessthan SUB r1, r1, r2 B gcd lessthan SUB r2, r2, r1 B gcd complete Using conditional execution gcd CMP r1, r2 SUBGT r1, r1, r2 SUBLT r2, r2, r1 BNE gcd Prog Model 16

Branch with link (subroutine call) BL fn1 ; branch to subroutine fn1, and next instruction ; address is copied to lr CMP r1, #8 ; compare with 8 MOVEQ r1, #2 ; if r1==8 then r1=2 fn1 <subroutine code> MOV pc, lr ; at the end of subroutine, return by moving pc = lr Prog Model 17

ARM vs. Thumb codes Prog Model 18

ARM code of binary to hexadecimal converter MOV r1,r0 ; r0 holds value to convert, r1=r0 MOV r2,#8 ; Load r2 with decimal 8 Loop: MOV r1,r1,ror #28 ; Rotate r1 right by 28 and put result in r1 AND r0,r1,#15 ; AND r1 with decimal 15 CMP r0,#10 ;Compare r0 with decimal 10 and ADDLTr0r0#'0' r0,r0,#0 ;ifit s it less than 10 then ADD ASCII 0 to r0 ADDGE r0,r0,#'a' ; otherwise ADD ASCII A to r0 SWI 0 ; routine to write char to screen SUBS r2,r2,#1 ; Subtract 1 from r2 BGT Loop ;and loop back to 1 if r2 is still greater than zero MOV pc,lr ;Load PC with Link reg (Return) Prog Model 19

Thumb code of binary to hexadecimal converter MOV r1,r0 ;Value to convert in r0, r1=r0 MOV r2,#8 ;Put 8 in r2 Loop1 LSR r0,r1,#28 ;Do logical shift right on r1 by 28 places and ; place in r0 LSL r1,r1,#4 ;Do logical shift left on r1 by 4 places CMP r0,#10 ;Compare r0 with 10 and BLT Loop2 ;if less than 10, branch to Loop2 ADD r0,# A - 0-10 ;ADD ASCII A-0-10 (7) to r0 Loop2 ADD r0,#'0' ;ADD ASCII 0 (48) to r0 SWI 0 ;routine to write char to screen SUBr2#1 r2,#1 ;subtract1fromr2 r2 BNE Loop1 ;if unfinished loop1 MOV pc,lr ;else,load PC with Link register Prog Model 20

Code size comparison ARM code 11 instructions 44 bytes Thumb code 12 instructions 24 bytes Prog Model 21

ARM-Thumb interworking instructions BX Rm Thumb version branch exchange pc = Rm & 0xfffffffe, T = Rm[0] BLX Rm Thumb version branch exchange with link pc = Rm & 0xfffffffe, T = Rm[0] lr = address of next instruction after BLX+1 Prog Model 22

ARM-Thumb interworking example ; ARM code CODE32 ; word aligned address(thumbcode)= 0x00009000 LDR r0, =thumbcode+1 r0 = 0x00009001 BLX r0 ; branch to Thumb code & mode... ; Thumb code CODE16 ; halfword aligned thumbcode ADD r1, #1 BX lr ; branch to ARM code & mode Prog Model 23

Thumb-2 instruction set Add 32-bit instructions (cover the functionality of the ARM instruction set) that can be freely intermixed with 16-bit instructions in a program. DSP algorithms using the 32-bit media instructions in Thumb-2 and use the smaller 16-bit Thumb instructions for the rest of the application. Does not require any mode change. The first halfword (hw1) determines the instruction length and functionality Prog Model 24

Thumb-2 instruction set (cont.) Most 32-bit Thumb instructions are unconditional, whereas most ARM instructions can be conditional. Thumb-2 introduces a conditional execution instruction, IT (if-then-else) that can make following instructions conditional. Prog Model 25

Load-store instructions Prog Model 26

Indexing methods Prog Model 27

Checksum example Programming 28

Argument passing in function call Prog Model 29

Thumb Execution Environment (Thumb-EE) instruction set Executed in the ThumbEE state (J=1 &T=1) In ThumbEE state, the processor executes almost the same instruction set as in Thumb state. However some are different, some are removed, and some ThumbEE instructions are added, such as New ThumbEE instructions to branch to handlers Null pointer checking on load/store instructions Additional instruction ti to check array bounds Some other modifications to load, store, and control flow instructions. Prog Model 30

Registers and operation modes Prog Model 31

Operation modes of ARM User mode ARM program execution state t System mode Privileged user mode for the OS Supervised (svc) mode Executing a SVC (supervisor call) instruction A processor enters supervisor mode on reset Fast interrupt mode handling fast interrupts Interrupt mode General-purpose interrupt handling Abort mode Data abort exception or instruction prefetch abort Undefined mode Attempt to execute an UNDEFINED instruction Secure monitor mode Executing a SMC (secure monitor call) instruction Prog Model 32

Reference A.N. Sloss, D. Symes, C. Wright, ARM System Developer s Guide, Elsevier Inc., 2004. Cortex -A8 Technical Reference Manual, ARM Limited. ARM Architecture Reference Manual, ARMv7-A and ARMv7-R edition, ARM Limited. Prog Model 33