Lecture 6
- IDEA for switch
- Need to jump to right place in program or right label or right address
- The label or address is dependent on what value of k
- Need to jump to right place in program or right label or right address
- Unconditional Jump
- Based on value of register = address to jump to is in the register
- jr
- jr , jump register
- jr , jump register
- Modularity
- Why use subprograms?
- Easy to understand
- Better organization
- Reusable
- Reduce complex tasks to simpler sets of task
- Reliable, less errors
- Easy to understand
- All programs are implemented / run sequentially
- jal
- jump and link procedure
- jumps to a procedure address
- saves the return address in $ra
- jumps to a procedure address
- jr
- jump register
- jump based on what is in $ra
- jump based on what is in $ra
- $a0, $a1, $a2, $a3
- Arguments
- Caller calls the subprogram with arguments from $a*
- The callee places subprograms result in $v0 and $v1
- Arguments
- $ra
- Return address
- Return address
- $sp
- Stack pointer
- Stack pointer
The Stack
- Procedure has only a total of 6 memory locations for data $a1-$a4 & $v0-$v1
- A very specific kind of memory
- It's in main memory but
- Has a particular structure
- It is a subset of main memory and it's run in a particular way
- It has a top and a bottom but all we can do is push stuff on it and take stuff off the top of it
- It's in main memory but