ARM Instructions ARM instructions are written as an operation code (opcode), followed by zero or more operands Operands may be constants (8-bit value),

Slides:



Advertisements
Similar presentations
ARM versions ARM architecture has been extended over several versions.
Advertisements

Goal: Write Programs in Assembly
Lecture 5: MIPS Instruction Set
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
LAB Flow Control Instructions
Lecture 5: Decision and Control CS 2011 Fall 2014, Dr. Rozier.
COMP3221 lec08-arith.1 Saeid Nooshabadi COMP 3221 Microprocessors and Embedded Systems Lecture 8: C/Assembler Data Processing
COMP3221 lec14-decision-II.1 Saeid Nooshabadi COMP 3221 Microprocessors and Embedded Systems Lectures 14: Making Decisions in C/Assembly Language – II.
Lecture 5 Sept 14 Goals: Chapter 2 continued MIPS assembly language instruction formats translating c into MIPS - examples.
Data Transfer & Decisions I (1) Fall 2005 Lecture 3: MIPS Assembly language Decisions I.
MIPS Instruction Set Advantages
ARM Instructions I Prof. Taeweon Suh Computer Science Education Korea University.
IT253: Computer Organization Lecture 4: Instruction Set Architecture Tonga Institute of Higher Education.
Making Decision – Microprocessor
11/02/2009CA&O Lecture 03 by Engr. Umbreen Sabir Computer Architecture & Organization Instructions: Language of Computer Engr. Umbreen Sabir Computer Engineering.
Topic 7: Control Flow Instructions CSE 30: Computer Organization and Systems Programming Winter 2011 Prof. Ryan Kastner Dept. of Computer Science and Engineering.
Natawut NupairojAssembly Language1 Control Structure.
Accumulator machine We will use the accumulator machine architecture to demonstate pass1 and pass2. The accumulator machine has one processor register:
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.
Chapter 2 Decision-Making Instructions (Instructions: Language of the Computer Part V)
Computer Organization Instructions Language of The Computer (MIPS) 2.
Lecture 2: Advanced Instructions, Control, and Branching EEN 312: Processors: Hardware, Software, and Interfacing Department of Electrical and Computer.
Computer Organization CS224 Fall 2012 Lessons 7 and 8.
Lecture 6: Branching CS 2011 Fall 2014, Dr. Rozier.
DR. SIMING LIU SPRING 2016 COMPUTER SCIENCE AND ENGINEERING UNIVERSITY OF NEVADA, RENO Session 11 Conditional Operations.
Digital Computer Concept and Practice Copyright ©2012 by Jaejin Lee Control Unit.
Instruction Set Architectures Early trend was to add more and more instructions to new CPUs to do elaborate operations –VAX architecture had an instruction.
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.
Deeper Assembly: Addressing, Conditions, Branching, and Loops
MIPS Instruction Set Advantages
Chapter 15: Higher Level Constructs
CS2100 Computer Organisation
Control Unit Lecture 6.
Assembly Language Programming of 8085
Microprocessor T. Y. B. Sc..
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.
Assembly Language Assembly Language
3.Instruction Set of 8085 Consists of 74 operation codes, e.g. MOV
The Cortex-M3/m4 Embedded Systems: Cortex-M3/M4 Instruction Sets
Lecture 4: MIPS Instruction Set
Making Decisions and Writing Loops
ECE 3430 – Intro to Microcomputer Systems
Decision Making.
Processor Instructions set. Learning Objectives
Microprocessor and Assembly Language
Morgan Kaufmann Publishers Computer Organization and Assembly Language
More on logical instruction and
Microprocessor and Assembly Language
Instructions for Making Decisions
The University of Adelaide, School of Computer Science
ARM Control Structures
How to represent signed integers
CSC 3210 Computer Organization and Programming
Write a program to calculate x**y, given x and y.
Flow Control Instructions
COMS 361 Computer Organization
ARM Control Structures
March 2006 Saeid Nooshabadi
Branching instructions
EECE.3170 Microprocessor Systems Design I
Overheads for Computers as Components 2nd ed.
MIPS Assembly.
MIPS assembly.
Multiply Instructions
Branch & Call Chapter 4 Sepehr Naimi
An Introduction to the ARM CORTEX M0+ Instructions
MIPS instructions.
Presentation transcript:

ARM Instructions ARM instructions are written as an operation code (opcode), followed by zero or more operands Operands may be constants (8-bit value), registers (r0 - r12), or memory references ([r0])

Immediates Immediates are numerical constants. They appear often in code, so there are ways to indicate their existence (designated by # in ARM) Add Immediate: /* f = g + 10 (in C) */ ADD r0, r1, #10 // (in ARM) where ARM registers r0, r1 are associated with C variables f, g The second operand is a #number instead of a register.

ARM Instructions Instruction syntax: opcode{cond}{flags} Rd, Rn, operand2 where: {cond} is an optional two-letter condition, e.g. EQ {flags} is an optional additional flag, e.g. S Rd is the destination register Rn is the first source register Operand2 is a flexible second operand

ARM Instructions Examples add r0, r1, #3 mov r0, #15 mov r1, #0x12 cmp r0, r1

ARM Comments One way to make your code more readable is to use comments! // is used for ARM comments in QEMU anything from // to end of line is a comment and will be ignored The block comment, /* comment */, is also available

Labels in ARM For our emulator, a label in ARM is designated as follows: label_name: e.g. start: … loop: done:

Processor Status Register(PSR) The N, Z, C, and V bits are the condition code flags. Flags are set  by arithmetic and logical CPU instructions and used for conditional execution The processor tests these flags to determine whether to execute a conditional instruction. N – Negative / less than Z – Zero C – Carry out V – oVerflow

Control Structures in ARM Implementation of Decisions Similar to accumulator instructions One instruction sets the flags, followed by another instruction that uses the flags to make the actual branch decision ARM compare and test instructions Instruction Operation Notes cmp rn, <op2> cmn rn, <op2> rn - <op2> rn += <op2> Always updates NZCV tst rn, <op2> teq rn, <op2> rn & <op2> rn ^ <op2> Always updates NZ, if shifted. <op2> may affect C flag

Condition Codes Suffix Description Flags tested Conditional branch instructions make a decision to branch based on the state of the appropriate flag. Suffix Description Flags tested eq Equal Z = 1 ne Not equal Z = 0 cs / hs Unsigned higher or same C = 1 cc / lo Unsigned lower C = 0 mi Minus N = 1 pl Positive or Zero N = 0 vs Overflow V = 1 vc No overflow V = 0 hi Unsigned higher C = 1 & Z = 0 ls Unsigned lower or same C = 0 or Z = 1 ge Greater than or equal N = V lt Less than N != V gt Greater than Z = 0 & N = V le Less than or equal Z = 1 or N = !V al Always   Condition codes are simply a way of testing the ALU status flags. This slide is for reference only.

ARM Branch Instructions Unconditional branch B (or BAL) branch always Conditional branches testing result of compare or other operation (signed arithmetic): beq – branch on equal (Z==1) bne – branch on not equal (Z==0) bls – branch on less than ((N xor V)==1) ble – branch on less than or equal ((Z or (N xor V))==1) bge – branch on greater than or equal ((N xor V)==0) bgt – branch on greater than ((Z or (N xor V))==0)

C if statement in ARM int x; int y; if(x == 0) y = 1; /* assume x is in r0, y is in r1 */ exit x == 0? y = 1 (false) (true) x == 0 C Source Code Ineffficient Assembly Efficient Assembly int x; int y; if(x == 0) y = 1; cmp r0, #0 beq then b endif then: mov r1, #1 // now store r1 in [y] endif: . . . cmp r0, #0 bne endif then: mov r1, #1

C if statement in ARM (true) (x+y)>z (false) x += y exit if((x+b)>z) x+=y; ARM code: /* assume x is in r0 y is in r1, and z is in r2 */ add r3, r0, r1 cmp r3, r2 ble false // branch to false when((x+y)>z) // is false add r0, r0, r1 // x = x+y /* now store content of r0 to [x] */ false: exit x+y > z? x += y (false) (true) (x+y)>z

C if-else statement in ARM if(i == j) f=g+h; else f=g-h; ARM code: /* assume f is in r0, i is in r1, j is in r2, g is in r3, h is in r4, */ cmp r1, r2 // Z = 1 if i==j beq true // branch to true when i==j sub r0, r3, r4 // f = g-h (false) b done // branch to done true: add r0, r3,r4 // f = g+h (true) done: exit i == j? f=g+h f=g-h (false) i != j (true) i == j

Conditional execution in ARM An unusual ARM feature is that all instructions may be conditional: CMP r0, #5 // if (r0 != 5) { ADDNE r1, r1, r0 // r1 := r1 + r0 - r2 SUBNE r1, r1, r2 } this removes the need for some short branches, improving performance and code density

ARM Control Structures Implementing Loops All for loops, while loops, and do-while loops have an implicit branch from the bottom to the top of the loop. This branch instruction becomes explicit when translated into assembly. while loop /* assume x is in r0 while ( x <= 10 ) and y is in r1 */ { loop: x = x + y; cmp r0, #10 // test condition } bgt done add r0, r0, r1 b loop done:

Loops in C/Assembly for loop // x: r0, y: r1, z: r2 for ( x = 1; x <= y; x++ ) mov r0, #1 { loop: z *= x; cmp r0, r1 // test condition } bgt done mul r2, r2, r0 rewritten as while loop add r0, r0, #1 x = 1; b loop while ( x <= y ) done: { z *= x; x++; }

Control Structures in ARM for loop, counted up from 0 to n-1 /* i : r0, n: r1 */ for ( i = 0; i < n; i++ ) { <body> mov i, #0 //clear itest: } loop: cmp r0, r1 rewritten as while loop bge done i = 0; <body> while ( i < n ) add r0, r0, #1 { b loop <body> done: i++; }

Control Structures in ARM for loop, counted up from 1 to n i .req r0 for ( i = 1; i <= n; i++ ) { n .req r1 <body> mov r1, #1 } loop: cmp i, n bgt done rewritten as while loop <body> i = 1; add i, i, #1 while(i <= n) b loop { done: <body> i++; }

Control Structures in ARM for loop, counted down from to n to 1 for ( i = n; i > 0; i-- ) i .req r0 { n .req r1 <body> mov n, i } loop: cmp i, #0 ble done rewritten as while loop <body> i = n; sub i, i, #1 while ( i > 0 ) b loop { done: <body> i--; }