Decision Making.

Slides:



Advertisements
Similar presentations
CENG 311 Decisions in C/Assembly Language
Advertisements

Goal: Write Programs in Assembly
4.
Lecture 5: MIPS Instruction Set
MIPS assembly. Review  Lat lecture, we learnt  addi,  and, andi, or, ori, xor, xori, nor,  beq, j, bne  An array is stored sequentially in the memory.
Branches Two branch instructions:
Lecture 20: 11/12/2002CS170 Fall CS170 Computer Organization and Architecture I Ayman Abdel-Hamid Department of Computer Science Old Dominion University.
Control Structures in ARM Implementation of Decisions Similar to accumulator instructions One instruction sets the flags, followed by another instruction.
CPS3340 COMPUTER ARCHITECTURE Fall Semester, /15/2013 Lecture 11: MIPS-Conditional Instructions Instructor: Ashraf Yaseen DEPARTMENT OF MATH & COMPUTER.
Comp Sci Control structures 1 Ch. 5 Control Structures.
Solution 2nd Exam.
ECE 15B Computer Organization Spring 2010 Dmitri Strukov Lecture 5: Data Transfer Instructions / Control Flow Instructions Partially adapted from Computer.
1 CDA 3101 Discussion Section 03.  Problem The following problems deal with translating from C to MIPS. Assume that the variables f, g, h, i and.
Assembly Code Example Selection Sort.
The University of Adelaide, School of Computer Science
CMPT 334 Computer Organization Chapter 2 Instructions: Language of the Computer [Adapted from Computer Organization and Design 5 th Edition, Patterson.
Apr. 12, 2000Systems Architecture I1 Systems Architecture I (CS ) Lecture 6: Branching and Procedures in MIPS* Jeremy R. Johnson Wed. Apr. 12, 2000.
CSCE 212 Quiz 2 – 2/2/11 1.What is the purpose of the jal instruction? 2.What are the two conditional branching (if, goto; not the slt instruction) instructions.
Lecture 5 Sept 14 Goals: Chapter 2 continued MIPS assembly language instruction formats translating c into MIPS - examples.
ECE 232 L5 Assembl.1 Adapted from Patterson 97 ©UCBCopyright 1998 Morgan Kaufmann Publishers ECE 232 Hardware Organization and Design Lecture 5 MIPS Assembly.
MIPS Instruction Set Advantages
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.
Lecture 15: 10/24/2002CS170 Fall CS170 Computer Organization and Architecture I Ayman Abdel-Hamid Department of Computer Science Old Dominion University.
MIPS coding. slt, slti slt $t3, $t1, $t2 – set $t3 to be 1 if $t1 < $t2 ; else clear $t3 to be 0. – “Set Less Than.” slti $t3, $t1, 100 – set $t3 to be.
11/02/2009CA&O Lecture 03 by Engr. Umbreen Sabir Computer Architecture & Organization Instructions: Language of Computer Engr. Umbreen Sabir Computer Engineering.
MIPS Machine Assembly Language Opening Discussion zWhat did we talk about last class? zHave you seen anything interesting in the news? zDo you.
IFT 201: Unit 1 Lecture 1.3: Processor Architecture-3
17 - Jumps & Branches. The PC PC marks next location in Fetch, Decode, Execute cycle.
1 Answer #1, Quiz #1 Lp:slt $t0,$s1,$s2 # $t0 = a
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 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.
Computer Organization CS224 Fall 2012 Lessons 7 and 8.
MIPS coding. slt, slti slt $t3, $t1, $t2 – set $t3 to be 1 if $t1 < $t2 ; else clear $t3 to be 0. – “Set Less Than.” slti $t3, $t1, 100 – set $t3 to be.
Chapter 2 — Instructions: Language of the Computer — 1 Conditional Operations Branch to a labeled instruction if a condition is true – Otherwise, continue.
DR. SIMING LIU SPRING 2016 COMPUTER SCIENCE AND ENGINEERING UNIVERSITY OF NEVADA, RENO Session 11 Conditional Operations.
Ch2a- 2 EE/CS/CPE Computer Organization  Seattle Pacific University Taking orders A computer does what you tell it to do Not necessarily what.
Control Structures Computer Organization I 1 October 2009 © McQuain, Feng & Ribbens Conditional Control Structure if ( i < j ) goto A; else.
CSCI-365 Computer Organization Lecture Note: Some slides and/or pictures in the following are adapted from: Computer Organization and Design, Patterson.
Computer Organization CS345 David Monismith Based upon notes by Dr. Bill Siever and notes from the Patternson and Hennessy Text.
Computer Architecture & Operations I
MIPS Assembly Language Programming
MIPS Instruction Set Advantages
CS2100 Computer Organisation
Lecture 4: MIPS Instruction Set
Computer Architecture & Operations I
Decision Making.
More Branch Instructions and Set Instructions
Conditional Branches What distinguishes a computer from a simple calculator is its ability to make decisions Decisions are made using the if statement,
Conditional Control Structure
Instructions for Making Decisions
CS170 Computer Organization and Architecture I
The University of Adelaide, School of Computer Science
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
How to represent signed integers
MIPS coding.
MIPS coding.
MIPS Coding.
The University of Adelaide, School of Computer Science
COMS 361 Computer Organization
ARM Control Structures
MIPS assembly.
Conditional Control Structure
MIPS instructions.
Part VI Looping Structures
Conditional Branching (beq)
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 MIPS Only two such instructions: beq $t0, $t1, label If value in $t0 equals value in $t1, go to instruction at label otherwise, execute next instruction in order bne $t0, $t1, label If value in $t0 does not equal value in $t1, go to instruction at label

if statement in assembly if(a == b) // a in $t0, b in $t1 {c = 1} // c in $s0 // next instruction bne $t0, $t1, endif addi $s0, $zero, 1 endif: # next instruction

if - else if(a == b) // a in $t0, b in $t1 {c = 1} // c in $s0 else // next instruction

if – else in assembly bne $t0, $t1, else addi $s0, $zero, 1 j endif endif: # next instruction

What about other comparisons? etc…

Set less than instruction slt $t0, $s1, $s2 If value in $s1 is less than value in $s2, then set the value in $t0 to 1, otherwise set $t0 to 0 Use slt combined with beq or bne, comparing to the $zero register, for an if comparison.

If again if(a < b) // a in $t0, b in $t1 {c = 1} // c in $s0 // next instruction slt $t2, $t0, $t1 beq $t2, $zero, endif addi $s0, $zero, 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 $t0, # and register $s0 contains 10 loop: slt $t1, $t0, $s0 b?? $t1, $zero, loopend # do something addi $t0, $t0, 1 j loop loopend: # next instruction

while loop # Assume count is in register $t0, # and register $s0 contains 10 loop: slt $t1, $t0, $s0 beq $t1, $zero, loopend # do something addi $t0, $t0, 1 j loop loopend: # next instruction

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

for loop example - assembly addi $t0, $zero, 5 loop: slt $t1, $t0, $zero bne $t1, $zero, loopend # do something addi $t0, $t0, -1 j loop loopend: # next instruction