Presentation is loading. Please wait.

Presentation is loading. Please wait.

Computer Architecture & Operations I

Similar presentations


Presentation on theme: "Computer Architecture & Operations I"— Presentation transcript:

1 Computer Architecture & Operations I
Instructor: Ryan Florin

2 Instructions for Making Decisions
High-level programming language C/C++: if … else … (conditional) goto (unconditional) for, while, until (loops) Assembly Languages MIPS: beq (branch if equal) bne (branch if not equal) j (unconditional jump)

3 Conditional Operations
The University of Adelaide, School of Computer Science 21 July 2018 Conditional Operations Branch to a labeled instruction if a condition is true Otherwise, continue sequentially beq rs, rt, L1 if (rs == rt) branch to instruction labeled L1; bne rs, rt, L1 if (rs != rt) branch to instruction labeled L1; j L1 unconditional jump to instruction labeled L1 Chapter 2 — Instructions: Language of the Computer

4 Compiling If Statements
The University of Adelaide, School of Computer Science 21 July 2018 Compiling If Statements C code: if (i==j) f = g+h; else f = g-h; Chapter 2 — Instructions: Language of the Computer

5 Compiling If Statements
The University of Adelaide, School of Computer Science 21 July 2018 Compiling If Statements C code: if (i==j) f = g+h; else f = g-h; f ($s0), g ($s1), h($s2), i($s3), j($s4) Compiled MIPS code: bne $s3, $s4, Else add $s0, $s1, $s j Exit Else: sub $s0, $s1, $s2 Exit: … Assembler calculates addresses Chapter 2 — Instructions: Language of the Computer

6 Compiling Loop Statements
The University of Adelaide, School of Computer Science 21 July 2018 Compiling Loop Statements C code: while (save[i] == k) i = i+1; i in $s3, k in $s5, address of save in $s6 Flowchart? Chapter 2 — Instructions: Language of the Computer

7 Compiling Loop Statements
The University of Adelaide, School of Computer Science 21 July 2018 Compiling Loop Statements C code: while (save[i] == k) i = i+1; i in $s3, k in $s5, address of save in $s6 Compiled MIPS code: Loop: sll $t1, $s3, add $t1, $t1, $s lw $t0, 0($t1) bne $t0, $s5, Exit addi $s3, $s3, j Loop Exit: … Chapter 2 — Instructions: Language of the Computer

8 The University of Adelaide, School of Computer Science
21 July 2018 More Examples C code: for (i=1; i<=5; i++) count++; How to initialize a variable? addi $t0, $zero, 0 # $t0 = 0 addi $t1, $zero, 10 # $t1 = 10 Chapter 2 — Instructions: Language of the Computer

9 The University of Adelaide, School of Computer Science
21 July 2018 More Examples C code: for (i=1; i<=5; i++) sum += A[i]; What assumptions need to be made? What is the address of array A? Should sum be initialized? Chapter 2 — Instructions: Language of the Computer

10 Summary Conditional Instructions Converting a C Program to MIPS beq
bne j Converting a C Program to MIPS


Download ppt "Computer Architecture & Operations I"

Similar presentations


Ads by Google