ARM Control Structures

Slides:



Advertisements
Similar presentations
Slides created by: Professor Ian G. Harris Efficient C Code  Your C program is not exactly what is executed  Machine code is specific to each ucontroller.
Advertisements

1 Lecture 3: MIPS Instruction Set Today’s topic:  More MIPS instructions  Procedure call/return Reminder: Assignment 1 is on the class web-page (due.
Goal: Write Programs in Assembly
Review of the MIPS Instruction Set Architecture. RISC Instruction Set Basics All operations on data apply to data in registers and typically change the.
Lecture 5: MIPS Instruction Set
CS/COE0447 Computer Organization & Assembly Language
Branches Two branch instructions:
Control Structures in ARM Implementation of Decisions Similar to accumulator instructions One instruction sets the flags, followed by another instruction.
Deeper Assembly: Addressing, Conditions, Branching, and Loops
The University of Adelaide, School of Computer Science
Lecture 5: Decision and Control CS 2011 Fall 2014, Dr. Rozier.
Lecture 4: Loads, Logic, Loops. Review Memory is byte-addressable, but lw and sw access one word at a time. These instructions transfer the contents of.
1 Lecture 2: MIPS Instruction Set Today’s topic:  MIPS instructions Reminder: sign up for the mailing list cs3810 Reminder: set up your CADE accounts.
Lecture 5 Sept 14 Goals: Chapter 2 continued MIPS assembly language instruction formats translating c into MIPS - examples.
More decisions and logic (1) Fall 2010 Lecture 4: Loads, Logic, Loops.
MIPS Instruction Set Advantages
IT253: Computer Organization Lecture 5: Assembly Language and an Introduction to MIPS Tonga Institute of Higher Education.
Making Decision – Microprocessor
1 Branches and Procedure Calls Lecture 14 Digital Design and Computer Architecture Harris & Harris Morgan Kaufmann / Elsevier, 2007.
IT 251 Computer Organization and Architecture More MIPS Control Instructions Chia-Chi Teng.
Lecture 4: MIPS Instruction Set
17 - Jumps & Branches. The PC PC marks next location in Fetch, Decode, Execute cycle.
MIPS coding. Review Shifting – Shift Left Logical (sll) – Shift Right Logical (srl) – Moves all of the bits to the left/right and fills in gap with 0’s.
Computer Architecture CSE 3322 Lecture 3 Assignment: 2.4.1, 2.4.4, 2.6.1, , Due 2/3/09 Read 2.8.
Computer Organization Instructions Language of The Computer (MIPS) 2.
Chapter 2 — Instructions: Language of the Computer — 1 Conditional Operations Branch to a labeled instruction if a condition is true – Otherwise, continue.
COM181 Computer Hardware Lecture 6: The MIPs CPU.
Digital Computer Concept and Practice Copyright ©2012 by Jaejin Lee Control Unit.
CSCI-365 Computer Organization Lecture Note: Some slides and/or pictures in the following are adapted from: Computer Organization and Design, Patterson.
Lecture 6: Decision and Control CS 2011 Spring 2016, Dr. Rozier.
ARM Instructions ARM instructions are written as an operation code (opcode), followed by zero or more operands Operands may be constants (8-bit value),
MIPS Programming.
Deeper Assembly: Addressing, Conditions, Branching, and Loops
MIPS Instruction Set Advantages
Chapter 15: Higher Level Constructs
ECE 3430 – Intro to Microcomputer Systems
ARM Registers Register – internal CPU hardware device that stores binary data; can be accessed much more rapidly than a location in RAM ARM has.
Computer Organization and Design Instruction Sets - 2
MIPS Coding Continued.
Lecture 4: MIPS Instruction Set
Making Decisions and Writing Loops
Computer Organization and Design Instruction Sets - 2
More Branch Instructions and Set Instructions
RISC Concepts, MIPS ISA Logic Design Tutorial 8.
Conditional Branches What distinguishes a computer from a simple calculator is its ability to make decisions Decisions are made using the if statement,
Instructions for Making Decisions
Single-Cycle CPU DataPath.
Lecture 4: MIPS Instruction Set
CSCI206 - Computer Organization & Programming
How to represent signed integers
MIPS Instruction Encoding
ECE232: Hardware Organization and Design
MIPS Instruction Encoding
The University of Adelaide, School of Computer Science
COMS 361 Computer Organization
COMS 361 Computer Organization
ARM Control Structures
ECE 352 Digital System Fundamentals
Branching instructions
MIPS Assembly.
MIPS Coding Continued.
MIPS assembly.
CS501 Advanced Computer Architecture
Branch & Call Chapter 4 Sepehr Naimi
The Processor: Datapath & Control.
COMS 361 Computer Organization
Processor: Datapath and Control
An Introduction to the ARM CORTEX M0+ Instructions
MIPS instructions.
Conditional Branching (beq)
Presentation transcript:

ARM Control Structures

Branch B identifier Branch (jump) to given identifier

Branch Instruction Format 24 bit immediate 110101110010001001101001 Shifted left 2 bits to make 26 bit value 11010111001000100110100100 Sign extended to 32 bits 11111111010111001000100110100100

Branch Instruction Format 24 bit immediate 110101110010001001101001 Shifted left 2 bits to make 26 bit value 11010111001000100110100100 Sign extended to 32 bits 11111111010111001000100110100100 Signed 26 bit value to be added to PC +/- 32Mbytes

Status Register CPSR register Tracks state of processor, recent instructions

Setting Status CMP : Compare CMP rn, #___ CMP rn, rm Set status register based on op1 – op2

Other Comparisons CMN : Compare Negative CMN op1, op2 Set status register based on op1 + op2 TST : Test bits TST op1, op2 Set status register based on op1 AND op2 Does not set Carry or oVerflow bits TEQ : Test equal TEQ op1, op2 Set status register based on op1 XOR op2 Does not set Carry or oVerflow bits

Conditional Branches BEQ identifier : Branch on equal Status register determines if branch taken

Conditional Branches Branch options Most Common

If Assembly if’s are “backwards” if(i == j) { k = 1; } … High Level Assembly if(i == j) { k = 1; } … Branch to cont if r1 != r2 r3 = 1 cont: …. .data i: .word 0x2 j: .word 0x2 k: .word 0x0 .text main: lw $8, i #load value at i in memory into $8 lw $9, j #load value at i in memory into $8 bne $8, $9 endif #if NOT same, skip ahead nop #branch delay!! ori $10, $0, 1 #store 1 into $10 sw $10, k #store the 1 into k endif: ori $30, $0, 0 #random instruction = rest of program...

If If implemented with branch: Skip ahead if NOT doing if body .data i: .word 0x2 j: .word 0x2 k: .word 0x0 .text main: lw $8, i #load value at i in memory into $8 lw $9, j #load value at i in memory into $8 bne $8, $9 endif #if NOT same, skip ahead nop #branch delay!! ori $10, $0, 1 #store 1 into $10 sw $10, k #store the 1 into k endif: ori $30, $0, 0 #random instruction = rest of program...

If / Else If/Else implemented with branch: Branch to skip if body for else case If body ends with jump to skip else body High Level Assembly if(i == j) { k = 1; } else { k = 2; } … Branch to else if r1 != r2 r3 = 1 jump to endif else: r3 = 2 endif: .data i: .word 0x2 j: .word 0x2 k: .word 0x999 .text main: lw $8, i #load value at i in memory into $8 lw $9, j #load value at i in memory into $8 bne $8, $9 else #if NOT same, skip ahead to else nop #branch delay!! ori $10, $0, 1 #store 1 into $10 sw $10, k #store the 1 into k j endif #skip else part else: endif: ori $30, $0, 0 #random instruction = rest of program...

If / Else If/Else implemented with branch: Branch to skip if body for else case If body ends with jump to skip else body .data i: .word 0x2 j: .word 0x2 k: .word 0x999 .text main: lw $8, i #load value at i in memory into $8 lw $9, j #load value at i in memory into $8 bne $8, $9 else #if NOT same, skip ahead to else nop #branch delay!! ori $10, $0, 1 #store 1 into $10 sw $10, k #store the 1 into k j endif #skip else part else: endif: ori $30, $0, 0 #random instruction = rest of program...

Loop = jump backwards # # $8 is loop control variable (i) init: ori $8, $0, 0 # count = 0 test: sltiu $9, $8, 10 # count < 10 beq $9, $0, endLp # end loop if count >= 10 sll $0, $0, 0 # delay # do stuff addiu $8, $8, 1 # count++ j test nop # delay endLp: sll $0,$0,0 # end loop target

Loop = jump backwards int i = 0; while(i < 10) { //do stuff i++; } # # $8 is loop control variable (i) init: ori $8, $0, 0 # count = 0 test: sltiu $9, $8, 10 # count < 10 beq $9, $0, endLp # end loop if count >= 10 sll $0, $0, 0 # delay # do stuff addiu $8, $8, 1 # count++ j test nop # delay endLp: sll $0,$0,0 # end loop target

Counting Loop Test jumps to end when done End branches back to test # # $8 is loop control variable (i) init: ori $8, $0, 0 # count = 0 test: sltiu $9, $8, 10 # count < 10 beq $9, $0, endLp # end loop if count >= 10 sll $0, $0, 0 # delay # do stuff addiu $8, $8, 1 # count++ j test nop # delay endLp: sll $0,$0,0 # end loop target

Real Code Counting Loop Naïve loop implementation : 4 instructions / iteration

Real Code Counting Loop Compilers usually move test to end of loop Start by jumping to test 3 instructions / iteration

Sum Sum 0…10

ARM Specific Tricks: Set Bits & Conditional Execution

Condition Bits ARM instructions feature 4 condition bits:

Condition Bits Lots of instructions start with E

Condition Bits Specify condition to execute instruction under

Condition Bits E = 1110 Always execute

Conditional Execution Apply conditions to most instructions

Condtional Without Branch Can implement if/else as conditional instructions

Fun Fact Setting Flags CMP, CMN, TST, TEQ set status register

Setting Flags Fun Fact CMP, CMN, TST, TEQ set status register Data instructions can do so optionally instructionS = Set status

Fun Fact Status Flag If If with CMP & conditional execution:

Fun Fact Status Flag If Setting status with subtraction instead:

Fun Fact Status Flag If Loop using set flags: