1 / 14

Lecture 3a: Supplemental Notes for Chapter 3

Lecture 3a: Supplemental Notes for Chapter 3. CS 447 Jason Bakos. Review of Branch Instructions. b <label> Unconditional branch Pseudoinstruction beq <r1>, <r2>, <label> Branch if equal bgez <r1>, label Branch if greater than or equal 0 bgezal <r1>, label

honey
Télécharger la présentation

Lecture 3a: Supplemental Notes for Chapter 3

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Lecture 3a:Supplemental Notes for Chapter 3 CS 447 Jason Bakos

  2. Review of Branch Instructions • b <label> • Unconditional branch • Pseudoinstruction • beq <r1>, <r2>, <label> • Branch if equal • bgez <r1>, label • Branch if greater than or equal 0 • bgezal <r1>, label • Branch if greater than or equal 0 and link

  3. Review of Branch Instructions • bgtz <r1>, <label> • Branch if greater than zero • blez <r1>, <label> • Branch if less than or equal 0 • bltzal <r1>, label • Branch if less than 0 and link • bltz <r1>, label • Branch if less than 0

  4. Review of Branch Instructions • bne <r1>, <r2>, <label> • Branch if not equal • beqz <r1>, <label> • Branch if equal 0 • Pseudoinstruction • bge <r1>, <r2>, label • Branch if greater than or equal • Pseudoinstruction • bgeu <r1>, <r2>, label • Branch if greater than or equal unsigned • Pseudoinstruction

  5. Review of Branch Instructions • bgt <r1>, <r2>, <label> • Branch if greater than • Pseudoinstruction • bgtu <r1>, <r2>, <label> • Branch if greater than unsigned • Pseudoinstruction • blte <r1>, <r2>, label • Branch if less than or equal • Pseudoinstruction • blteu <r1>, <r2>, label • Branch if less than or equal unsigned • Pseudoinstruction

  6. Review of Branch Instructions • blt <r1>, <r2>, <label> • Branch if less than • Pseudoinstruction • bltu <r1>, <r2>, <label> • Branch if less than unsigned • Pseudoinstruction • bnez <r1>, label • Branch if not equal zero • Pseudoinstruction

  7. Notes on Branch Instructions • Offset field represents offset in instruction words (bytes/4) • starting from the next instruction • next instruction would be offset 0 • can be negative (as can offset in load/store) • Branch pseudoinstructions assemble into the equivalent comparison instruction followed by a bgtz • And-link instructions load the address of the next instruction into $31 ($ra) if the branch is taken

  8. Notes on Comparison Instructions • There is a comparison instruction for every conditional branch instruction • They work just like the conditional branch instructions, but instead, if the comparison is evaluated true, the destination register is set to the value 1, and 0 otherwise • slt and sltu follow the R-type format • Comparison instructions aren’t really useful, except for slti and sltiu (unsigned), which are immediate comparison instructions • They follow the I-type format • Immediates are sign-extended!!! • Use these, followed by a bltz to compare a register and immediate and branch based on result • seq, sge, sgeu, sgt, sgtu, sle, sleu, sne are pseudoinstructions

  9. Jump Instructions • j <label> • Unconditional jump (used when b instruction is used) • jal <label> • Jump and link (used for procedure call) • jalr <r1>, <r2> • Jump and link register (same as above, but links into r2) • jr <r1> • Jump register (used to return from a procedure)

  10. Notes on Pseudodirect Addressing • j and jal use pseudodirect addressing • To compute the effective branch target address, the MS 6 bits of the PC are added to the address in the instruction

  11. A More Robust Procedure Calling Convention • We’ll use $a0-$a3 to pass parameters to a procedure • We’ll use $v0 and $v1 for procedure returns • We want to save $s0-$s7 across procedure calls • We want to be able to have multiple levels of procedure calls and we want to be able to call procedures recursively • This means we need to somehow save arguments, state registers, and return addresses for each procedure call

  12. A More Robust Procedure Calling Convention • Solution: Use a stack! When each procedure is called, push arguments, return address, and saved registers onto a stack NOTE: The stack frames can be FIXED size using this convention To create a better procedure calling convention, we would also allow for variable numbers of arguments and local variable storage on the stack, but we will make this simpler

  13. A More Robust Procedure Calling Convention • For calling procedures: • Caller must move arguments into argument registers and jal to procedure • Callee must save arguments, return address, and machine state (registers) on stack, and decrement $sp by 13*4=52 • $sp always points to next stack position • stack grows down • Upon completion, callee must set the return value register(s), restore the $s registers, restore $ra, increment $sp by 52, and jump back to the caller • $sp is already initialized when you start your program

  14. More Notes • You can use whatever procedure calling convention you want in your programs, but I recommend using this one • Your programs’ procedures will share a static memory space (no scope) • In order to implement scope, we’d have to allocate local space on the stack

More Related