Lecture Notes: MIPS Case Study (Control Flow Instruction) PDF

Document Details

CuteWatermelonTourmaline

Uploaded by CuteWatermelonTourmaline

Kazi Nazrul University

Dohyung Kim

Tags

MIPS computer architecture control flow assembly language

Summary

These lecture notes cover MIPS case study (control flow instruction). They detail conditional operations, compiling if statements, compiling loop statements, and more conditional operations.

Full Transcript

ISA : MIPS Case Study (Control Flow Instruction) 471029: Introduction to Computer Architecture 11th Lecture Disclaimer: Slides are mainly based on COD 5th textbook and also developed in part by Profs. Dohyung Kim @ KNU and Computer architecture course @ KAIST and SKKU...

ISA : MIPS Case Study (Control Flow Instruction) 471029: Introduction to Computer Architecture 11th Lecture Disclaimer: Slides are mainly based on COD 5th textbook and also developed in part by Profs. Dohyung Kim @ KNU and Computer architecture course @ KAIST and SKKU 1 MIPS Control Flow Instructions  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; 2 MIPS Control Flow Instructions (cont’d)  Compiling If statements  C code: if (i == j) f = g + h; else f = g – h;  Assume f, g, h, I, and j in $s0, $s1, $s2, $s3, and $s4, respectively  Compiled MIPS code: bne $s3, $s4, Else Assembler calculates addresses add $s0, $s1, $s2 j Exit Else: sub $s0, $s1, $s2 Exit:... 3 MIPS Control Flow Instructions (cont’d)  Compiling loop statements  C code: while (save[i] == k) i += 1; i in $s3, k in $s5, address of save in $s6  Suppose the data type of the save array is word  Compiled MIPS code: Loop: sll $t1, $s3, 2 add $t1, $t1, $s6 lw $t0, 0($t1) bne $t0, $s5, Exit addi $s3, $s3, 1 j Loop Exit:... 4 MIPS Control Flow Instructions (cont’d)  More conditional operations  Set result to 1 if a condition is true (slt: set less than)  Otherwise, set to 0  if (rs

Use Quizgecko on...
Browser
Browser