March 2006 Saeid Nooshabadi

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

ARM versions ARM architecture has been extended over several versions.
COMP3221 lec16-function-II.1 Saeid Nooshabadi COMP 3221 Microprocessors and Embedded Systems Lectures 16 : Functions in C/ Assembly - II
Embedded System Design Center ARM7TDMI Microprocessor Data Processing Instructions Sai Kumar Devulapalli.
Control Structures in ARM Implementation of Decisions Similar to accumulator instructions One instruction sets the flags, followed by another instruction.
COMP3221 lec9-logical-I.1 Saeid Nooshabadi COMP 3221 Microprocessors and Embedded Systems Lecture 9: C/Assembler Logical and Shift - I
COMP3221 lec-12-mem-II.1 Saeid Nooshabadi COMP 3221 Microprocessors and Embedded Systems Lecture 12: Memory Access - II
ARM Microprocessor “MIPS for the Masses”.
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 lec13-decision-I.1 Saeid Nooshabadi COMP 3221 Microprocessors and Embedded Systems Lectures 13: Making Decisions in C/Assembly Language - I
COMP3221 lec13-decision-I.1 Saeid Nooshabadi COMP 3221 Microprocessors and Embedded Systems Lectures 4/5: Making Decisions in C/Assembly Language - I
COMP3221 lec14-decision-II.1 Saeid Nooshabadi COMP 3221 Microprocessors and Embedded Systems Lectures 14: Making Decisions in C/Assembly Language – II.
COMP3221 lec06-numbers-II.1 Saeid Nooshabadi COMP 3221 Microprocessors and Embedded Systems Lecture 6: Number Systems - II
Elec2041 lec-11-mem-I.1 Saeid Nooshabadi COMP 3221 Microprocessors and Embedded Systems Lecture 11: Memory Access - I
ARM Instructions I Prof. Taeweon Suh Computer Science Education Korea University.
Embedded System Design Center Sai Kumar Devulapalli ARM7TDMI Microprocessor Thumb Instruction Set.
Topic 10: Instruction Representation CSE 30: Computer Organization and Systems Programming Winter 2011 Prof. Ryan Kastner Dept. of Computer Science and.
Lecture 2: Basic Instructions CS 2011 Fall 2014, Dr. Rozier.
Lecture 4. ARM Instructions #1 Prof. Taeweon Suh Computer Science Education Korea University ECM586 Special Topics in Embedded Systems.
Making Decision – Microprocessor
Lecture 2: Basic Instructions EEN 312: Processors: Hardware, Software, and Interfacing Department of Electrical and Computer Engineering Spring 2014, Dr.
Chapter 10 The Assembly Process. What Assemblers Do Translates assembly language into machine code. Assigns addresses to all symbolic labels (variables.
Topic 7: Control Flow Instructions CSE 30: Computer Organization and Systems Programming Winter 2011 Prof. Ryan Kastner Dept. of Computer Science and Engineering.
1 Chapter 4 ARM Assembly Language Smruti Ranjan Sarangi Computer Organisation and Architecture PowerPoint Slides PROPRIETARY MATERIAL. © 2014 The McGraw-Hill.
Lecture 2: Advanced Instructions, Control, and Branching EEN 312: Processors: Hardware, Software, and Interfacing Department of Electrical and Computer.
EECS 370 Discussion 1 xkcd.com. EECS 370 Discussion Topics Today: – ARM Addressing Endianness, Loading, and Storing Data – Data Layout Struct Packing.
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.
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),
Smruti Ranjan Sarangi, IIT Delhi Chapter 4 ARM Assembly Language
Architecture Revisions
Chapter 4: Introduction to Assembly Language Programming
Status Register Status = system byte (supervisor only) + user byte = system status + condition code register usually, it is not important to know.
Chapter 15: Higher Level Constructs
Microprocessor T. Y. B. Sc..
Introduction to the ARM Instruction Set
ECE 3430 – Intro to Microcomputer Systems
The University of Adelaide, School of Computer Science
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
Making Decisions and Writing Loops
ECE 3430 – Intro to Microcomputer Systems
Processor Instructions set. Learning Objectives
March 2006 Saeid Nooshabadi
April 2006 Saeid Nooshabadi
March 2006 Saeid Nooshabadi
Chapter 5 The LC-3.
ARM Control Structures
CSC 3210 Computer Organization and Programming
Instruction encoding We’ve already seen some important aspects of processor design. A datapath contains an ALU, registers and memory. Programmers and compilers.
ARM Control Structures
March 2006 Saeid Nooshabadi
Branching instructions
March 2006 Saeid Nooshabadi
ARM Introduction.
Overheads for Computers as Components 2nd ed.
MIPS Assembly.
March, 2006 Saeid Nooshabadi
March 2006 Saeid Nooshabadi
Computer Architecture
Multiply Instructions
Branch & Call Chapter 4 Sepehr Naimi
Introduction to Assembly Chapter 2
ECE511: Digital System & Microprocessor
An Introduction to the ARM CORTEX M0+ Instructions
Presentation transcript:

March 2006 Saeid Nooshabadi saeid@unsw.edu.au ELEC2041 Microprocessors and Interfacing Lectures 14: Making Decisions in C/Assembly Language - II http://webct.edtec.unsw.edu.au/ March 2006 Saeid Nooshabadi saeid@unsw.edu.au

Overview Compare instruction mechanism Flag setting Instructions Conditional Instructions Conclusion

Review (#1/2) HLL decisions (if, case) and loops (while, for) use same assembly instructions Compare instruction: cmp in ARM Conditional branches: beq, bne, bgt, blt, etc in ARM Unconditional branches: b, and mov pc, rn in ARM Switch/Case: chained if-else or jump table + ldr pc, [ ] ldr pc, [ ] is VERY POWERFUL!

Review (#2/2) Some Branch Conditions after cmp instruction: b Unconditional bal Branch Always beq Branch Equal bne Branch Not Equal blt Branch Less Than ble Branch Less Than or Equal bgt Branch Greater Than bge Branch Greater Than or Equal Full Table Page 64 Steve Furber: ARM System On-Chip; 2nd Ed, Addison-Wesley, 2000, ISBN: 0-201-67519-6.

Review: Branches: PC-relative addressing Recall register r15 in the machine also called PC; points to the currently executing instruction Most instruction add 4 to it. (pc increments by 4 after execution of most instructions) Branch changes it to a specific value Branch adds to it 24-bit signed value (contained in the instruction) Shifted left by 2 bits Labels => addresses memory 0: b address –32MB 24 bits beq address registers r15 = pc +32MB r14 r0 FFF...

Review: Status Flags in Program Status Register CPSR Mode N Z C V 28 31 8 4 I F T Copies of the ALU status flags (latched for some instructions). cmp r1, r2 ; update Flags after r1–r2 Flags After cmp Instruction Negative (N=‘1’) Bit 31 of the result has been set. Indicates a negative number in signed operations Zero (Z=‘1’) Result of operation was zero. Carry (C=‘1’) Result was greater than 32 bits (for unsigned arithmetic, bit 31 is the magnitude bit, and not the sign bit). oVerflow (V=‘1’) Result was greater than 31 bits (for signed arithmetic bit 31 is the sign bit and not the magnitude bit). Indicates a possible corruption of the sign bit in signed numbers (carry into the msb  carry out of msb) Current Program Status Register (CPSR) can be considered as an extension of the PC. It contains the: condition code flags, N,Z,C,V. interrupt (FIQ, IRQ) disable bits mode bits T bit Software must never change value in TBIT. If this happens, the processor will enter an unpredictable state. Lower 28 bits known as the "control bits". Bits other than the specified interrupt and mode bits are reserved for future processors, and no program should depend on their values. The condition codes in the CPSR will be preserved or updated depending on the value of the S bit in the instruction. Some instructions do alter condition flags regardless of “S”, ie CMN, CMP, TST and TEQ (return no other result). Mode field bigger than needs to be - just history. Only six modes valid on pre-ARM Architecture v4 chips. SPSRs Also five other PSRs, the Saved Program Status Registers, one for each privilege mode, into which a copy of the CPSR is loaded when an exception occurs.

Cmp Instructions and CPSR Flags (#1/3) 28 31 24 20 16 12 8 4 N Z C V cmp r1, r2 ;Update flags after r1–r2 CPSR x1xx = Z set (equal)(eq) x0xx = Z clear (not equal)(ne) xx1x = C set (unsigned higher or same) (hs/cs) xx0x = C clear (unsigned lower) (lo/cc) x01x = C set and Z clear (unsigned higher)(hi) 1xxx = N set (negative) (mi) 0xxx = N clear (positive or zero) (pl) xx0x OR x1xx = C clear or Z set (unsigned lower or same)(ls)

Cmp Instructions and CPSR Flags (#2/3) 28 31 24 20 16 12 8 4 cmp r1, r2 ;Update flags after r1–r2 N Z C V CPSR xxx1 = V set (signed overflow)(vs) xxx0 = V clear (signed no overflow) (vc) 1xx1 = N set and V set (signed greater or equal (ge) 0xx0 = N clear and V clear (signed greater or equal)(ge) 1xx0 = N set and V clear (signed less than) (lt) 0xx1 = N clear and V set (signed less than) (lt) 10x1 = Z clear, and N set and V set (signed greater)(gt) 00x0 = Z clear, and N clear and V clear (signed greater) (gt) N = V (signed greater or equal (ge) N  V (signed less than) (lt) Z clear AND (N =V) (signed greater than) (gt)

cmp Instructions and CPSR Flags (#3/3) 28 31 24 20 16 12 8 4 N Z C V cmp r1, r2 ;Update flags after r1–r2 CPSR Z set OR N  V (signed less or equal)(le) x1xx = Z set (equal)(eq) 1xx0 = N set and V clear (signed less) (le) 0xx1 = N clear and V set (signed less) (le)

Example Assuming r1 = 0x7fffffff, and r2 = 0xffffffff What the CPSR flags would be after the instruction; cmp r1, r2 Answer: r1 = 2147483647 r2 = (4294967295)or(-1) (Unsigned) (signed) r1- r2 = 0x7fff ffff - 0xffff ffff r1- r2 = 0x7fff ffff + - 0xffff ffff 0x0000 0001 2’s complement of 0xffff ffff 0x8000 0000 (carry into msb  carry out of msb) 0 (carry out) N=1, Z= 0, C = 0, V=1 C clear  (unsigned lower) (lo/cc) Z clear AND (N =V)  (signed greater than) (gt) 2147483647 > -1

Branch Instruction Conditional Execution Field 28 24 31 23 20 16 12 8 4 COND 24-bit signed offset L 101 cmp r1, r2 B{<cont>} xyz 0000 = EQ - Z set (equal) 0001 = NE - Z clear (not equal) 0010 = HS / CS - C set (unsigned higher or same) 0011 = LO / CC - C clear (unsigned lower) 0100 = MI -N set (negative) 0101 = PL- N clear (positive or zero) 0110 = VS - V set (overflow) 0111 = VC - V clear (no overflow) 1000 = HI - C set and Z clear (unsigned higher) 1001 = LS - C clear or Z set (unsigned lower or same) 1010 = GE - N set and V set, or N clear and V clear (signed >or =) 1011 = LT - N set and V clear, or N clear and V set (signed <) 1100 = GT - Z clear, and either N set and V set, or N clear and V clear (signed >) 1101 = LE - Z set, or N set and V clear,or N clear and V set (signed <, or =) 1110 = AL - always 1111 = NV - reserved.

Flag Setting Instructions Compare cmp r1, r2 ; Update flags after r1 – r2 Compare Negated cmn r1, r2 ; Update flags after r1 + r2 Test tst r1, r2 ; Update flags after r1 AND r2 Test Equivalence teq r1, r2 ; Update flags after r1 EOR r2 These instructions DO NOT save results; Only UPDATE CPSR Flags

Flag Setting Instructions Example Assuming r1 = 0x7fffffff, and r2 = 0xffffffff What the CPSR flags would be after the instructions cmp r1, r2, lsl #2 cmn r1, r2, lsl #2 tst r1, r2, lsr #1 teq r1, r2, lsr #1

Flag Setting Instructions Example Solution (#1/4) cmp r1, r2, lsl #2 Answer: r1 = 0x7fffffff = 2147483647 r2 lsl #2 = 0xfffffffc = 4294967292 (unsigned) = (-4) (signed) r1 – (r2, lsl #2) = 0x7fff ffff + 0x0000 0004 2’s complement of 0xffff fffc 0x8000 0003 (carry into msb  carry out of msb) 0 (carry out) N=1, Z= 0, C = 0, V = 1 C clear  (unsigned lower) (lo/cc) 2147483647 < 4294967292 Z clear AND (N = V)  (signed greater than) (gt) 2147483647 > -4

Flag Setting Instructions Example Solution (#2/4) cmn r1, r2, lsl #2 Answer: r1 = 0x7fffffff = 2147483647 r2 lsl #2 = 0xfffffffc = 4294967292 (unsigned) = (-4) (signed) r1 + r2, lsl #2 = r1 – (-(r2 <<2) (comparing r1 and –r2) 0x7fff ffff + 0xffff fffc 0x7fff fffb (carry into msb = carry out of msb) 1 (carry out) N = 0, Z= 0, C = 1, V = 0 C set  (unsigned higher or same) (hs/cc). C set here really means there was an unsigned addition overflow Z clear AND (N = V)  (signed greater than) (gt) 2147483647 > -(-4) = 4

Flag Setting Instructions Example Solution (#3/4) tst r1, r2, lsr #1 Answer: r1 = 0x7fffffff R2, lsr #1 = 0x7fffffff Destination C lsr r1 and r2 lsr # 1 = 0x7fff ffff and 0x7fff ffff N = 0, Z= 0, C = 1, V= 0 N clear  (Positive or Zero) (pl) Z clear  (Not Equal) (ne). It really means ANDing of r1 and r2 does not make all bits 0 , ie r1 AND r2  0

Flag Setting Instructions Example Solution (#4/4) teq r1, r2, lsr #1 Answer: r1 = 0x7fffffff R2, lsr #1 = 0x7fffffff Destination C lsr r1 eor r2 lsl # 1 = 0x7fff ffff xor 0x7fff ffff 0x0000 0000 N = 0, Z= 1, C = 1, V= 0 N clear  (Positive or Zero) (pl) Z set  (Equal) It means r1 = r2

Updating CPSR Flags with Data Processing Instructions By default, data processing operations do not affect the condition flags add r0,r1,r2 ; r0 = r1 + r2 ; ... and DO not set ; flags To cause the condition flags to be updated, the “S” bit of the instruction needs to be set by postfixing the instruction with an “S”. For example to add two numbers and set the condition flags: adds r0,r1,r2 ; r0 = r1 + r2 ; ... and DO set flags

Updating Flags Example Compile this C code into ARM: sum = 0; for (i=0;i<10;i=i+1) sum = sum + A[i]; sum:v1, i:v2, base address of A:v3

Updating Flags Example Solution Ver 1 sum = 0; for (i=0;i<10;i=i+1) sum = sum + A[i]; sum:v1, i:v2, base address of A:v3 C mov v1, #0 mov v2, #0 Loop: ldr a1,[v3,v2,lsl #2] ; a1=A[i] add v1, v1, a1 ;sum = sum+A [i] add v2, v2, #1 ;increment i cmp v2, #10 ; Check(i<10) bne Loop ; goto loop A R M

Updating Flags Example Solution Ver 2 sum = 0; for (i=0;i<10;i=i+1) sum = sum + A[i]; sum:v1, i:v2, base address of A:v3 C mov v1, #0 mov v2, #9 ; start with i = 9 Loop: ldr a1,[v3,v2,lsl #2] ; a1=A[i] add v1, v1, a1 ;sum = sum+A [i] sub v2, v2, #1 ;decrement i cmp v2, #0 ; Check(i<0) bge Loop ; goto loop A R M

Updating Flags Example Solution Ver 3 sum = 0; for (i=0;i<10;i=i+1) sum = sum + A[i]; sum:v1, i:v2, base address of A:v3 C mov v1, #0 mov v2, #9 ; start with i = 9 Loop: ldr a1,[v3,v2,lsl #2] ; a1=A[i] add v1, v1, a1 ; sum = sum+A [i] subs v2, v2, #1 ; decrement i ; update flags bge Loop ; goto loop A R M

ELEC2041 Reading Materials (Week #5) Week #5: Steve Furber: ARM System On-Chip; 2nd Ed, Addison-Wesley, 2000, ISBN: 0-201-67519-6. We use chapters 3 and 5 ARM Architecture Reference Manual –On CD ROM

Conditional Execution Recall Conditional Branch Instruction: beq, bne, bgt, bge, blt, ble, bhi, bhs,blo, bls, etc Almost all processors only allow branch instructions to be executed conditionally. However by reusing the condition evaluation hardware, ARM effectively increases number of instructions. All instructions contain a condition field which determines whether the CPU will execute them. This removes the need for many branches, Allows very dense in-line code, without branches. Example: subs v2, v2,#1 ; Update flags addeq v3,v3, #2 ; add if EQ (Z = 1)

Conditional Code Example Convert the GCD algorithm given in this flowchart into 1) “Normal” assembler, where only branches can be conditional. 2) ARM assembler, where all instructions are conditional, thus improving code density. The only instructions you need are cmp, b and sub. Start Stop r0 = r1 ? r0 > r1 ? r0 = r0 - r1 r1 = r1 - r0 Yes No

Conditional Code Example (Solution) “Normal” Assembler gcd cmp r0, r1 ;reached the end? beq stop blt less ;if r0 > r1 sub r0, r0, r1 ;subtract r1 from r0 bal gcd less sub r1, r1, r0 ;subtract r0 from r1 stop ARM Conditional Assembler gcd cmp r0, r1 ;if r0 > r1 subgt r0, r0, r1 ;subtract r1 from r0 sublt r1, r1, r0 ;else subtract r0 ; from r1 bne gcd ;reached the end? r0 = r1 = 1 Normal cmp - 1 beq - 3 (4) Cond sub - x - 1 sub - x - 1 bne - x - 1 r0 = 1, r1 = 2 Normal cmp - 1 beq - x - 1 blt - 3 sub - 1 bal - 3 beq - 3 (13) Cond sub - x - 1 bne - 3 sub - x -1 sub - x - 1 bne - x - 1 (10) r0 = 2, r1 = 1 Normal cmp - 1 beq - x - 1 blt -x -1 sub - 1 bal - 3 beq - 3 (11) Cond sub - 1 sub - x - 1 bne - 3 sub -x -1 sub - x -1 bne -x -1 (10)

Long Integer Addition Example long int = 64 bits long int l, m, n; n = l + m; /*Won’t work in C. Still treats long int as int */ r0 r2 r1 r3 + 31 32 63 r4 r5 C l m n r0 = r1 = 1 Normal cmp - 1 beq - 3 (4) Cond sub - x - 1 sub - x - 1 bne - x - 1 r0 = 1, r1 = 2 Normal cmp - 1 beq - x - 1 blt - 3 sub - 1 bal - 3 beq - 3 (13) Cond sub - x - 1 bne - 3 sub - x -1 sub - x - 1 bne - x - 1 (10) r0 = 2, r1 = 1 Normal cmp - 1 beq - x - 1 blt -x -1 sub - 1 bal - 3 beq - 3 (11) Cond sub - 1 sub - x - 1 bne - 3 sub -x -1 sub - x -1 bne -x -1 (10)

Long Integer Addition Example (Analysis) We need to do the addition in two steps struct int64 {int lo; int hi; }l, m, n; n.lo = m.lo + l.lo; n.hi = m.hi + l.hi + C; How to check on carry in C? r0 r2 r1 r3 + 31 32 63 r4 r5 C l m n lo hi r0 = r1 = 1 Normal cmp - 1 beq - 3 (4) Cond sub - x - 1 sub - x - 1 bne - x - 1 r0 = 1, r1 = 2 Normal cmp - 1 beq - x - 1 blt - 3 sub - 1 bal - 3 beq - 3 (13) Cond sub - x - 1 bne - 3 sub - x -1 sub - x - 1 bne - x - 1 (10) r0 = 2, r1 = 1 Normal cmp - 1 beq - x - 1 blt -x -1 sub - 1 bal - 3 beq - 3 (11) Cond sub - 1 sub - x - 1 bne - 3 sub -x -1 sub - x -1 bne -x -1 (10)

Long Integer Carry Generation Statement n.lo = l.lo + m.lo; would generate a carry C if: … 0 11 … … 0 10 … … 1 01 … C=1 (Bit 31 of l.lo = 1) and (bit 31 of m.lo = 1) … 0 11 … … 0 01 … … 1 00 … C=1 Or (Bit 31 of l.lo = 1) and (bit 31 of n.lo  1) … 0 01 … … 0 11 … … 1 00 … C=1 Or (Bit 31 of m.lo = 1) and (bit 31 of n.lo  1) r0 r2 r1 r3 + 31 32 63 r4 r5 C l m n hi lo r0 = r1 = 1 Normal cmp - 1 beq - 3 (4) Cond sub - x - 1 sub - x - 1 bne - x - 1 r0 = 1, r1 = 2 Normal cmp - 1 beq - x - 1 blt - 3 sub - 1 bal - 3 beq - 3 (13) Cond sub - x - 1 bne - 3 sub - x -1 sub - x - 1 bne - x - 1 (10) r0 = 2, r1 = 1 Normal cmp - 1 beq - x - 1 blt -x -1 sub - 1 bal - 3 beq - 3 (11) Cond sub - 1 sub - x - 1 bne - 3 sub -x -1 sub - x -1 bne -x -1 (10)

Long Integer Addition Example in C struct int64 {int lo; int hi; }; struct int64 ad_64(struct int64 l, struct int64 m){ struct int64 n; unsigned hibitl=l.lo >> 31, hibitm=m.lo >> 31, hibitn; n.lo=l.lo + m.lo; hibitn=n.lo >> 31; n.hi=l.hi + m.hi + ((hibitl & hibitm) || (hibitl & ~hibitn) || (hibitm & ~hibitn)); return n; } r0 = r1 = 1 Normal cmp - 1 beq - 3 (4) Cond sub - x - 1 sub - x - 1 bne - x - 1 r0 = 1, r1 = 2 Normal cmp - 1 beq - x - 1 blt - 3 sub - 1 bal - 3 beq - 3 (13) Cond sub - x - 1 bne - 3 sub - x -1 sub - x - 1 bne - x - 1 (10) r0 = 2, r1 = 1 Normal cmp - 1 beq - x - 1 blt -x -1 sub - 1 bal - 3 beq - 3 (11) Cond sub - 1 sub - x - 1 bne - 3 sub -x -1 sub - x -1 bne -x -1 (10)

Long Integer Addition Example Compiled /* l.lo, l.hi, m.lo and m.hi are passed in r0-r1*/ str lr, [sp,-#4]! ; store ret add. mov ip, r0, asr #31 ; hibitl (l.lo>>31) mov lr, r2, asr #31 ; hibitm,(m.lo>>31) add r0, r0, r2 ; n.lo = l.lo + m.lo add r1, r3, r1 ; n.hi = l.hi + m.hi mov r2, r0, asr #31 ; hibitn,(n.lo>>31) tst lr, ip ; is hibitl=hibitm ? bne .L3 mvn r2, r2 ; ~(hibitn) tst ip, r2 ; is hibitl=~hibitn ? tst lr, r2 ; is hibitm=~hibitn ? beq .L2 .L3: mov r2, #1 ; C = 1 .L2: add r1, r1, r2 ; n.hi = l.hi + m.hi + C ldr lr, [sp,#4]! ; get ret add. mov pc, lr ;n.lo n.hi retuned in r0-r1 r0 = r1 = 1 Normal cmp - 1 beq - 3 (4) Cond sub - x - 1 sub - x - 1 bne - x - 1 r0 = 1, r1 = 2 Normal cmp - 1 beq - x - 1 blt - 3 sub - 1 bal - 3 beq - 3 (13) Cond sub - x - 1 bne - 3 sub - x -1 sub - x - 1 bne - x - 1 (10) r0 = 2, r1 = 1 Normal cmp - 1 beq - x - 1 blt -x -1 sub - 1 bal - 3 beq - 3 (11) Cond sub - 1 sub - x - 1 bne - 3 sub -x -1 sub - x -1 bne -x -1 (10)

Long Integer Addition Example ARM /* l.lo, l.hi, m.lo and m.hi are passed in r0-r1*/ str lr, [sp,-#4]! ; store ret add. adds r0, r0, r2 ; n.lo = l.lo + m.lo adc r1, r3, r1 ; n.hi = l.hi + m.hi + C ldr lr, [sp,#4]! ; get ret add. mov pc, lr ;n.lo n.hi retuned in r0-r1 adc Is add with Carry r0 = r1 = 1 Normal cmp - 1 beq - 3 (4) Cond sub - x - 1 sub - x - 1 bne - x - 1 r0 = 1, r1 = 2 Normal cmp - 1 beq - x - 1 blt - 3 sub - 1 bal - 3 beq - 3 (13) Cond sub - x - 1 bne - 3 sub - x -1 sub - x - 1 bne - x - 1 (10) r0 = 2, r1 = 1 Normal cmp - 1 beq - x - 1 blt -x -1 sub - 1 bal - 3 beq - 3 (11) Cond sub - 1 sub - x - 1 bne - 3 sub -x -1 sub - x -1 bne -x -1 (10)

Long Integer Addition Example in C (GCC) long long type extension in gcc long long ad_64(long long l,long long m){ long long n; n = m + l; return n; } ARM Compiled Code ad_64: /* l.lo, l.hi, m.lo and m.hi are passed in r0- r1*/ adds r0, r0, r2 ; n.lo = l.lo + m.lo adc r1, r3, r1 ; n.hi = l.hi + m.hi + C mov pc, lr Long long type is 64 bits r0 = r1 = 1 Normal cmp - 1 beq - 3 (4) Cond sub - x - 1 sub - x - 1 bne - x - 1 r0 = 1, r1 = 2 Normal cmp - 1 beq - x - 1 blt - 3 sub - 1 bal - 3 beq - 3 (13) Cond sub - x - 1 bne - 3 sub - x -1 sub - x - 1 bne - x - 1 (10) r0 = 2, r1 = 1 Normal cmp - 1 beq - x - 1 blt -x -1 sub - 1 bal - 3 beq - 3 (11) Cond sub - 1 sub - x - 1 bne - 3 sub -x -1 sub - x -1 bne -x -1 (10)

“And in Conclusion …” Flag Setting Instructions: cmp, cmn, tst, teq in ARM Data Processing Instructions with Flag setting Feature: adds, subs, ands, in ARM Conditional Instructions: addeq, ldreq,etc in ARM