Presentation is loading. Please wait.

Presentation is loading. Please wait.

1. 2 6.1 Simple Procedure Calls jal: performs the control transfer (unconditional jump) to the starting address of procedure, while also saving the return.

Similar presentations


Presentation on theme: "1. 2 6.1 Simple Procedure Calls jal: performs the control transfer (unconditional jump) to the starting address of procedure, while also saving the return."— Presentation transcript:

1 1

2 2 6.1 Simple Procedure Calls jal: performs the control transfer (unconditional jump) to the starting address of procedure, while also saving the return address in $ra.

3 3 procedure call 1.Put argument in places known to the procedue (register $a0 - $a3). 2.Transfer control to the procedure, saving the return address (jal). 3.Acquire storage space, if required, for use by the procedure. 4.Perform the desired task. 5.Put results in place known to the calling program (register $v0 - $v1) 6.Return control to calling point (jr) Applicable to procedure call that invokes maximal 4 words of arguments and 2 words of results.

4 4 Procedure convention A procedure can use registers $v0 - $v1 and $t0 - $t9 freely without having to save their original contents. Division of responsibility between the calling and called program –Caller-saved registers: $v0 - $v1, $t0 - $t9 A calling program should not expect any values placed in these 12 registers to remain unchanged. –Callee-saved registers: $a0 - $a3, $s0 - $s7, $gp, $sp, $fp, $ra A procedure (callee program) that modifies any of these must restore them to their original values before terminating.

5 5 Figure 6.2 Example of nested procedure calls. Nested Procedure call 1. Procedure abc puts arguments in $a0 - $a3 and save any useful data in $v0 - $v1, $t0 - $t9 2. After return from xyz, procedure abc may transfer to

6 6 Figure 6.3 Overview of the memory address space in MiniMIPS. 6.2 Using Stack for Data Storage Conventions for using memory address space in MiniMIPS: Second half: memory-mapped I/O First half: First 1M words: system use Next 63M words: text of the program being executed Beginning at 0x10000000: program’s data segment Beginning 0x7ffffffc growing backward: stack

7 7 Figure 6.4 Effects of push and pop operations on a stack. Push: addi $sp, $sp,-4 sw $t4, 0($sp) Pop: lw $t5, 0($sp) addi $sp, $sp, 4

8 8 Figure 6.5 Use of the stack by a procedure. 6.3 Parameters and Results 1.How can we pass more than four input parameters to a procedure or receive more than two results? 2.Where does a procedure save its own parameters and intermediate results when calling another procedure (nested calls)?

9 9 6.4 Data Types MiniMIPS has the following data types:

10 10 Singed integer: 2’s-complement

11 11 Table 6.1 ASCII (American Standard Code for Information Interchange) 1, 2

12 12 Figure 6.6 Load and store instructions for byte-size data elements. Load byte, load byte unsigned, store byte lb$t0,8($s3)# load rt with byte mem[8+$s3]; # signed-extended to fill the register; lbu$t0,8($s3) # load rt with byte mem[8+$s3]; # zero-extended to fill the register; sb$t0,8($s3)# store byte 0 of rt to mem[8+$s3];

13 13 Figure 6.7 A 32-bit word has no inherent meaning and can be interpreted in a number of equally valid ways in the absence of other cues (e.g., context) for the intended meaning. A bit string, stored in memory or in a register, has no inherent meaning. It can mean different things depending on how it is interpreted.

14 14 Figure 6.8 Using the indexing method and the pointer updating method to step through the elements of an array. 6.5 Arrays and Pointers 1.Index: use a register that holds the index i and increment the register in each step to effect moving from element i of the list to element i+1. 2.Pointer: use a register that points to the list element being examined and update it in each step to point to the next element.

15 15 Figure 6.9 One iteration of selection sort. Example 6.4 Selection sort using a max-finding procedure

16 16 Figure 6.10 The multiply (mult) and divide (div) instructions of MiniMIPS. 6.6 Additional Instructions mult$s0, $s1# set Hi, Lo to ($s0)×($s0) div$s0, $s1# set Hi to ($s0) mod ($s0) # set Lo to ($s0) / ($s0)

17 17 Figure 6.11 MiniMIPS instructions for copying the contents of Hi and Lo registers into general registers. mfhi$t0# set $t0 to (Hi) mflo$t0, $s1# set $t0 to (Lo)

18 18 Figure 6.12 The four logical shift instructions of MiniMIPS. sll $t0, $s1, 2# $t0 = ($s1) left-shifted by 2 bits srl $t0, $s1, 2# $t0 = ($s1) right-shifted by 2 bits sllv $t0, $s1, $s0 # $t0 = ($s1) left-shifted by ($s0) srlv $t0, $s1, $s0 # $t0 = ($s1) right-shifted by ($s0) Shift instructions

19 19 Table 6.2 The 40 MiniMIPS instructions covered in Chapters 5–7.*

20 20


Download ppt "1. 2 6.1 Simple Procedure Calls jal: performs the control transfer (unconditional jump) to the starting address of procedure, while also saving the return."

Similar presentations


Ads by Google