Class Notes (835,600)
Canada (509,275)
CSC258H1 (46)


2 Pages
Unlock Document

Computer Science
Steve Engels

 MIPS Instructions cont.  Control flow in assembly o Shift instructions o Not all programs follow a linear set of instructions st  1 ndaracter: "s" = shift  Some operations require the code to branch to one section of  2 character: "l" or "r" = shift direction the code or another (if/else)  3 character: "a" or "l" = arthematic or logical  Some require the code to jump back and repeat a section of  shift left logical == shift left arthematic (not in use) code again (for/while) th  4 (optional) character: "v" = a variable number of bits, o For this, we have labels on the left-hand side that indicate the points specified by $s that the program flow might need to jump to Instruction Opcode/ Synatx Operation  References to these points in the assembly code are resolved at compile time to offset values for the program counter Function sll 000000 $d, $s, a $d = $t << a o Branch instructions sllv 000100 $d, $t, $s $d = $t << $s  Branch operations are key when implementing if statements and while loops sra 000011 $d, $t, a $d = $t >> a  The labels are memory locations, assigned to each lable at srav 000111 $d, $t, $s $d = $t >> $s compile time srl 000010 $d, $t, a $d = $t >>> a  Note: i is calculated as srlv 000110 $d, $t, $s $d = $t >>> $s (label – (current PC + 4)) >> 2  In branch i-type instruction last 16 bits is the difference btwn  Data movement instructions the branch-call location and the branch-to location o These instructions for operating on the HI and LO registers  beq = branch if equals Instruction Opcode/ Synatx Operation  bgtz = branch if greater than Function  blez = branch if lesser than or equals to mfhi 010000 $d $d = hi  bne = branch if not equals mflo 010010 $d $t = lo  Note: branch if lesser than DNE, instead: beq, bgtz & blez mthi 010001 $s hi = $s Instruction Opcode/Fun Synatx Operation mtlo 010011 $s lo = $s ction beq 000100 $s, $t, label if ($s == $t)  ALU instructions pc += i << 2 o Note that for ALU instructions, most are R-type instructions  The six-digit codes in the table are therefore the function codes 000111 $s, label if ($s > 0) pc += i << 2 (opcodes are 000000)  Exceptions are the I-type instructions (addi, andi, orri, etc.)z) 000110 $s, label if ($s <= 0) o Note all R-type instructions have an I-type equivalent pc += i << 2  RISC architecures dictate that an operation doesn’t need an bne 000101 $s, $t, label if ($s != $t) instruction if it can be performed through multiple existing pc += i << 2 operations  Ex. addi + div  divi o Jump instructions  j = “jump”, for calling subroutines  Store the immediate value into a register first than divide  similar to GOTO statements  Example program o A fibonacci sequence C code into assembly code  if an assembly program doesn’t have jump statements, 1. int fib(void) { the program will run from beginning to end sequentially 2. int n = 10;  jal = “jump and link”, for calling functions 3. int f1 = 1, f2 = -1; 4. while (n != 0) {  register $ra ($31) stores the address that’s used when 5. f1 = f1 + f2; returning from a subroutine 6. f2 = f1 – f2;  jalr = “jump and link to register” 7. n = n – 1;  jr = “jump to register”, jump to address contain in register $s 8. } 9. return f1;  usually for ending a subroutine by jumping to the return 10. } address stored in $ra
More Less

Related notes for CSC258H1

Log In


Join OneClass

Access over 10 million pages of study
documents for 1.3 million courses.

Sign up

Join to view


By registering, I agree to the Terms and Privacy Policies
Already have an account?
Just a few more details

So we can recommend you notes for your school.

Reset Password

Please enter below the email address you registered with and we will send you a link to reset your password.

Add your courses

Get notes from the top students in your class.