Instructions for Making Decisions

Slides:



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

Goal: Write Programs in Assembly
4.
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
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:
1 ECE462/562 ISA and Datapath Review Ali Akoglu. 2 Instruction Set Architecture A very important abstraction –interface between hardware and low-level.
CPS3340 COMPUTER ARCHITECTURE Fall Semester, /15/2013 Lecture 11: MIPS-Conditional Instructions Instructor: Ashraf Yaseen DEPARTMENT OF MATH & COMPUTER.
MIPS processor continued. Review Different parts in the processor should be connected appropriately to be able to carry out the functions. Connections.
1 ECE369 ECE369 Chapter 2. 2 ECE369 Instruction Set Architecture A very important abstraction –interface between hardware and low-level software –standardizes.
ECE 15B Computer Organization Spring 2010 Dmitri Strukov Lecture 5: Data Transfer Instructions / Control Flow Instructions Partially adapted from Computer.
CS1104 – Computer Organization PART 2: Computer Architecture Lecture 5 MIPS ISA & Assembly Language Programming.
Chapter 2 Instructions: Language of the Computer
Inst.eecs.berkeley.edu/~cs61c UCB CS61C : Machine Structures Lecture 6 – Introduction to MIPS Data Transfer & Decisions I Pieter Abbeel’s recent.
CS61C L09 Introduction to MIPS: Data Transfer & Decisions I (1) Garcia © UCB Lecturer PSOE Dan Garcia inst.eecs.berkeley.edu/~cs61c.
CS 61C L09 Introduction to MIPS: Data Transfer & Decisions I (1) Garcia, Fall 2004 © UCB Lecturer PSOE Dan Garcia inst.eecs.berkeley.edu/~cs61c.
CSCE 212 Quiz 8 – 3/23/11 1.What type of element is the ALU (combinational or state) and what does it mean for an element to be that type? 2.What is the.
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.
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.
Computer Architecture - The Instruction Set The Course’s Goals  To be interesting and fun. An interested student learns more.  To answer questions that.
ECE 232 L5 Assembl.1 Adapted from Patterson 97 ©UCBCopyright 1998 Morgan Kaufmann Publishers ECE 232 Hardware Organization and Design Lecture 5 MIPS Assembly.
Data Transfer & Decisions I (1) Fall 2005 Lecture 3: MIPS Assembly language Decisions I.
CS61C L09 Introduction to MIPS : Data Transfer and Decisions (1) Garcia, Spring 2007 © UCB Lecturer SOE Dan Garcia inst.eecs.berkeley.edu/~cs61c.
9/29: Lecture Topics Memory –Addressing (naming) –Address space sizing Data transfer instructions –load/store on arrays on arrays with variable indices.
1 Branches and Procedure Calls Lecture 14 Digital Design and Computer Architecture Harris & Harris Morgan Kaufmann / Elsevier, 2007.
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.
Chapter 2 Decision-Making Instructions (Instructions: Language of the Computer Part V)
 1998 Morgan Kaufmann Publishers MIPS arithmetic All instructions have 3 operands Operand order is fixed (destination first) Example: C code: A = B +
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.
Computer Organization Rabie A. Ramadan Lecture 3.
DR. SIMING LIU SPRING 2016 COMPUTER SCIENCE AND ENGINEERING UNIVERSITY OF NEVADA, RENO Session 11 Conditional Operations.
CSCI-365 Computer Organization Lecture Note: Some slides and/or pictures in the following are adapted from: Computer Organization and Design, Patterson.
MIPS Assembly Language Programming
MIPS Instruction Set Advantages
CS2100 Computer Organisation
MIPS Coding Continued.
Lecture 4: MIPS Instruction Set
Computer Architecture & Operations I
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,
CS170 Computer Organization and Architecture I
The University of Adelaide, School of Computer Science
MIPS coding.
Pick up the handout on your way in!!
Lecture 4: MIPS Instruction Set
MISP Assembly.
MIPS Instruction Encoding
ECE232: Hardware Organization and Design
MIPS coding.
September 24 Test 1 review More programming
C second, objective-c, Go up!
MIPS Instruction Encoding
MIPS coding.
The University of Adelaide, School of Computer Science
MIPS Assembly.
3.
COMS 361 Computer Organization
MIPS Assembly.
MIPS e pipelining Tecniche di base.
MIPS Coding Continued.
MIPS coding.
MIPS assembly.
9/27: Lecture Topics Memory Data transfer instructions
MIPS Processor.
MIPS instructions.
Presentation transcript:

Instructions for Making Decisions 9/22/2018 Instructions for Making Decisions A distinctive feature of programs is that they can make different decisions based on the input data 9/22/2018 CDA3100 CDA3100

Instruction beq (branch if equal) 9/22/2018 Instruction beq (branch if equal) To support decision making, MIPS has conditional branch instruction: beq register1, register2, L1 Equivalent to the following in C: if (register1 == register2) goto L1; In other words, if the two registers have the same value, go to L1; otherwise, nothing happens L1 is a label, which can be considered as the name of the address of an instruction. An instruction is also stored in the memory, and of course has an address The address is 32 bits, but is impossible to know or be remembered by the programmers, so we create labels to refer to the addresses We can write lines like to introduce a label for an instruction: L1: add $t0, $t1, $t2 Go to a label means that fetch that instruction at the address associated with a label from the memory and execute the instruction An address can be associated with more than one label Keep in mind that if the condition is not true, nothing happens, meaning that the processor will just execute the instruction appearing immediately after the beq in your program 9/22/2018 CDA3100 CDA3100

9/22/2018 Instruction bne Similarly, bne (branch not equal) means go to L1 if the value in register1 does not equal to the value in regster2 bne register1, register2, L1 9/22/2018 CDA3100 CDA3100

MIPS has also an unconditional branch, equivalent to goto in C: 9/22/2018 Instruction j (jump) MIPS has also an unconditional branch, equivalent to goto in C: j L1 Jump to the instruction labeled with L1 9/22/2018 CDA3100 CDA3100

Compiling if-then-else 9/22/2018 Compiling if-then-else Suppose variables f, g, h, i, and j are in registers $s0 through $s4, how to implement the following in MIPS? 9/22/2018 CDA3100 CDA3100

Compiling if-then-else 9/22/2018 Compiling if-then-else Suppose variables f, g, h, i, and j are in registers $s0 through $s4, how to implement the following in MIPS? 9/22/2018 CDA3100 CDA3100

Compiling if-then-else 9/22/2018 Compiling if-then-else Suppose variables f, g, h, i, and j are in registers $s0 through $s4, how to implement the following in MIPS? 9/22/2018 CDA3100 CDA3100

MIPS Assembly for if-then-else 9/22/2018 MIPS Assembly for if-then-else Now it is straightforward to translate the C program into MIPS assembly 9/22/2018 CDA3100 CDA3100

Questions If $t0 is holding 17, $t1 is holding 8, what will be the value stored in $t2 after the following instructions? andi $t0, $t0, 3 beq $t0, $0, L1 addi $t0, $t0, 1 L1: add $t2, $t0, $t1   (a) 10. (b) 8. (c) 2. (d) None of the above. Answer: a.