Decision Making.

Slides:



Advertisements
Similar presentations
EECC250 - Shaaban #1 Lec # 2 Winter Addressing Modes  Addressing modes are concerned with the way data is accessed  Addressing can be.
Advertisements

4-1 EE 319K Introduction to Embedded Systems Lecture 4: Arithmetic overflow, Branches, Control Structures, Abstraction & Refinement Bard, Erez, Gerstlauer,
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
Comp Sci Control structures 1 Ch. 5 Control Structures.
CMPT 334 Computer Organization Chapter 2 Instructions: Language of the Computer [Adapted from Computer Organization and Design 5 th Edition, Patterson.
ACOE2511 Assembly Language Arithmetic and Logic Instructions.
Lecture 5: Decision and Control CS 2011 Fall 2014, Dr. Rozier.
CS2422 Assembly Language & System Programming October 17, 2006.
Flow Control Instructions
Conditional Processing If … then … else While … do; Repeat … until.
CEG 320/520: Computer Organization and Assembly Language ProgrammingFlow Control 1 Flow Control.
LAB Flag Bits and Register
ECE 265 – LECTURE 8 The M68HC11 Basic Instruction Set The remaining instructions 10/20/ ECE265.
Making Decision – Microprocessor
Lecture 8. MIPS Instructions #3 – Branch Instructions #1 Prof. Taeweon Suh Computer Science Education Korea University 2010 R&E Computer System Education.
Microprocessors Monday, Apr. 13 Dr. Asmaa Farouk Faculty of Engineering, Electrical Department, Assiut University.
11/02/2009CA&O Lecture 03 by Engr. Umbreen Sabir Computer Architecture & Organization Instructions: Language of Computer Engr. Umbreen Sabir Computer Engineering.
Chapter 10 The Assembly Process. What Assemblers Do Translates assembly language into machine code. Assigns addresses to all symbolic labels (variables.
ECE 447: Lecture 12 Logic, Arithmetic, Data Test and Control Instructions of MC68HC11.
Topic 7: Control Flow Instructions CSE 30: Computer Organization and Systems Programming Winter 2011 Prof. Ryan Kastner Dept. of Computer Science and Engineering.
Arithmetic Flags and Instructions
(Flow Control Instructions)
Natawut NupairojAssembly Language1 Control Structure.
Computer Architecture and Operating Systems CS 3230 :Assembly Section Lecture 5 Department of Computer Science and Software Engineering University of Wisconsin-Platteville.
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.
EEL 3801 Part V Conditional Processing. This section explains how to implement conditional processing in Assembly Language for the 8086/8088 processors.
DR. SIMING LIU SPRING 2016 COMPUTER SCIENCE AND ENGINEERING UNIVERSITY OF NEVADA, RENO Session 11 Conditional Operations.
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),
5-1 EE 319K Introduction to Microcontrollers Lecture 5: Conditionals, Loops, Modular Programming, Sub- routines, Parameter passing.
Deeper Assembly: Addressing, Conditions, Branching, and Loops
The Little man computer
Microprocessor Systems Design I
Slide 7 Mikroprosesor Sub. Algoritma Program___
Status Register Status = system byte (supervisor only) + user byte = system status + condition code register usually, it is not important to know.
Homework Reading Labs PAL, pp
ECE 3430 – Intro to Microcomputer Systems
The University of Adelaide, School of Computer Science
Making Decisions and Writing Loops
ICS312 SET 7 Flags.
ECE 3430 – Intro to Microcomputer Systems
Decision Making.
Conditional Branches What distinguishes a computer from a simple calculator is its ability to make decisions Decisions are made using the if statement,
The FLAGS Register An x bit means an unidentified value 9/12/2018
Morgan Kaufmann Publishers Computer Organization and Assembly Language
More on logical instruction and
Microprocessor and Assembly Language
MIPS ALU.
Memory Organisation Source: under
Lecture 4 ( Assembly Language).
Pick up the handout on your way in!!
Week 6 The darkness, the loop of negative thoughts on repeat, clamours and interferes with the music I hear in my head. Lady Gaga.
ARM Control Structures
CS 235 Computer Organization & Assembly Language
MIPS ALU.
And conditional branching
ECE 3430 – Intro to Microcomputer Systems
Program Logic and Control
Program Logic and Control
Homework Reading Machine Projects Labs PAL, pp
Write a program to calculate x**y, given x and y.
The University of Adelaide, School of Computer Science
ARM Control Structures
EECE.3170 Microprocessor Systems Design I
Chapter 7 –Program Logic and Control
EECE.3170 Microprocessor Systems Design I
Chapter 7 –Program Logic and Control
Branch & Call Chapter 4 Sepehr Naimi
An Introduction to the ARM CORTEX M0+ Instructions
Presentation transcript:

Decision Making

if and loops Need to do one of two things if : do next instruction or skip to another (else) loop: continue in loop or exit loop

Decision instructions in ARMv8 Simple instructions: cbz X9, label Conditional branch on zero If value in X9 equals zero, go to instruction at label otherwise, execute next instruction in order cbnz X9, label Conditional branch if not zero If value in X9 does not equal zero, go to instruction at label

if statement in assembly if(a == b) // a in X19, b in X20 {c = 1} // c in X21 // next instruction sub X9, X19, X20 cbnz X9, endif mov X21, #1 endif: // next instruction

if - else if(a == b) // a in X19, b in X20 {c = 1} // c in X21 else // next instruction

if – else in assembly sub X9, X19, X20 cbnz X9, else mov X21, 1 b endif else: mov X21, 0 endif: # next instruction

What about other comparisons? etc…

Conditional branches based on flags Flags set by instructions set by arithmetic/logical instructions indicate facts about previous result four bits negative(N) result was negative zero (Z) result was zero overflow(V) result had overflow result(C) result had a carry out of most significant bit, or borrow into most significant bit

Conditional branches based on flags Most commonly used with subs subtract and set flags subs XZR, X9, X10 X9 – X10, set flags, can’t write to XZR Condition branches on relation between X9, X10 b.lt branch if less than; b.le branch if less than or equal b.gt, (bge) branch if greater than (or equal) Unsigned conditions b.lo, (b.ls) branch if lower (or same) b.hi, (b.hs) branch if higher (or same)

Conditional branches based on flags Can test flags directly, when they are set by one of a limited set of operations,(append s to instruction to indicate that flags will be set, e.g. adds) b.m branch on minus (N = 1) b.pl branch on plus (N = 0) b.vs branch if overflow (V = 1) b.vc branch if overflow clear (V = 0)

if again if(a < b) // a in X19, b in X20 {c = 1} // c in X21 // next instruction subs XZR, X19, X20 b.lt endif mov X21, 1 endif: # next instruction

while loop while (condition) { loop body } Each time at the top of the loop, check the condition. If true, continue the loop. At the end of the loop, go back to check the condition again.

while loop example - c while(count < 10) { // do something } // next instruction

while loop example - assembly // Assume count is in register X10, // and register X19 contains 10 loop: subs XZR, X10, X19 b.?? loopend # do something add X10, X10, 1 b loop loopend: # next instruction

while loop example - assembly // Assume count is in register X10, // and register X19 contains 10 loop: subs XZR, X10, X19 b.ge loopend # do something add X10, X10, 1 b loop loopend: # next instruction

for loop example - c for(cnt = 5, cnt >= 0, cnt--) { // do something } // next instruction

for loop example - assembly mov X10, #5 loop: subs XZR, X10, #0 b.lt loopend # do something sub X10, X10, #1 b loop loopend: # next instruction