Lecture 15: 10/24/2002CS170 Fall 20021 CS170 Computer Organization and Architecture I Ayman Abdel-Hamid Department of Computer Science Old Dominion University.

Slides:



Advertisements
Similar presentations
1 Lecture 3: MIPS Instruction Set Today’s topic:  More MIPS instructions  Procedure call/return Reminder: Assignment 1 is on the class web-page (due.
Advertisements

Lecture 13: 10/8/2002CS170 Fall CS170 Computer Organization and Architecture I Ayman Abdel-Hamid Department of Computer Science Old Dominion University.
Goal: Write Programs in Assembly
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.
Lecture 20: 11/12/2002CS170 Fall CS170 Computer Organization and Architecture I Ayman Abdel-Hamid Department of Computer Science Old Dominion University.
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.
©UCB CS 161 Lecture 4 Prof. L.N. Bhuyan
ECE 15B Computer Organization Spring 2010 Dmitri Strukov Lecture 5: Data Transfer Instructions / Control Flow Instructions Partially adapted from Computer.
Lecture 6: MIPS Instruction Set Today’s topic –Control instructions –Procedure call/return 1.
CS1104 – Computer Organization PART 2: Computer Architecture Lecture 5 MIPS ISA & Assembly Language Programming.
Chapter 2 Instructions: Language of the Computer
1 Today’s lecture  Last lecture we started talking about control flow in MIPS (branches)  Finish up control-flow (branches) in MIPS —if/then —loops —case/switch.
Apr. 12, 2000Systems Architecture I1 Systems Architecture I (CS ) Lecture 6: Branching and Procedures in MIPS* Jeremy R. Johnson Wed. Apr. 12, 2000.
CS2100 Computer Organisation MIPS Part III: Instruction Formats (AY2014/2015) Semester 2.
1 Warning! Unlike the previous lessons, for today's lesson you will have to listen, think and even understand (for the exam, of course). Individuals with.
Instruction Representation II (1) Fall 2007 Lecture 10: Instruction Representation II.
S. Barua – CPSC 440 CHAPTER 2 INSTRUCTIONS: LANGUAGE OF THE COMPUTER Goals – To get familiar with.
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.
Instruction Representation II (1) Fall 2005 Lecture 10: Instruction Representation II.
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
ISA-2 CSCE430/830 MIPS: Case Study of Instruction Set Architecture CSCE430/830 Computer Architecture Instructor: Hong Jiang Courtesy of Prof. Yifeng Zhu.
Lecture 4 section 2.4-?? As opposed to CISC – Complicated Instruction Set Architecture (ala the x86)
Lecture 8. MIPS Instructions #3 – Branch Instructions #1 Prof. Taeweon Suh Computer Science Education Korea University 2010 R&E Computer System Education.
Lecture 19: 11/7/2002CS170 Fall CS170 Computer Organization and Architecture I Ayman Abdel-Hamid Department of Computer Science Old Dominion University.
COSC 2021: Computer Organization Instructor: Dr. Amir Asif Department of Computer Science York University Handout # 3: MIPS Instruction Set I Topics: 1.
11/02/2009CA&O Lecture 03 by Engr. Umbreen Sabir Computer Architecture & Organization Instructions: Language of Computer Engr. Umbreen Sabir Computer Engineering.
April 23, 2001Systems Architecture I1 Systems Architecture I (CS ) Lecture 9: Assemblers, Linkers, and Loaders * Jeremy R. Johnson Mon. April 23,
Lecture 4: MIPS Instruction Set
IFT 201: Unit 1 Lecture 1.3: Processor Architecture-3
CDA 3101 Fall 2013 Introduction to Computer Organization
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.
9/29: Lecture Topics Conditional branch instructions
Chapter 2 CSF 2009 The MIPS Assembly Language. Stored Program Computers Instructions represented in binary, just like data Instructions and data stored.
MS108 Computer System I Lecture 3 ISA Prof. Xiaoyao Liang 2015/3/13 1.
Computer Organization Instructions Language of The Computer (MIPS) 2.
Computer Organization CS224 Fall 2012 Lessons 7 and 8.
EET 4250 Instruction Representation & Formats Acknowledgements: Some slides and lecture notes for this course adapted from Prof. Mary Jane Penn.
Computer Architecture CSE 3322 Lecture 4 Assignment: 2.4.1, 2.4.4, 2.6.1, , Due 2/10/09
Chapter 2 — Instructions: Language of the Computer — 1 Conditional Operations Branch to a labeled instruction if a condition is true – Otherwise, continue.
CDA 3101 Spring 2016 Introduction to Computer Organization
Computer Organization Instructions Language of The Computer (MIPS) 2.
DR. SIMING LIU SPRING 2016 COMPUTER SCIENCE AND ENGINEERING UNIVERSITY OF NEVADA, RENO Session 11 Conditional Operations.
Lecture 16: 10/29/2002CS170 Fall CS170 Computer Organization and Architecture I Ayman Abdel-Hamid Department of Computer Science Old Dominion University.
March 21, 2016© Craig ZIlles (adapted from slides by Howard Huang) 1 What does this code do? label:sub$a0, $a0, 1 bne$a0, $zero, label Arf.
CMPUT Computer Organization and Architecture I1 CMPUT229 - Fall 2003 Topic3: Instructions, The Language of the Machine José Nelson Amaral.
10/1: Lecture Topics Conditional branch instructions –slides from 9/29 set Unconditional jump instructions Instruction encoding.
CSCI-365 Computer Organization Lecture Note: Some slides and/or pictures in the following are adapted from: Computer Organization and Design, Patterson.
CSCI-365 Computer Organization Lecture Note: Some slides and/or pictures in the following are adapted from: Computer Organization and Design, Patterson.
Lecture 17: 10/31/2002CS170 Fall CS170 Computer Organization and Architecture I Ayman Abdel-Hamid Department of Computer Science Old Dominion University.
Computer Architecture & Operations I
MIPS Instruction Set Advantages
MIPS Coding Continued.
Lecture 4: MIPS Instruction Set
Computer Architecture & Operations I
RISC Concepts, MIPS ISA Logic Design Tutorial 8.
CS170 Computer Organization and Architecture I
The University of Adelaide, School of Computer Science
Instructions - Type and Format
Lecture 4: MIPS Instruction Set
MIPS Instruction Encoding
MIPS Instruction Encoding
Lecture 5: Procedure Calls
The University of Adelaide, School of Computer Science
MIPS Coding Continued.
CS/COE0447 Computer Organization & Assembly Language
Presentation transcript:

Lecture 15: 10/24/2002CS170 Fall CS170 Computer Organization and Architecture I Ayman Abdel-Hamid Department of Computer Science Old Dominion University Lecture 15: 10/24/2002

CS170 Fall Outline Loops Should cover section 3.5

Lecture 15: 10/24/2002CS170 Fall A Loop with a variable array index Loop:g = g + A[i]; i = i + j; If (i != h) go to Loop Variables g, h, i, and j associated with $s1  $s4 Array base is in $s5. What is the MIPS assembly code? Loop:add $t1, $s3, $s3# $t1  2 *i add $t1, $t1, $t1# $t1  4 *i add $t1, $t1, $s5# $t1  address of A[i] lw $t0, 0($t1)# $t0  A[i] add $s1, $s1, $t0# g  g + A[i] add $s3, $s3, $s4# i = i+ j bne $s3, $s2, Loop # go to Loop if i != h

Lecture 15: 10/24/2002CS170 Fall A While Loop 1/2 while (save[i] == k) i = i + j; i, j, and k associated with $s3  $s5. Base of array save is in $s6. What is MIPS Assembly code? Save[i] == k? i = i +j Exit: Yes No Loop:add $t1, $s3, $s3# $t1  2 *i add $t1, $t1, $t1# $t1  4 *i add $t1, $t1, $s6# $t1  address of save[i] lw $t0, 0($t1)# $t0  save[i] bne $t0, $s5, Exit# go to Exit if save [i] != k add $s3, $s3, $s4#i = i + j j Loop# go to Loop Exit:

Lecture 15: 10/24/2002CS170 Fall A While Loop 2/2 Solve problem 3.9 (see handout) Previous assembly code in while example uses a conditional branch and an unconditional jump each time through the loop, which is inefficient Optimize the code so that it uses at most one branch or jump each time through the loop

Lecture 15: 10/24/2002CS170 Fall A less than test if ( a < b) go to Less a, b associated with $s0, and $s1, respectively. What is the MIPS assembly code? To test for less than we introduce a new instruction slt $t0, $s0, $s1# slt is set on less than Register $t0 is set to 1 if the value in register $s0 is less than the value in register $s1, otherwise, register $t0 is set to 0 Register $zero always contains zero Comparing $t0 to $zero gives us the effect of branching if a less than b Combining slt with bne implements branch on less than slt $t0, $s0, $s1# $t0  1 if a < b, otherwise $t0  0 bne $t0, $zero, Less# go to Less if $t0 != 0 …… Less: Why not provide one instruction that performs branch on less than?

Lecture 15: 10/24/2002CS170 Fall Case/Switch Statement 1/3 Switch statement allows the programmer to select one of many alternatives depending on a single value Can be implemented as a series of if –then-else statements (not efficient) Alternatively (or more efficiently)  First instruction within each case sequence is assigned a label (the label holds the address of the first instruction in the sequence)  These addresses are stored in a jump table in memory Use new instruction jr register (jump register) Unconditional jump to the address specified in register Program loads appropriate entry from jump table into a register, then jump to proper address using a jump register

Lecture 15: 10/24/2002CS170 Fall Case/Switch Statement 2/3 switch (k) { case 0:f = i + j; break; case 1:f = g + h; break; case 2:f = g - h; break; case 3:f = i – j; break; } Variables f through k associated with $s0  $s5. Register $t2 contains 4. Register $t4 contains address of jump table in memory. MIPS Assembly code? Address of instruction f = i + j  label L0 Address of instruction f = g+ h  label L1 Address of instruction f = g - h  label L2 Address of instruction f = i - j  label L3 L0 L1 L2 L3 $t Jump table stored in memory 1024

Lecture 15: 10/24/2002CS170 Fall Case/Switch Statement 3/3 slt $t3, $s5, $zero# test if k < 0 bne $t3, $zero, Exit# if k < 0 go to Exit slt $t3,$s5,$t2# test if k < 4 beq $t3, $zero, Exit# if k >= 4 go to Exit add $t1,$s5,$s5# $t1  2 *k (Why?) add $t1,$t1,$t1# $t1  4 *k add $t1,$t1,$t4# $t1  address of JumpTable[k] lw $t0,0($t1)# $t0  JumpTable[k] jr $t0# jump to address found in register $t0 L0:add $s0, $s3, $s4# (k = 0) then f = i +j j Exit# break (go to Exit) L1:add $s0,$s1,$s2#(k = 1) then f = g+h j Exit# break (go to Exit) L2:sub $s0,$s1,$s2#(k=2) then f = g-h j Exit L3:sub $s0,$s3,$s4#(k=3) then f = i- j Exit:# End of switch statement

Lecture 15: 10/24/2002CS170 Fall What we know so far Fig. 3.9 page 131 instruction format for unconditional jump j (J-format) (more on target address in section 3.8) The jr instruction  (R-format) opcode = 0, funct = 8, rs is jump register The slt instruction  (R-format) Opcode = 0, funct = 42, rs, rd, rt The beq, bne instructions  (I-format) $zero always contains the value 0 The instruction beq $s1, $s2, 100 is an I-format instruction. The resulting machine code Op| rs | rt | address 4 | 17 | 18 | 25 Why the value in address field is 25 and not 100? Will discuss this when we cover section 3.8