February 15 Your assignment: ASK QUESTIONS

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

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:
The University of Adelaide, School of Computer Science
Lecture 20: 11/12/2002CS170 Fall CS170 Computer Organization and Architecture I Ayman Abdel-Hamid Department of Computer Science Old Dominion University.
Lecture 9: MIPS Instruction Set
Exploring Security Vulnerabilities by Exploiting Buffer Overflow using the MIPS ISA Andrew T. Phillips Jack S. E. Tan Department of Computer Science University.
1 Procedure Calls, Linking & Launching Applications Lecture 15 Digital Design and Computer Architecture Harris & Harris Morgan Kaufmann / Elsevier, 2007.
Solution 2nd Exam.
1 Lecture 4: Procedure Calls Today’s topics:  Procedure calls  Large constants  The compilation process Reminder: Assignment 1 is due on Thursday.
MIPS Calling Convention Chapter 2.7 Appendix A.6.
Lecture 6: MIPS Instruction Set Today’s topic –Control instructions –Procedure call/return 1.
Assembly Code Example Selection Sort.
The University of Adelaide, School of Computer Science
Computer Organization CS224
Computer Architecture CSCE 350
1 Nested Procedures Procedures that don't call others are called leaf procedures, procedures that call others are called nested procedures. Problems may.
CPS3340 COMPUTER ARCHITECTURE Fall Semester, /17/2013 Lecture 12: Procedures Instructor: Ashraf Yaseen DEPARTMENT OF MATH & COMPUTER SCIENCE CENTRAL.
CS1104 – Computer Organization PART 2: Computer Architecture Lecture 4 Assembly Language Programming 2.
The University of Adelaide, School of Computer Science
Apr. 12, 2000Systems Architecture I1 Systems Architecture I (CS ) Lecture 6: Branching and Procedures in MIPS* Jeremy R. Johnson Wed. Apr. 12, 2000.
Lecture 8: MIPS Instruction Set
Computer Organization CS345 David Monismith Based upon notes by Dr. Bill Siever and notes from the Patternson and Hennessy Text.
CS 61C L11 Introduction to MIPS: Procedures I (1) Garcia, Spring 2004 © UCB Lecturer PSOE Dan Garcia inst.eecs.berkeley.edu/~cs61c.
L5 – Addressing Modes 1 Comp 411 – Spring /29/08 Operands and Addressing Modes Where is the data? Addresses as data Names and Values Indirection.
ENEE350 Spring07 1 Ankur Srivastava University of Maryland, College Park Adapted from Computer Organization and Design, Patterson & Hennessy, © 2005.”
Computer Structure - The Instruction Set (2) Goal: Implement Functions in Assembly  When executing a procedure (function in C) the program must follow.
Lecture 5: Procedures. Function call book-keeping in C main() { int i,j,k,m;... i = mult(j,k);... m = mult(i,i);... } /* really dumb mult function */
Inst.eecs.berkeley.edu/~cs61c UCB CS61C : Machine Structures Lecture 11 – Introduction to MIPS Procedures I Internet2, a non-profit advanced.
Lecture 7: MIPS Instruction Set Today’s topic –Procedure call/return –Large constants Reminders –Homework #2 posted, due 9/17/
Adapted from Computer Organization and Design, Patterson & Hennessy, UCB ECE232: Hardware Organization and Design Part 7: MIPS Instructions III
Character Data and 32-bit Constants (Lecture #20) ECE 445 – Computer Organization The slides included herein were taken from the materials accompanying.
Lecture 19: 11/7/2002CS170 Fall CS170 Computer Organization and Architecture I Ayman Abdel-Hamid Department of Computer Science Old Dominion University.
MIPS Calling Convention. Procedure Calls Procedure must work the same from any call Procedure uses regs that main was using We need a convention to –pass.
1 Branches and Procedure Calls Lecture 14 Digital Design and Computer Architecture Harris & Harris Morgan Kaufmann / Elsevier, 2007.
IT 251 Computer Organization and Architecture More MIPS Control Instructions Chia-Chi Teng.
Procedure (Method) Calls Ellen Spertus MCS 111 September 25, 2003.
MIPS Machine Assembly Language Opening Discussion zWhat did we talk about last class? zHave you seen anything interesting in the news? zDo you.
Lecture 4: MIPS Instruction Set
Computer Architecture CSE 3322 Lecture 4 crystal.uta.edu/~jpatters/cse3322 Assignments due 9/15: 3.7, 3.9, 3.11.
Computer Architecture CSE 3322 Lecture 3 Assignment: 2.4.1, 2.4.4, 2.6.1, , Due 2/3/09 Read 2.8.
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.
1 CS232 Exam 1 Solutions February 20, 2004 Name:  This exam has 5 pages, including this cover.  There are three questions, worth a total of 100 points.
CMPUT Computer Organization and Architecture I1 CMPUT229 - Fall 2003 Topic4: Procedures José Nelson Amaral.
DR. SIMING LIU SPRING 2016 COMPUTER SCIENCE AND ENGINEERING UNIVERSITY OF NEVADA, RENO Session 12 Procedure Calling.
CPEG323 Homework Review I Long Chen October, 17 th, 2005.
MIPS Assembly Language Programming
Function Calls in MIPS To call a function: jal func
Lecture 5: Procedure Calls
Computer Architecture & Operations I
Prof. Hsien-Hsin Sean Lee
Lecture 4: MIPS Instruction Set
Decision Making.
RISC Concepts, MIPS ISA Logic Design Tutorial 8.
Procedures (Functions)
Procedures (Functions)
CSCI206 - Computer Organization & Programming
Addressing in Jumps jump j Label go to Label op address 2 address
October 1 Programming Questions?
Lecture 5: Procedure Calls
September 26 More programming Questions? 1/16/2019 Comp 120 Fall 2001.
Lecture 6: Assembly Programs
MIPS e pipelining Tecniche di base.
Compilers Jakub Yaghob
Introduction Lab1 A crash course in assembler programming
Conditional Branching (beq)
Presentation transcript:

February 15 Your assignment: ASK QUESTIONS Send email to “gb” describing as carefully as you can what you don’t understand... 12/28/2018 Comp 120 Spring 2001

Grade Distribution Mean = 82 points Median = 87 points 12/28/2018 Comp 120 Spring 2001

Code Pattern for IF if(COND_EXPR) { STMTS1 } else { STMTS2 } CONDCODE(COND_EXPR, Lfalse1, Ltrue2) Ltrue2: CODE(STMTS1) j Lnext3 Lfalse1: CODE(STMTS2) Lnext3: 12/28/2018 Comp 120 Spring 2001

Code Pattern for Conditional Expr Comparisons: == != < > <= >= Conjunctions: && || Parenthesis: ( ) == get left in reg A get right in reg B bne $A,$B, Lfalse A == B A B get left in reg A get right in reg B slt $t0,A,B beq t0,$zero,Lfalse < A < B A B 12/28/2018 Comp 120 Spring 2001

CP for && and || && CONDCODE(L, Lfalse, Lnew1) Lnew1: CONDCODE(R, Lfalse, Ltrue) L && R L R || CONDCODE(L, Lnew1, Ltrue) Lnew1: CONDCODE(R, Lfalse, Ltrue) L || R L R 12/28/2018 Comp 120 Spring 2001

Example Conditional if(A != B && A > C) { ST } else { SE } A=s1, B=s2, C=s3 beq $s1,$s2,Lfalse23 Lnew24: slt $t0, $s3, $s1 beq $t0, $zero, Lfalse23 Ltrue25: CODE(ST) j Lnext27 Lfalse23: CODE(SE) Lnext27: && > != A C A B 12/28/2018 Comp 120 Spring 2001

While while(COND_EXPR) { STMTS; } Lwhile44: CONDCODE(COND_EXPR, Lfalse45, Ltrue46) Ltrue46: CODE(STMTS) j Lwhile44 Lfalse45: 12/28/2018 Comp 120 Spring 2001

FOR for(INIT; COND_EXPR; UPDATE) { STMTS } CODE(INIT) Lfor17: CONDCODE(COND_EXPR, Lnext18, Ltrue19) Ltrue19: CODE(STMTS) CODE(UPDATE) j Lfor17 Lnext18: 12/28/2018 Comp 120 Spring 2001

Functions foo: save any of $ra or $s0-s7 that are overwritten int foo(int a, int b, int c, int d) { STMTS; return EXPR; } we know a=$a0, b=$a1, c=$a2, d=$a3 assign other simple variables to registers as possible foo: save any of $ra or $s0-s7 that are overwritten CODE(STMTS) CODE(EXPR) leave result in $v0 restore $ra, and $s0-s7 if we saved them earlier jr $ra 12/28/2018 Comp 120 Spring 2001

cfind int cfind(char str[], char c) { for(int i=0; str[i] != 0; i++) if(s[i] == c) return i; return -1; } a0 == address of str a1 == value of character c v0 == i no need to save anything 12/28/2018 Comp 120 Spring 2001

Expand function template cfind: # no need to save anything CODE(‘for ...’) CODE(‘return -1’) jr $ra 12/28/2018 Comp 120 Spring 2001

Expand for cfind: CODE(‘i=0’) Lfor1: CONDCODE(‘s[i] != 0, Lnext2, Ltrue3) Ltrue3: CODE(‘if ...’) CODE(‘i++’) j Lfor1 Lnext2: CODE(‘return -1’) jr $ra 12/28/2018 Comp 120 Spring 2001

Expand for INIT cfind: move $v0, $zero Lfor1: CONDCODE(‘s[i] != 0 && s[i] != c’, Lnext2, Ltrue3) Ltrue3: CODE(‘if ...’) CODE(‘i++’) j Lfor1 Lnext2: CODE(‘return -1’) jr $ra 12/28/2018 Comp 120 Spring 2001

Expand for COND_EXPR cfind: # no need to save anything move $v0, $zero Lfor1: add $t0, $a0, $v0 # address of s[i] lb $t1, 0($t0) # t1 = s[i] beq $t1, $zero, Lnext2 Ltrue3: CODE(‘if ...’) CODE(‘i++’) j Lfor1 Lnext2: CODE(‘return -1’) jr $ra 12/28/2018 Comp 120 Spring 2001

Expand if CONDCODE(‘s[i] == c’, Lfalse4, Ltrue5) Ltrue5: cfind: move $v0, $zero Lfor1: add $t0, $a0, $v0 # address of s[i] lb $t1, 0($t0) # t1 = s[i] beq $t1, $zero, Lnext2 Ltrue3: CONDCODE(‘s[i] == c’, Lfalse4, Ltrue5) Ltrue5: CODE(‘return i’); Lfalse4: CODE(‘i++’) j Lfor1 Lnext2: CODE(‘return -1’) jr $ra 12/28/2018 Comp 120 Spring 2001

Expand if COND_EXPR bne $t1, $a1, Lfalse4 cfind: move $v0, $zero Lfor1: add $t0, $a0, $v0 # address of s[i] lb $t1, 0($t0) # t1 = s[i] beq $t1, $zero, Lnext2 Ltrue3: bne $t1, $a1, Lfalse4 Ltrue5: CODE(‘return i’); Lfalse4: CODE(‘i++’) j Lfor1 Lnext2: CODE(‘return -1’) jr $ra 12/28/2018 Comp 120 Spring 2001

Expand return jr $ra # return i already in v0 cfind: move $v0, $zero Lfor1: add $t0, $a0, $v0 # address of s[i] lb $t1, 0($t0) # t1 = s[i] beq $t1, $zero, Lnext2 Ltrue3: bne $t1, $a1, Lfalse4 Ltrue5: jr $ra # return i already in v0 Lfalse4: CODE(‘i++’) j Lfor1 Lnext2: CODE(‘return -1’) jr $ra 12/28/2018 Comp 120 Spring 2001

Expand i++ addi $v0, $v0, 1 # i = i+1; cfind: move $v0, $zero Lfor1: add $t0, $a0, $v0 # address of s[i] lb $t1, 0($t0) # t1 = s[i] beq $t1, $zero, Lnext2 Ltrue3: bne $t1, $a1, Lfalse4 Ltrue5: jr $ra # return i already in v0 Lfalse4: addi $v0, $v0, 1 # i = i+1; j Lfor1 Lnext2: CODE(‘return -1’) jr $ra 12/28/2018 Comp 120 Spring 2001

Expand return -1 subi $v0, $zero, 1 # return value = -1 cfind: move $v0, $zero Lfor1: add $t0, $a0, $v0 # address of s[i] lb $t1, 0($t0) # t1 = s[i] beq $t1, $zero, Lnext2 Ltrue3: bne $t1, $a1, Lfalse4 Ltrue5: jr $ra # return i already in v0 Lfalse4: addi $v0, $v0, 1 # i = i+1; j Lfor1 Lnext2: subi $v0, $zero, 1 # return value = -1 jr $ra 12/28/2018 Comp 120 Spring 2001

Remove unused labels cfind: move $v0, $zero # i = 0 Lfor1: add $t0, $a0, $v0 # address of s[i] lb $t1, 0($t0) # t1 = s[i] beq $t1, $zero, Lnext2 # if s[i] == 0 bne $t1, $a1, Lfalse4 # if s[i] == c jr $ra # return i already in v0 Lfalse4: addi $v0, $v0, 1 # i = i+1; j Lfor1 Lnext2: subu $v0, $zero, 1 # return -1 jr $ra 12/28/2018 Comp 120 Spring 2001