Presentation is loading. Please wait.

Presentation is loading. Please wait.

CMPUT 229 - Computer Organization and Architecture I1 CMPUT229 - Fall 2003 Topic4: Procedures José Nelson Amaral.

Similar presentations


Presentation on theme: "CMPUT 229 - Computer Organization and Architecture I1 CMPUT229 - Fall 2003 Topic4: Procedures José Nelson Amaral."— Presentation transcript:

1 CMPUT 229 - Computer Organization and Architecture I1 CMPUT229 - Fall 2003 Topic4: Procedures José Nelson Amaral

2 CMPUT 229 - Computer Organization and Architecture I2 Reading Assignment zChapter 3 of Hennessy and Patterson: ySections 3.6 to 3.8. yPages A-26 to A-29 of Appendix A

3 CMPUT 229 - Computer Organization and Architecture I3 Calling Itself int fact ( int n ) { if (n < 1) return(1); else return(n * fact(n-1)); }

4 CMPUT 229 - Computer Organization and Architecture I4 Procedure Call 1Place parameters in a place where the procedure can access them. 2Transfer control to procedure. 3 Acquire the storage resources needed for the procedure. 4Perform the procedure’s task. 5Place the result value in a place where the calling program can access it. 6Return control to the point of origin. Pat.-Hen. pp. 132

5 CMPUT 229 - Computer Organization and Architecture I5 Registers Used for Procedure Calls $a0-$a3: four argument registers in which to pass parameters $v0-$v1: two value registers in which to return values $ra: one return address register to return to the point of origin Pat.-Hen. pp. 132

6 CMPUT 229 - Computer Organization and Architecture I6 Jumping and Returning The jump-and-link instruction (jal) is used to jump to a procedure and link the returning address. jalProcedureAddress stores the value of PC+4 in the register $ra and transfer the execution to the ProcedureAddress When the procedure completes execution, it will jump back to the calling point using: jr$ra Pat.-Hen. pp. 133

7 CMPUT 229 - Computer Organization and Architecture I7 A Procedure that Doesn’t Call Another Procedure int leaf_example ( int g, int h, int i, int j) { int f; f = (g + h) - (i + j); return f; } Parameter Passing Convention g  $a0 h  $a1 i  $a2 j  $a3 Assumption f  $s0 MIPS assembly: sub $sp, $sp, 12 # Make room in stack for 3 more items sw $t1, 8($sp)# push $t1 into stack sw $t0, 4($sp)# push $t0 into stack sw $s0, 0($sp)# push $s0 into stack add $t0, $a0, $a1# $t0  g + h add $t1, $a2, $a3# $t1  i + j sub $s0, $t0, $t1# f  $t0 - $t1 add $v0, $s0, $zero# $v0  $s0 lw $s0, 0($sp)# restore $s0 lw $t0, 4($sp)# restore $t0 lw $t1, 8($sp)# restore $t1 add $sp, $sp, 12# adjust stack pointer Pat.-Hen. pp. 134-135

8 CMPUT 229 - Computer Organization and Architecture I8 Example of lw execution cont($t0) cont($t1) $t0 $t1 g h i $a0 $a1 $a2 j $a3 cont($s0) $s0 $sp MIPS assembly: sub $sp, $sp, 12 # Make room in stack for 3 more items sw $t1, 8($sp)# push $t1 into stack sw $t0, 4($sp)# push $t0 into stack sw $s0, 0($sp)# push $s0 into stack add $t0, $a0, $a1# $t0  g + h add $t1, $a2, $a3# $t1  i + j sub $s0, $t0, $t1# f  $t0 - $t1 add $v0, $s0, $zero# $v0  $s0 lw $s0, 0($sp)# restore $s0 lw $t0, 4($sp)# restore $t0 lw $t1, 8($sp)# restore $t1 add $sp, $sp, 12# adjust stack pointer Memory  High Address  Low Address $v0 Pat.-Hen. pp. 134-135 int leaf_example ( int g, int h, int i, int j) { int f; f = (g + h) - (i + j); return f; } Processor

9 CMPUT 229 - Computer Organization and Architecture I9 Example of lw execution cont($t0) cont($t1) $t0 $t1 g h i $a0 $a1 $a2 j $a3 cont($s0) $s0 MIPS assembly: sub $sp, $sp, 12 # Make room in stack for 3 more items sw $t1, 8($sp)# push $t1 into stack sw $t0, 4($sp)# push $t0 into stack sw $s0, 0($sp)# push $s0 into stack add $t0, $a0, $sa1# $t0  g + h add $t1, $a2, $a3# $t1  i + j sub $s0, $t0, $t1# f  $t0 - $t1 add $v0, $s0, $zero# $v0  $s0 lw $s0, 0($sp)# restore $s0 lw $t0, 4($sp)# restore $t0 lw $t1, 8($sp)# restore $t1 add $sp, $sp, 12# adjust stack pointer Memory $sp  High Address  Low Address $v0 Pat.-Hen. pp. 134-135 int leaf_example ( int g, int h, int i, int j) { int f; f = (g + h) - (i + j); return f; } Processor

10 CMPUT 229 - Computer Organization and Architecture I10 Example of lw execution cont($t1) cont($t0) cont($t1) $t0 $t1 g h i $a0 $a1 $a2 j $a3 cont($s0) $s0 MIPS assembly: sub $sp, $sp, 12 # Make room in stack for 3 more items sw $t1, 8($sp)# push $t1 into stack sw $t0, 4($sp)# push $t0 into stack sw $s0, 0($sp)# push $s0 into stack add $t0, $a0, $a1# $t0  g + h add $t1, $a2, $a3# $t1  i + j sub $s0, $t0, $t1# f  $t0 - $t1 add $v0, $s0, $zero# $v0  $s0 lw $s0, 0($sp)# restore $s0 lw $t0, 4($sp)# restore $t0 lw $t1, 8($sp)# restore $t1 add $sp, $sp, 12# adjust stack pointer Memory $sp  High Address  Low Address $v0 Pat.-Hen. pp. 134-135 int leaf_example ( int g, int h, int i, int j) { int f; f = (g + h) - (i + j); return f; } Processor

11 CMPUT 229 - Computer Organization and Architecture I11 Example of lw execution cont($t1) cont($t0) cont($t1) $t0 $t1 g h i $a0 $a1 $a2 j $a3 cont($s0) $s0 MIPS assembly: sub $sp, $sp, 12 # Make room in stack for 3 more items sw $t1, 8($sp)# push $t1 into stack sw $t0, 4($sp)# push $t0 into stack sw $s0, 0($sp)# push $s0 into stack add $t0, $a0, $a1# $t0  g + h add $t1, $a2, $a3# $t1  i + j sub $s0, $t0, $t1# f  $t0 - $t1 add $v0, $s0, $zero# $v0  $s0 lw $s0, 0($sp)# restore $s0 lw $t0, 4($sp)# restore $t0 lw $t1, 8($sp)# restore $t1 add $sp, $sp, 12# adjust stack pointer Memory $sp  High Address  Low Address $v0 Pat.-Hen. pp. 134-135 int leaf_example ( int g, int h, int i, int j) { int f; f = (g + h) - (i + j); return f; } Processor

12 CMPUT 229 - Computer Organization and Architecture I12 Example of lw execution cont($t1) cont($t0) cont($s0) cont($t0) cont($t1) $t0 $t1 g h i $a0 $a1 $a2 j $a3 cont($s0) $s0 MIPS assembly: sub $sp, $sp, 12 # Make room in stack for 3 more items sw $t1, 8($sp)# push $t1 into stack sw $t0, 4($sp)# push $t0 into stack sw $s0, 0($sp)# push $s0 into stack add $t0, $a0, $a1# $t0  g + h add $t1, $a2, $a3# $t1  i + j sub $s0, $t0, $t1# f  $t0 - $t1 add $v0, $s0, $zero# $v0  $s0 lw $s0, 0($sp)# restore $s0 lw $t0, 4($sp)# restore $t0 lw $t1, 8($sp)# restore $t1 add $sp, $sp, 12# adjust stack pointer Memory $sp  High Address  Low Address $v0 Pat.-Hen. pp. 134-135 int leaf_example ( int g, int h, int i, int j) { int f; f = (g + h) - (i + j); return f; } Processor

13 CMPUT 229 - Computer Organization and Architecture I13 Example of lw execution cont($t1) cont($t0) cont($s0) g+h cont($t1) $t0 $t1 g h i $a0 $a1 $a2 j $a3 cont($s0) $s0 MIPS assembly: sub $sp, $sp, 12 # Make room in stack for 3 more items sw $t1, 8($sp)# push $t1 into stack sw $t0, 4($sp)# push $t0 into stack sw $s0, 0($sp)# push $s0 into stack add $t0, $a0, $a1# $t0  g + h add $t1, $a2, $a3# $t1  i + j sub $s0, $t0, $t1# f  $t0 - $t1 add $v0, $s0, $zero# $v0  $s0 lw $s0, 0($sp)# restore $s0 lw $t0, 4($sp)# restore $t0 lw $t1, 8($sp)# restore $t1 add $sp, $sp, 12# adjust stack pointer Memory $sp  High Address  Low Address $v0 Pat.-Hen. pp. 134-135 int leaf_example ( int g, int h, int i, int j) { int f; f = (g + h) - (i + j); return f; } Processor

14 CMPUT 229 - Computer Organization and Architecture I14 Example of lw execution cont($t1) cont($t0) cont($s0) g+h i+j $t0 $t1 g h i $a0 $a1 $a2 j $a3 cont($s0) $s0 MIPS assembly: sub $sp, $sp, 12 # Make room in stack for 3 more items sw $t1, 8($sp)# push $t1 into stack sw $t0, 4($sp)# push $t0 into stack sw $s0, 0($sp)# push $s0 into stack add $t0, $a0, $a1# $t0  g + h add $t1, $a2, $a3# $t1  i + j sub $s0, $t0, $t1# f  $t0 - $t1 add $v0, $s0, $zero# $v0  $s0 lw $s0, 0($sp)# restore $s0 lw $t0, 4($sp)# restore $t0 lw $t1, 8($sp)# restore $t1 add $sp, $sp, 12# adjust stack pointer Memory $sp  High Address  Low Address $v0 Pat.-Hen. pp. 134-135 int leaf_example ( int g, int h, int i, int j) { int f; f = (g + h) - (i + j); return f; } Processor

15 CMPUT 229 - Computer Organization and Architecture I15 Example of lw execution cont($t1) cont($t0) cont($s0) g+h i+j $t0 $t1 g h i $a0 $a1 $a2 j $a3 $t0-$t1 $s0 MIPS assembly: sub $sp, $sp, 12 # Make room in stack for 3 more items sw $t1, 8($sp)# push $t1 into stack sw $t0, 4($sp)# push $t0 into stack sw $s0, 0($sp)# push $s0 into stack add $t0, $a0, $a1# $t0  g + h add $t1, $a2, $a3# $t1  i + j sub $s0, $t0, $t1# f  $t0 - $t1 add $v0, $s0, $zero# $v0  $s0 lw $s0, 0($sp)# restore $s0 lw $t0, 4($sp)# restore $t0 lw $t1, 8($sp)# restore $t1 add $sp, $sp, 12# adjust stack pointer Memory $sp  High Address  Low Address $v0 Pat.-Hen. pp. 134-135 int leaf_example ( int g, int h, int i, int j) { int f; f = (g + h) - (i + j); return f; } Processor

16 CMPUT 229 - Computer Organization and Architecture I16 Example of lw execution cont($t1) cont($t0) cont($s0) g+h i+j $t0 $t1 g h i $a0 $a1 $a2 j $a3 $t0-$t1 $s0 MIPS assembly: sub $sp, $sp, 12 # Make room in stack for 3 more items sw $t1, 8($sp)# push $t1 into stack sw $t0, 4($sp)# push $t0 into stack sw $s0, 0($sp)# push $s0 into stack add $t0, $a0, $a1# $t0  g + h add $t1, $a2, $a3# $t1  i + j sub $s0, $t0, $t1# f  $t0 - $t1 add $v0, $s0, $zero# $v0  $s0 lw $s0, 0($sp)# restore $s0 lw $t0, 4($sp)# restore $t0 lw $t1, 8($sp)# restore $t1 add $sp, $sp, 12# adjust stack pointer Memory $sp  High Address  Low Address $t0-$t1 $v0 Pat.-Hen. pp. 134-135 int leaf_example ( int g, int h, int i, int j) { int f; f = (g + h) - (i + j); return f; } Processor

17 CMPUT 229 - Computer Organization and Architecture I17 Example of lw execution cont($t1) cont($t0) cont($s0) g+h i+j $t0 $t1 g h i $a0 $a1 $a2 j $a3 cont($s0) $s0 MIPS assembly: sub $sp, $sp, 12 # Make room in stack for 3 more items sw $t1, 8($sp)# push $t1 into stack sw $t0, 4($sp)# push $t0 into stack sw $s0, 0($sp)# push $s0 into stack add $t0, $a0, $a1# $t0  g + h add $t1, $a2, $a3# $t1  i + j sub $s0, $t0, $t1# f  $t0 - $t1 add $v0, $s0, $zero# $v0  $s0 lw $s0, 0($sp)# restore $s0 lw $t0, 4($sp)# restore $t0 lw $t1, 8($sp)# restore $t1 add $sp, $sp, 12# adjust stack pointer Memory $sp  High Address  Low Address $t0-$t1 $v0 Pat.-Hen. pp. 134-135 int leaf_example ( int g, int h, int i, int j) { int f; f = (g + h) - (i + j); return f; } Processor

18 CMPUT 229 - Computer Organization and Architecture I18 Example of lw execution cont($t1) cont($t0) cont($s0) cont($t0) i+j $t0 $t1 g h i $a0 $a1 $a2 j $a3 cont($s0) $s0 MIPS assembly: sub $sp, $sp, 12 # Make room in stack for 3 more items sw $t1, 8($sp)# push $t1 into stack sw $t0, 4($sp)# push $t0 into stack sw $s0, 0($sp)# push $s0 into stack add $t0, $a0, $a1# $t0  g + h add $t1, $a2, $a3# $t1  i + j sub $s0, $t0, $t1# f  $t0 - $t1 add $v0, $s0, $zero# $v0  $s0 lw $s0, 0($sp)# restore $s0 lw $t0, 4($sp)# restore $t0 lw $t1, 8($sp)# restore $t1 add $sp, $sp, 12# adjust stack pointer Memory $sp  High Address  Low Address $t0-$t1 $v0 Pat.-Hen. pp. 134-135 int leaf_example ( int g, int h, int i, int j) { int f; f = (g + h) - (i + j); return f; } Processor

19 CMPUT 229 - Computer Organization and Architecture I19 Example of lw execution cont($t1) cont($t0) cont($s0) cont($t0) cont($t1) $t0 $t1 g h i $a0 $a1 $a2 j $a3 cont($s0) $s0 MIPS assembly: sub $sp, $sp, 12 # Make room in stack for 3 more items sw $t1, 8($sp)# push $t1 into stack sw $t0, 4($sp)# push $t0 into stack sw $s0, 0($sp)# push $s0 into stack add $t0, $a0, $a1# $t0  g + h add $t1, $a2, $a3# $t1  i + j sub $s0, $t0, $t1# f  $t0 - $t1 add $v0, $s0, $zero# $v0  $s0 lw $s0, 0($sp)# restore $s0 lw $t0, 4($sp)# restore $t0 lw $t1, 8($sp)# restore $t1 add $sp, $sp, 12# adjust stack pointer Memory $sp  High Address  Low Address $t0-$t1 $v0 Pat.-Hen. pp. 134-135 int leaf_example ( int g, int h, int i, int j) { int f; f = (g + h) - (i + j); return f; } Processor

20 CMPUT 229 - Computer Organization and Architecture I20 Example of lw execution cont($t1) cont($t0) cont($s0) cont($t0) cont($t1) $t0 $t1 g h i $a0 $a1 $a2 j $a3 cont($s0) $s0 MIPS assembly: sub $sp, $sp, 12 # Make room in stack for 3 more items sw $t1, 8($sp)# push $t1 into stack sw $t0, 4($sp)# push $t0 into stack sw $s0, 0($sp)# push $s0 into stack add $t0, $a0, $a1# $t0  g + h add $t1, $a2, $a3# $t1  i + j sub $s0, $t0, $t1# f  $t0 - $t1 add $v0, $s0, $zero# $v0  $s0 lw $s0, 0($sp)# restore $s0 lw $t0, 4($sp)# restore $t0 lw $t1, 8($sp)# restore $t1 add $sp, $sp, 12# adjust stack pointer Memory Processor  High Address  Low Address $t0-$t1 $v0 $sp Pat.-Hen. pp. 134-135 int leaf_example ( int g, int h, int i, int j) { int f; f = (g + h) - (i + j); return f; }

21 CMPUT 229 - Computer Organization and Architecture I21 Register Saving Convention To avoid saving and restoring registers that might not contain any useful value, MIPS adopts the following software convention: Registers $t0-$t9 are not preserved by the callee on a procedure call. Registers $s0-$s7 must be preserved on a procedure call. We also say that registers $t0-$t9 are caller saved, and that registers $s0-s7 are callee saved. These names indicates which procedure (the caller or the callee) is responsible for preserving the value stored in the register at the procedure boundary.

22 CMPUT 229 - Computer Organization and Architecture I22 Linking a Recursive Procedure int fact ( int n ) { if (n < 1) return(1); else return(n * fact(n-1)); } MIPS assembly: fact: sub $sp, $sp, 8 # Make room in stack for 2 more items sw $ra, 4($sp)# save the return address sw $a0, 0($sp)# save the argument n slt $t0, $a0, 1# if ($a0<1) then $t0  1 else $t0  0 beq $t0, $zero, L1# if n  1, go to L1 add $v0, $zero, 1# return 1 add $sp, $sp, 8# pop two items from the stack jr $ra# return to the instruction after jal L1: sub $a0, $a0, 1# subtract 1 from argument jal fact:# call fact(n-1) lw $a0, 0($sp)# just returned from jal: restore n lw $ra, 4($sp)# restore the return address add $sp, $sp, 8# pop two items from the stack mul $v0, $a0, $v0# return n*fact(n-1) jr $ra# return to the caller

23 CMPUT 229 - Computer Organization and Architecture I23 Example fact(3) MIPS assembly: fact: sub $sp, $sp, 8 # Make room in stack for 2 more items sw $ra, 4($sp)# save the return address sw $a0, 0($sp)# save the argument n slt $t0, $a0, 1# if ($a0<1) then $t0  1 else $t0  0 beq $t0, $zero, L1# if n  1, go to L1 add $v0, $zero, 1# return 1 add $sp, $sp, 8# pop two items from the stack jr $ra# return to the instruction after jal L1: sub $a0, $a0, 1# subtract 1 from argument jal fact:# call fact(n-1) lw $a0, 0($sp)# just returned from jal: restore n lw $ra, 4($sp)# restore the return address add $sp, $sp, 8# pop two items from the stack mul $v0, $a0, $v0# return n*fact(n-1) jr $ra# return to the caller $t0 $v0 3 $a0 Processor 0x10002000 $sp $ra $sp Memory  High Address  Low Address 0x1000 3FFBadd$a0,$zero,3 0x1000 4000jalfact 0x1000 4004…. Pat.-Hen. pp. 136-138 and A-26/A-29

24 CMPUT 229 - Computer Organization and Architecture I24 Example fact(3) MIPS assembly: fact: sub $sp, $sp, 8 # Make room in stack for 2 more items sw $ra, 4($sp)# save the return address sw $a0, 0($sp)# save the argument n slt $t0, $a0, 1# if ($a0<1) then $t0  1 else $t0  0 beq $t0, $zero, L1# if n  1, go to L1 add $v0, $zero, 1# return 1 add $sp, $sp, 8# pop two items from the stack jr $ra# return to the instruction after jal L1: sub $a0, $a0, 1# subtract 1 from argument jal fact:# call fact(n-1) lw $a0, 0($sp)# just returned from jal: restore n lw $ra, 4($sp)# restore the return address add $sp, $sp, 8# pop two items from the stack mul $v0, $a0, $v0# return n*fact(n-1) jr $ra# return to the caller $t0 $v0 3 $a0 Processor 0x10002000 $sp 0x1000 4004 $ra $sp Memory  High Address 0x1000 3FFBadd$a0,$zero,3 0x1000 4000jalfact 0x1000 4004….  Low Address Pat.-Hen. pp. 136-138 and A-26/A-29

25 CMPUT 229 - Computer Organization and Architecture I25 Example fact(3) MIPS assembly: fact: sub $sp, $sp, 8 # Make room in stack for 2 more items sw $ra, 4($sp)# save the return address sw $a0, 0($sp)# save the argument n slt $t0, $a0, 1# if ($a0<1) then $t0  1 else $t0  0 beq $t0, $zero, L1# if n  1, go to L1 add $v0, $zero, 1# return 1 add $sp, $sp, 8# pop two items from the stack jr $ra# return to the instruction after jal L1: sub $a0, $a0, 1# subtract 1 from argument jal fact:# call fact(n-1) lw $a0, 0($sp)# just returned from jal: restore n lw $ra, 4($sp)# restore the return address add $sp, $sp, 8# pop two items from the stack mul $v0, $a0, $v0# return n*fact(n-1) jr $ra# return to the caller $t0 $v0 3 $a0 Processor 0x1000 1FF8 $sp 0x1000 4004 $ra $sp Memory  High Address 0x1000 3FFBadd$a0,$zero,3 0x1000 4000jalfact 0x1000 4004….  Low Address Pat.-Hen. pp. 136-138 and A-26/A-29

26 CMPUT 229 - Computer Organization and Architecture I26 Example fact(3) MIPS assembly: fact: sub $sp, $sp, 8 # Make room in stack for 2 more items sw $ra, 4($sp)# save the return address sw $a0, 0($sp)# save the argument n slt $t0, $a0, 1# if ($a0<1) then $t0  1 else $t0  0 beq $t0, $zero, L1# if n  1, go to L1 add $v0, $zero, 1# return 1 add $sp, $sp, 8# pop two items from the stack jr $ra# return to the instruction after jal L1: sub $a0, $a0, 1# subtract 1 from argument jal fact:# call fact(n-1) lw $a0, 0($sp)# just returned from jal: restore n lw $ra, 4($sp)# restore the return address add $sp, $sp, 8# pop two items from the stack mul $v0, $a0, $v0# return n*fact(n-1) jr $ra# return to the caller $t0 $v0 3 $a0 Processor 0x1000 1FF8 $sp 0x1000 4004 $ra 0x1000 4004 3 $sp Memory  High Address 0x1000 3FFBadd$a0,$zero,3 0x1000 4000jalfact 0x1000 4004….  Low Address Pat.-Hen. pp. 136-138 and A-26/A-29

27 CMPUT 229 - Computer Organization and Architecture I27 Example fact(3) MIPS assembly: fact: sub $sp, $sp, 8 # Make room in stack for 2 more items sw $ra, 4($sp)# save the return address sw $a0, 0($sp)# save the argument n slt $t0, $a0, 1# if ($a0<1) then $t0  1 else $t0  0 beq $t0, $zero, L1# if n  1, go to L1 add $v0, $zero, 1# return 1 add $sp, $sp, 8# pop two items from the stack jr $ra# return to the instruction after jal L1: sub $a0, $a0, 1# subtract 1 from argument jal fact:# call fact(n-1) lw $a0, 0($sp)# just returned from jal: restore n lw $ra, 4($sp)# restore the return address add $sp, $sp, 8# pop two items from the stack mul $v0, $a0, $v0# return n*fact(n-1) jr $ra# return to the caller 1 $t0 $v0 3 $a0 Processor 0x1000 1FF8 $sp 0x1000 4004 $ra 0x1000 4004 3 $sp Memory  High Address 0x1000 3FFBadd$a0,$zero,3 0x1000 4000jalfact 0x1000 4004….  Low Address Pat.-Hen. pp. 136-138 and A-26/A-29

28 CMPUT 229 - Computer Organization and Architecture I28 Example fact(3) MIPS assembly: fact: sub $sp, $sp, 8 # Make room in stack for 2 more items sw $ra, 4($sp)# save the return address sw $a0, 0($sp)# save the argument n slt $t0, $a0, 1# if ($a0<1) then $t0  1 else $t0  0 beq $t0, $zero, L1# if n  1, go to L1 add $v0, $zero, 1# return 1 add $sp, $sp, 8# pop two items from the stack jr $ra# return to the instruction after jal L1: sub $a0, $a0, 1# subtract 1 from argument jal fact:# call fact(n-1) lw $a0, 0($sp)# just returned from jal: restore n lw $ra, 4($sp)# restore the return address add $sp, $sp, 8# pop two items from the stack mul $v0, $a0, $v0# return n*fact(n-1) jr $ra# return to the caller 0 $t0 $v0 3 $a0 Processor 0x1000 1FF8 $sp 0x1000 4004 $ra 0x1000 4004 3 $sp Memory  High Address 0x1000 3FFBadd$a0,$zero,3 0x1000 4000jalfact 0x1000 4004….  Low Address Pat.-Hen. pp. 136-138 and A-26/A-29

29 CMPUT 229 - Computer Organization and Architecture I29 Example fact(3) MIPS assembly: fact: sub $sp, $sp, 8 # Make room in stack for 2 more items sw $ra, 4($sp)# save the return address sw $a0, 0($sp)# save the argument n slt $t0, $a0, 1# if ($a0<1) then $t0  1 else $t0  0 beq $t0, $zero, L1# if n  1, go to L1 add $v0, $zero, 1# return 1 add $sp, $sp, 8# pop two items from the stack jr $ra# return to the instruction after jal L1: sub $a0, $a0, 1# subtract 1 from argument jal fact:# call fact(n-1) lw $a0, 0($sp)# just returned from jal: restore n lw $ra, 4($sp)# restore the return address add $sp, $sp, 8# pop two items from the stack mul $v0, $a0, $v0# return n*fact(n-1) jr $ra# return to the caller 0 $t0 $v0 3 $a0 Processor 0x1000 1FF8 $sp 0x1000 4004 $ra 0x1000 4004 3 $sp Memory  High Address 0x1000 3FFBadd$a0,$zero,3 0x1000 4000jalfact 0x1000 4004….  Low Address Pat.-Hen. pp. 136-138 and A-26/A-29

30 CMPUT 229 - Computer Organization and Architecture I30 Example fact(3) MIPS assembly: fact: sub $sp, $sp, 8 # Make room in stack for 2 more items sw $ra, 4($sp)# save the return address sw $a0, 0($sp)# save the argument n slt $t0, $a0, 1# if ($a0<1) then $t0  1 else $t0  0 beq $t0, $zero, L1# if n  1, go to L1 add $v0, $zero, 1# return 1 add $sp, $sp, 8# pop two items from the stack jr $ra# return to the instruction after jal L1: sub $a0, $a0, 1# subtract 1 from argument jal fact:# call fact(n-1) lw $a0, 0($sp)# just returned from jal: restore n lw $ra, 4($sp)# restore the return address add $sp, $sp, 8# pop two items from the stack mul $v0, $a0, $v0# return n*fact(n-1) jr $ra# return to the caller 0 $t0 $v0 2 $a0 Processor 0x1000 1FF8 $sp 0x1000 4004 $ra 0x1000 4004 3 $sp Memory  High Address 0x1000 3FFBadd$a0,$zero,3 0x1000 4000jalfact 0x1000 4004….  Low Address Pat.-Hen. pp. 136-138 and A-26/A-29

31 CMPUT 229 - Computer Organization and Architecture I31 Example fact(3) MIPS assembly: fact: sub $sp, $sp, 8 # Make room in stack for 2 more items sw $ra, 4($sp)# save the return address sw $a0, 0($sp)# save the argument n slt $t0, $a0, 1# if ($a0<1) then $t0  1 else $t0  0 beq $t0, $zero, L1# if n  1, go to L1 add $v0, $zero, 1# return 1 add $sp, $sp, 8# pop two items from the stack jr $ra# return to the instruction after jal L1: sub $a0, $a0, 1# subtract 1 from argument jal fact:# call fact(n-1) lw $a0, 0($sp)# just returned from jal: restore n lw $ra, 4($sp)# restore the return address add $sp, $sp, 8# pop two items from the stack mul $v0, $a0, $v0# return n*fact(n-1) jr $ra# return to the caller 0 $t0 $v0 2 $a0 Processor 0x1000 1FF8 $sp 0x1000 6FEC $ra 0x1000 4004 3 $sp Memory  High Address 0x1000 3FFBadd$a0,$zero,3 0x1000 4000jalfact 0x1000 4004….  Low Address Pat.-Hen. pp. 136-138 and A-26/A-29

32 CMPUT 229 - Computer Organization and Architecture I32 Example fact(3) MIPS assembly: fact: sub $sp, $sp, 8 # Make room in stack for 2 more items sw $ra, 4($sp)# save the return address sw $a0, 0($sp)# save the argument n slt $t0, $a0, 1# if ($a0<1) then $t0  1 else $t0  0 beq $t0, $zero, L1# if n  1, go to L1 add $v0, $zero, 1# return 1 add $sp, $sp, 8# pop two items from the stack jr $ra# return to the instruction after jal L1: sub $a0, $a0, 1# subtract 1 from argument jal fact:# call fact(n-1) lw $a0, 0($sp)# just returned from jal: restore n lw $ra, 4($sp)# restore the return address add $sp, $sp, 8# pop two items from the stack mul $v0, $a0, $v0# return n*fact(n-1) jr $ra# return to the caller 0 $t0 $v0 2 $a0 Processor 0x1000 1FF0 $sp 0x1000 6FEC $ra 0x1000 4004 3 $sp Memory  High Address 0x1000 3FFBadd$a0,$zero,3 0x1000 4000jalfact 0x1000 4004….  Low Address Pat.-Hen. pp. 136-138 and A-26/A-29

33 CMPUT 229 - Computer Organization and Architecture I33 Example fact(3) MIPS assembly: fact: sub $sp, $sp, 8 # Make room in stack for 2 more items sw $ra, 4($sp)# save the return address sw $a0, 0($sp)# save the argument n slt $t0, $a0, 1# if ($a0<1) then $t0  1 else $t0  0 beq $t0, $zero, L1# if n  1, go to L1 add $v0, $zero, 1# return 1 add $sp, $sp, 8# pop two items from the stack jr $ra# return to the instruction after jal L1: sub $a0, $a0, 1# subtract 1 from argument jal fact:# call fact(n-1) lw $a0, 0($sp)# just returned from jal: restore n lw $ra, 4($sp)# restore the return address add $sp, $sp, 8# pop two items from the stack mul $v0, $a0, $v0# return n*fact(n-1) jr $ra# return to the caller 0 $t0 $v0 2 $a0 Processor 0x1000 1FF0 $sp 0x1000 6FEC $ra 0x1000 4004 3 0x1000 6FEC 2 $sp Memory  High Address 0x1000 3FFBadd$a0,$zero,3 0x1000 4000jalfact 0x1000 4004….  Low Address Pat.-Hen. pp. 136-138 and A-26/A-29

34 CMPUT 229 - Computer Organization and Architecture I34 Example fact(3) MIPS assembly: fact: sub $sp, $sp, 8 # Make room in stack for 2 more items sw $ra, 4($sp)# save the return address sw $a0, 0($sp)# save the argument n slt $t0, $a0, 1# if ($a0<1) then $t0  1 else $t0  0 beq $t0, $zero, L1# if n  1, go to L1 add $v0, $zero, 1# return 1 add $sp, $sp, 8# pop two items from the stack jr $ra# return to the instruction after jal L1: sub $a0, $a0, 1# subtract 1 from argument jal fact:# call fact(n-1) lw $a0, 0($sp)# just returned from jal: restore n lw $ra, 4($sp)# restore the return address add $sp, $sp, 8# pop two items from the stack mul $v0, $a0, $v0# return n*fact(n-1) jr $ra# return to the caller 0 $t0 $v0 1 $a0 Processor 0x1000 1FF0 $sp 0x1000 6FEC $ra 0x1000 4004 3 0x1000 6FEC 2 $sp Memory  High Address 0x1000 3FFBadd$a0,$zero,3 0x1000 4000jalfact 0x1000 4004….  Low Address Pat.-Hen. pp. 136-138 and A-26/A-29

35 CMPUT 229 - Computer Organization and Architecture I35 Example fact(3) MIPS assembly: fact: sub $sp, $sp, 8 # Make room in stack for 2 more items sw $ra, 4($sp)# save the return address sw $a0, 0($sp)# save the argument n slt $t0, $a0, 1# if ($a0<1) then $t0  1 else $t0  0 beq $t0, $zero, L1# if n  1, go to L1 add $v0, $zero, 1# return 1 add $sp, $sp, 8# pop two items from the stack jr $ra# return to the instruction after jal L1: sub $a0, $a0, 1# subtract 1 from argument jal fact:# call fact(n-1) lw $a0, 0($sp)# just returned from jal: restore n lw $ra, 4($sp)# restore the return address add $sp, $sp, 8# pop two items from the stack mul $v0, $a0, $v0# return n*fact(n-1) jr $ra# return to the caller 0 $t0 $v0 1 $a0 Processor 0x1000 1FF0 $sp 0x1000 6FEC $ra 0x1000 4004 3 0x1000 6FEC 2 $sp Memory  High Address 0x1000 3FFBadd$a0,$zero,3 0x1000 4000jalfact 0x1000 4004….  Low Address Pat.-Hen. pp. 136-138 and A-26/A-29

36 CMPUT 229 - Computer Organization and Architecture I36 Example fact(3) MIPS assembly: fact: sub $sp, $sp, 8 # Make room in stack for 2 more items sw $ra, 4($sp)# save the return address sw $a0, 0($sp)# save the argument n slt $t0, $a0, 1# if ($a0<1) then $t0  1 else $t0  0 beq $t0, $zero, L1# if n  1, go to L1 add $v0, $zero, 1# return 1 add $sp, $sp, 8# pop two items from the stack jr $ra# return to the instruction after jal L1: sub $a0, $a0, 1# subtract 1 from argument jal fact:# call fact(n-1) lw $a0, 0($sp)# just returned from jal: restore n lw $ra, 4($sp)# restore the return address add $sp, $sp, 8# pop two items from the stack mul $v0, $a0, $v0# return n*fact(n-1) jr $ra# return to the caller 0 $t0 $v0 1 $a0 Processor 0x1000 1FE8 $sp 0x1000 6FEC $ra 0x1000 4004 3 0x1000 6FEC 2 $sp Memory  High Address 0x1000 3FFBadd$a0,$zero,3 0x1000 4000jalfact 0x1000 4004….  Low Address Pat.-Hen. pp. 136-138 and A-26/A-29

37 CMPUT 229 - Computer Organization and Architecture I37 Example fact(3) MIPS assembly: fact: sub $sp, $sp, 8 # Make room in stack for 2 more items sw $ra, 4($sp)# save the return address sw $a0, 0($sp)# save the argument n slt $t0, $a0, 1# if ($a0<1) then $t0  1 else $t0  0 beq $t0, $zero, L1# if n  1, go to L1 add $v0, $zero, 1# return 1 add $sp, $sp, 8# pop two items from the stack jr $ra# return to the instruction after jal L1: sub $a0, $a0, 1# subtract 1 from argument jal fact:# call fact(n-1) lw $a0, 0($sp)# just returned from jal: restore n lw $ra, 4($sp)# restore the return address add $sp, $sp, 8# pop two items from the stack mul $v0, $a0, $v0# return n*fact(n-1) jr $ra# return to the caller 0 $t0 $v0 1 $a0 Processor 0x1000 1FE8 $sp 0x1000 6FEC $ra 0x1000 4004 3 0x1000 6FEC 2 1 $sp Memory  High Address 0x1000 3FFBadd$a0,$zero,3 0x1000 4000jalfact 0x1000 4004….  Low Address Pat.-Hen. pp. 136-138 and A-26/A-29

38 CMPUT 229 - Computer Organization and Architecture I38 Example fact(3) MIPS assembly: fact: sub $sp, $sp, 8 # Make room in stack for 2 more items sw $ra, 4($sp)# save the return address sw $a0, 0($sp)# save the argument n slt $t0, $a0, 1# if ($a0<1) then $t0  1 else $t0  0 beq $t0, $zero, L1# if n  1, go to L1 add $v0, $zero, 1# return 1 add $sp, $sp, 8# pop two items from the stack jr $ra# return to the instruction after jal L1: sub $a0, $a0, 1# subtract 1 from argument jal fact:# call fact(n-1) lw $a0, 0($sp)# just returned from jal: restore n lw $ra, 4($sp)# restore the return address add $sp, $sp, 8# pop two items from the stack mul $v0, $a0, $v0# return n*fact(n-1) jr $ra# return to the caller 1 $t0 $v0 0 $a0 Processor 0x1000 1FE8 $sp 0x1000 6FEC $ra 0x1000 4004 3 0x1000 6FEC 2 1 $sp Memory  High Address 0x1000 3FFBadd$a0,$zero,3 0x1000 4000jalfact 0x1000 4004….  Low Address Pat.-Hen. pp. 136-138 and A-26/A-29

39 CMPUT 229 - Computer Organization and Architecture I39 Example fact(3) MIPS assembly: fact: sub $sp, $sp, 8 # Make room in stack for 2 more items sw $ra, 4($sp)# save the return address sw $a0, 0($sp)# save the argument n slt $t0, $a0, 1# if ($a0<1) then $t0  1 else $t0  0 beq $t0, $zero, L1# if n  1, go to L1 add $v0, $zero, 1# return 1 add $sp, $sp, 8# pop two items from the stack jr $ra# return to the instruction after jal L1: sub $a0, $a0, 1# subtract 1 from argument jal fact:# call fact(n-1) lw $a0, 0($sp)# just returned from jal: restore n lw $ra, 4($sp)# restore the return address add $sp, $sp, 8# pop two items from the stack mul $v0, $a0, $v0# return n*fact(n-1) jr $ra# return to the caller 1 $t0 $v0 0 $a0 Processor 0x1000 1FE8 $sp 0x1000 6FEC $ra 0x1000 4004 3 0x1000 6FEC 2 1 $sp Memory  High Address 0x1000 3FFBadd$a0,$zero,3 0x1000 4000jalfact 0x1000 4004….  Low Address Pat.-Hen. pp. 136-138 and A-26/A-29

40 CMPUT 229 - Computer Organization and Architecture I40 Example fact(3) MIPS assembly: fact: sub $sp, $sp, 8 # Make room in stack for 2 more items sw $ra, 4($sp)# save the return address sw $a0, 0($sp)# save the argument n slt $t0, $a0, 1# if ($a0<1) then $t0  1 else $t0  0 beq $t0, $zero, L1# if n  1, go to L1 add $v0, $zero, 1# return 1 add $sp, $sp, 8# pop two items from the stack jr $ra# return to the instruction after jal L1: sub $a0, $a0, 1# subtract 1 from argument jal fact:# call fact(n-1) lw $a0, 0($sp)# just returned from jal: restore n lw $ra, 4($sp)# restore the return address add $sp, $sp, 8# pop two items from the stack mul $v0, $a0, $v0# return n*fact(n-1) jr $ra# return to the caller 1 $t0 $v0 0 $a0 Processor 0x1000 1FE0 $sp 0x1000 6FEC $ra 0x1000 4004 3 0x1000 6FEC 2 1 Memory  High Address 0x1000 3FFBadd$a0,$zero,3 0x1000 4000jalfact 0x1000 4004….  Low Address 0x1000 6FEC 0 $sp Pat.-Hen. pp. 136-138 and A-26/A-29

41 CMPUT 229 - Computer Organization and Architecture I41 Example fact(3) MIPS assembly: fact: sub $sp, $sp, 8 # Make room in stack for 2 more items sw $ra, 4($sp)# save the return address sw $a0, 0($sp)# save the argument n slt $t0, $a0, 1# if ($a0<1) then $t0  1 else $t0  0 beq $t0, $zero, L1# if n  1, go to L1 add $v0, $zero, 1# return 1 add $sp, $sp, 8# pop two items from the stack jr $ra# return to the instruction after jal L1: sub $a0, $a0, 1# subtract 1 from argument jal fact:# call fact(n-1) lw $a0, 0($sp)# just returned from jal: restore n lw $ra, 4($sp)# restore the return address add $sp, $sp, 8# pop two items from the stack mul $v0, $a0, $v0# return n*fact(n-1) jr $ra# return to the caller 1 $t0 $v0 0 $a0 Processor 0x1000 1FE0 $sp 0x1000 6FEC $ra 0x1000 4004 3 0x1000 6FEC 2 1 Memory  High Address 0x1000 3FFBadd$a0,$zero,3 0x1000 4000jalfact 0x1000 4004….  Low Address 0x1000 6FEC 0 $sp Pat.-Hen. pp. 136-138 and A-26/A-29

42 CMPUT 229 - Computer Organization and Architecture I42 Example fact(3) MIPS assembly: fact: sub $sp, $sp, 8 # Make room in stack for 2 more items sw $ra, 4($sp)# save the return address sw $a0, 0($sp)# save the argument n slt $t0, $a0, 1# if ($a0<1) then $t0  1 else $t0  0 beq $t0, $zero, L1# if n  1, go to L1 add $v0, $zero, 1# return 1 add $sp, $sp, 8# pop two items from the stack jr $ra# return to the instruction after jal L1: sub $a0, $a0, 1# subtract 1 from argument jal fact:# call fact(n-1) lw $a0, 0($sp)# just returned from jal: restore n lw $ra, 4($sp)# restore the return address add $sp, $sp, 8# pop two items from the stack mul $v0, $a0, $v0# return n*fact(n-1) jr $ra# return to the caller 1 $t0 1 $v0 0 $a0 Processor 0x1000 1FE0 $sp 0x1000 6FEC $ra 0x1000 4004 3 0x1000 6FEC 2 1 Memory  High Address 0x1000 3FFBadd$a0,$zero,3 0x1000 4000jalfact 0x1000 4004….  Low Address 0x1000 6FEC 0 $sp Pat.-Hen. pp. 136-138 and A-26/A-29

43 CMPUT 229 - Computer Organization and Architecture I43 Example fact(3) MIPS assembly: fact: sub $sp, $sp, 8 # Make room in stack for 2 more items sw $ra, 4($sp)# save the return address sw $a0, 0($sp)# save the argument n slt $t0, $a0, 1# if ($a0<1) then $t0  1 else $t0  0 beq $t0, $zero, L1# if n  1, go to L1 add $v0, $zero, 1# return 1 add $sp, $sp, 8# pop two items from the stack jr $ra# return to the instruction after jal L1: sub $a0, $a0, 1# subtract 1 from argument jal fact:# call fact(n-1) lw $a0, 0($sp)# just returned from jal: restore n lw $ra, 4($sp)# restore the return address add $sp, $sp, 8# pop two items from the stack mul $v0, $a0, $v0# return n*fact(n-1) jr $ra# return to the caller 1 $t0 1 $v0 0 $a0 Processor 0x1000 1FE8 $sp 0x1000 6FEC $ra 0x1000 4004 3 0x1000 6FEC 2 1 Memory  High Address 0x1000 3FFBadd$a0,$zero,3 0x1000 4000jalfact 0x1000 4004….  Low Address 0x1000 6FEC 0 $sp Pat.-Hen. pp. 136-138 and A-26/A-29

44 CMPUT 229 - Computer Organization and Architecture I44 Example fact(3) MIPS assembly: fact: sub $sp, $sp, 8 # Make room in stack for 2 more items sw $ra, 4($sp)# save the return address sw $a0, 0($sp)# save the argument n slt $t0, $a0, 1# if ($a0<1) then $t0  1 else $t0  0 beq $t0, $zero, L1# if n  1, go to L1 add $v0, $zero, 1# return 1 add $sp, $sp, 8# pop two items from the stack jr $ra# return to the instruction after jal L1: sub $a0, $a0, 1# subtract 1 from argument jal fact:# call fact(n-1) lw $a0, 0($sp)# just returned from jal: restore n lw $ra, 4($sp)# restore the return address add $sp, $sp, 8# pop two items from the stack mul $v0, $a0, $v0# return n*fact(n-1) jr $ra# return to the caller 1 $t0 1 $v0 0 $a0 Processor 0x1000 1FE8 $sp 0x1000 6FEC $ra 0x1000 4004 3 0x1000 6FEC 2 1 Memory  High Address 0x1000 3FFBadd$a0,$zero,3 0x1000 4000jalfact 0x1000 4004….  Low Address 0x1000 6FEC 0 $sp Pat.-Hen. pp. 136-138 and A-26/A-29

45 CMPUT 229 - Computer Organization and Architecture I45 Example fact(3) MIPS assembly: fact: sub $sp, $sp, 8 # Make room in stack for 2 more items sw $ra, 4($sp)# save the return address sw $a0, 0($sp)# save the argument n slt $t0, $a0, 1# if ($a0<1) then $t0  1 else $t0  0 beq $t0, $zero, L1# if n  1, go to L1 add $v0, $zero, 1# return 1 add $sp, $sp, 8# pop two items from the stack jr $ra# return to the instruction after jal L1: sub $a0, $a0, 1# subtract 1 from argument jal fact:# call fact(n-1) lw $a0, 0($sp)# just returned from jal: restore n lw $ra, 4($sp)# restore the return address add $sp, $sp, 8# pop two items from the stack mul $v0, $a0, $v0# return n*fact(n-1) jr $ra# return to the caller 1 $t0 1 $v0 1 $a0 Processor 0x1000 1FE8 $sp 0x1000 6FEC $ra 0x1000 4004 3 0x1000 6FEC 2 1 Memory  High Address 0x1000 3FFBadd$a0,$zero,3 0x1000 4000jalfact 0x1000 4004….  Low Address 0x1000 6FEC 0 $sp Pat.-Hen. pp. 136-138 and A-26/A-29

46 CMPUT 229 - Computer Organization and Architecture I46 Example fact(3) MIPS assembly: fact: sub $sp, $sp, 8 # Make room in stack for 2 more items sw $ra, 4($sp)# save the return address sw $a0, 0($sp)# save the argument n slt $t0, $a0, 1# if ($a0<1) then $t0  1 else $t0  0 beq $t0, $zero, L1# if n  1, go to L1 add $v0, $zero, 1# return 1 add $sp, $sp, 8# pop two items from the stack jr $ra# return to the instruction after jal L1: sub $a0, $a0, 1# subtract 1 from argument jal fact:# call fact(n-1) lw $a0, 0($sp)# just returned from jal: restore n lw $ra, 4($sp)# restore the return address add $sp, $sp, 8# pop two items from the stack mul $v0, $a0, $v0# return n*fact(n-1) jr $ra# return to the caller 1 $t0 1 $v0 1 $a0 Processor 0x1000 1FE8 $sp 0x1000 6FEC $ra 0x1000 4004 3 0x1000 6FEC 2 1 Memory  High Address 0x1000 3FFBadd$a0,$zero,3 0x1000 4000jalfact 0x1000 4004….  Low Address 0x1000 6FEC 0 $sp Pat.-Hen. pp. 136-138 and A-26/A-29

47 CMPUT 229 - Computer Organization and Architecture I47 Example fact(3) MIPS assembly: fact: sub $sp, $sp, 8 # Make room in stack for 2 more items sw $ra, 4($sp)# save the return address sw $a0, 0($sp)# save the argument n slt $t0, $a0, 1# if ($a0<1) then $t0  1 else $t0  0 beq $t0, $zero, L1# if n  1, go to L1 add $v0, $zero, 1# return 1 add $sp, $sp, 8# pop two items from the stack jr $ra# return to the instruction after jal L1: sub $a0, $a0, 1# subtract 1 from argument jal fact:# call fact(n-1) lw $a0, 0($sp)# just returned from jal: restore n lw $ra, 4($sp)# restore the return address add $sp, $sp, 8# pop two items from the stack mul $v0, $a0, $v0# return n*fact(n-1) jr $ra# return to the caller 1 $t0 1 $v0 1 $a0 Processor 0x1000 1FF0 $sp 0x1000 6FEC $ra 0x1000 4004 3 0x1000 6FEC 2 1 $sp Memory  High Address 0x1000 3FFBadd$a0,$zero,3 0x1000 4000jalfact 0x1000 4004….  Low Address 0x1000 6FEC 0 Pat.-Hen. pp. 136-138 and A-26/A-29

48 CMPUT 229 - Computer Organization and Architecture I48 Example fact(3) MIPS assembly: fact: sub $sp, $sp, 8 # Make room in stack for 2 more items sw $ra, 4($sp)# save the return address sw $a0, 0($sp)# save the argument n slt $t0, $a0, 1# if ($a0<1) then $t0  1 else $t0  0 beq $t0, $zero, L1# if n  1, go to L1 add $v0, $zero, 1# return 1 add $sp, $sp, 8# pop two items from the stack jr $ra# return to the instruction after jal L1: sub $a0, $a0, 1# subtract 1 from argument jal fact:# call fact(n-1) lw $a0, 0($sp)# just returned from jal: restore n lw $ra, 4($sp)# restore the return address add $sp, $sp, 8# pop two items from the stack mul $v0, $a0, $v0# return n*fact(n-1) jr $ra# return to the caller 1 $t0 1 $v0 1 $a0 Processor 0x1000 1FF0 $sp 0x1000 6FEC $ra 0x1000 4004 3 0x1000 6FEC 2 1 $sp Memory  High Address 0x1000 3FFBadd$a0,$zero,3 0x1000 4000jalfact 0x1000 4004….  Low Address 0x1000 6FEC 0 Pat.-Hen. pp. 136-138 and A-26/A-29

49 CMPUT 229 - Computer Organization and Architecture I49 Example fact(3) MIPS assembly: fact: sub $sp, $sp, 8 # Make room in stack for 2 more items sw $ra, 4($sp)# save the return address sw $a0, 0($sp)# save the argument n slt $t0, $a0, 1# if ($a0<1) then $t0  1 else $t0  0 beq $t0, $zero, L1# if n  1, go to L1 add $v0, $zero, 1# return 1 add $sp, $sp, 8# pop two items from the stack jr $ra# return to the instruction after jal L1: sub $a0, $a0, 1# subtract 1 from argument jal fact:# call fact(n-1) lw $a0, 0($sp)# just returned from jal: restore n lw $ra, 4($sp)# restore the return address add $sp, $sp, 8# pop two items from the stack mul $v0, $a0, $v0# return n*fact(n-1) jr $ra# return to the caller 1 $t0 1 $v0 1 $a0 Processor 0x1000 1FF0 $sp 0x1000 6FEC $ra 0x1000 4004 3 0x1000 6FEC 2 1 $sp Memory  High Address 0x1000 3FFBadd$a0,$zero,3 0x1000 4000jalfact 0x1000 4004….  Low Address 0x1000 6FEC 0 Pat.-Hen. pp. 136-138 and A-26/A-29

50 CMPUT 229 - Computer Organization and Architecture I50 Example fact(3) MIPS assembly: fact: sub $sp, $sp, 8 # Make room in stack for 2 more items sw $ra, 4($sp)# save the return address sw $a0, 0($sp)# save the argument n slt $t0, $a0, 1# if ($a0<1) then $t0  1 else $t0  0 beq $t0, $zero, L1# if n  1, go to L1 add $v0, $zero, 1# return 1 add $sp, $sp, 8# pop two items from the stack jr $ra# return to the instruction after jal L1: sub $a0, $a0, 1# subtract 1 from argument jal fact:# call fact(n-1) lw $a0, 0($sp)# just returned from jal: restore n lw $ra, 4($sp)# restore the return address add $sp, $sp, 8# pop two items from the stack mul $v0, $a0, $v0# return n*fact(n-1) jr $ra# return to the caller 1 $t0 1 $v0 2 $a0 Processor 0x1000 1FF0 $sp 0x1000 6FEC $ra 0x1000 4004 3 0x1000 6FEC 2 1 $sp Memory  High Address 0x1000 3FFBadd$a0,$zero,3 0x1000 4000jalfact 0x1000 4004….  Low Address 0x1000 6FEC 0 Pat.-Hen. pp. 136-138 and A-26/A-29

51 CMPUT 229 - Computer Organization and Architecture I51 Example fact(3) MIPS assembly: fact: sub $sp, $sp, 8 # Make room in stack for 2 more items sw $ra, 4($sp)# save the return address sw $a0, 0($sp)# save the argument n slt $t0, $a0, 1# if ($a0<1) then $t0  1 else $t0  0 beq $t0, $zero, L1# if n  1, go to L1 add $v0, $zero, 1# return 1 add $sp, $sp, 8# pop two items from the stack jr $ra# return to the instruction after jal L1: sub $a0, $a0, 1# subtract 1 from argument jal fact:# call fact(n-1) lw $a0, 0($sp)# just returned from jal: restore n lw $ra, 4($sp)# restore the return address add $sp, $sp, 8# pop two items from the stack mul $v0, $a0, $v0# return n*fact(n-1) jr $ra# return to the caller 1 $t0 1 $v0 2 $a0 Processor 0x1000 1FF8 $sp 0x1000 6FEC $ra 0x1000 4004 3 0x1000 6FEC 2 1 $sp Memory  High Address 0x1000 3FFBadd$a0,$zero,3 0x1000 4000jalfact 0x1000 4004….  Low Address 0x1000 6FEC 0 Pat.-Hen. pp. 136-138 and A-26/A-29

52 CMPUT 229 - Computer Organization and Architecture I52 Example fact(3) MIPS assembly: fact: sub $sp, $sp, 8 # Make room in stack for 2 more items sw $ra, 4($sp)# save the return address sw $a0, 0($sp)# save the argument n slt $t0, $a0, 1# if ($a0<1) then $t0  1 else $t0  0 beq $t0, $zero, L1# if n  1, go to L1 add $v0, $zero, 1# return 1 add $sp, $sp, 8# pop two items from the stack jr $ra# return to the instruction after jal L1: sub $a0, $a0, 1# subtract 1 from argument jal fact:# call fact(n-1) lw $a0, 0($sp)# just returned from jal: restore n lw $ra, 4($sp)# restore the return address add $sp, $sp, 8# pop two items from the stack mul $v0, $a0, $v0# return n*fact(n-1) jr $ra# return to the caller 1 $t0 2 $v0 2 $a0 Processor 0x1000 1FF8 $sp 0x1000 6FEC $ra 0x1000 4004 3 0x1000 6FEC 2 1 $sp Memory  High Address 0x1000 3FFBadd$a0,$zero,3 0x1000 4000jalfact 0x1000 4004….  Low Address 0x1000 6FEC 0 Pat.-Hen. pp. 136-138 and A-26/A-29

53 CMPUT 229 - Computer Organization and Architecture I53 Example fact(3) MIPS assembly: fact: sub $sp, $sp, 8 # Make room in stack for 2 more items sw $ra, 4($sp)# save the return address sw $a0, 0($sp)# save the argument n slt $t0, $a0, 1# if ($a0<1) then $t0  1 else $t0  0 beq $t0, $zero, L1# if n  1, go to L1 add $v0, $zero, 1# return 1 add $sp, $sp, 8# pop two items from the stack jr $ra# return to the instruction after jal L1: sub $a0, $a0, 1# subtract 1 from argument jal fact:# call fact(n-1) lw $a0, 0($sp)# just returned from jal: restore n lw $ra, 4($sp)# restore the return address add $sp, $sp, 8# pop two items from the stack mul $v0, $a0, $v0# return n*fact(n-1) jr $ra# return to the caller 1 $t0 2 $v0 2 $a0 Processor 0x1000 1FF8 $sp 0x1000 6FEC $ra 0x1000 4004 3 0x1000 6FEC 2 1 $sp Memory  High Address 0x1000 3FFBadd$a0,$zero,3 0x1000 4000jalfact 0x1000 4004….  Low Address 0x1000 6FEC 0 Pat.-Hen. pp. 136-138 and A-26/A-29

54 CMPUT 229 - Computer Organization and Architecture I54 Example fact(3) MIPS assembly: fact: sub $sp, $sp, 8 # Make room in stack for 2 more items sw $ra, 4($sp)# save the return address sw $a0, 0($sp)# save the argument n slt $t0, $a0, 1# if ($a0<1) then $t0  1 else $t0  0 beq $t0, $zero, L1# if n  1, go to L1 add $v0, $zero, 1# return 1 add $sp, $sp, 8# pop two items from the stack jr $ra# return to the instruction after jal L1: sub $a0, $a0, 1# subtract 1 from argument jal fact:# call fact(n-1) lw $a0, 0($sp)# just returned from jal: restore n lw $ra, 4($sp)# restore the return address add $sp, $sp, 8# pop two items from the stack mul $v0, $a0, $v0# return n*fact(n-1) jr $ra# return to the caller 1 $t0 2 $v0 3 $a0 Processor 0x1000 1FF8 $sp 0x1000 6FEC $ra 0x1000 4004 3 0x1000 6FEC 2 1 $sp Memory  High Address 0x1000 3FFBadd$a0,$zero,3 0x1000 4000jalfact 0x1000 4004….  Low Address 0x1000 6FEC 0 Pat.-Hen. pp. 136-138 and A-26/A-29

55 CMPUT 229 - Computer Organization and Architecture I55 Example fact(3) MIPS assembly: fact: sub $sp, $sp, 8 # Make room in stack for 2 more items sw $ra, 4($sp)# save the return address sw $a0, 0($sp)# save the argument n slt $t0, $a0, 1# if ($a0<1) then $t0  1 else $t0  0 beq $t0, $zero, L1# if n  1, go to L1 add $v0, $zero, 1# return 1 add $sp, $sp, 8# pop two items from the stack jr $ra# return to the instruction after jal L1: sub $a0, $a0, 1# subtract 1 from argument jal fact:# call fact(n-1) lw $a0, 0($sp)# just returned from jal: restore n lw $ra, 4($sp)# restore the return address add $sp, $sp, 8# pop two items from the stack mul $v0, $a0, $v0# return n*fact(n-1) jr $ra# return to the caller 1 $t0 2 $v0 3 $a0 Processor 0x1000 1FF8 $sp 0x1000 4004 $ra 0x1000 4004 3 0x1000 6FEC 2 1 $sp Memory  High Address 0x1000 3FFBadd$a0,$zero,3 0x1000 4000jalfact 0x1000 4004….  Low Address 0x1000 6FEC 0 Pat.-Hen. pp. 136-138 and A-26/A-29

56 CMPUT 229 - Computer Organization and Architecture I56 Example fact(3) MIPS assembly: fact: sub $sp, $sp, 8 # Make room in stack for 2 more items sw $ra, 4($sp)# save the return address sw $a0, 0($sp)# save the argument n slt $t0, $a0, 1# if ($a0<1) then $t0  1 else $t0  0 beq $t0, $zero, L1# if n  1, go to L1 add $v0, $zero, 1# return 1 add $sp, $sp, 8# pop two items from the stack jr $ra# return to the instruction after jal L1: sub $a0, $a0, 1# subtract 1 from argument jal fact:# call fact(n-1) lw $a0, 0($sp)# just returned from jal: restore n lw $ra, 4($sp)# restore the return address add $sp, $sp, 8# pop two items from the stack mul $v0, $a0, $v0# return n*fact(n-1) jr $ra# return to the caller 1 $t0 2 $v0 3 $a0 Processor 0x1000 2000 $sp 0x1000 4004 $ra 0x1000 4004 3 0x1000 6FEC 2 1 $sp Memory  High Address 0x1000 3FFBadd$a0,$zero,3 0x1000 4000jalfact 0x1000 4004….  Low Address 0x1000 6FEC 0 Pat.-Hen. pp. 136-138 and A-26/A-29

57 CMPUT 229 - Computer Organization and Architecture I57 Example fact(3) MIPS assembly: fact: sub $sp, $sp, 8 # Make room in stack for 2 more items sw $ra, 4($sp)# save the return address sw $a0, 0($sp)# save the argument n slt $t0, $a0, 1# if ($a0<1) then $t0  1 else $t0  0 beq $t0, $zero, L1# if n  1, go to L1 add $v0, $zero, 1# return 1 add $sp, $sp, 8# pop two items from the stack jr $ra# return to the instruction after jal L1: sub $a0, $a0, 1# subtract 1 from argument jal fact:# call fact(n-1) lw $a0, 0($sp)# just returned from jal: restore n lw $ra, 4($sp)# restore the return address add $sp, $sp, 8# pop two items from the stack mul $v0, $a0, $v0# return n*fact(n-1) jr $ra# return to the caller 1 $t0 6 $v0 3 $a0 Processor 0x1000 2000 $sp 0x1000 4004 $ra 0x1000 4004 3 0x1000 6FEC 2 1 $sp Memory  High Address 0x1000 3FFBadd$a0,$zero,3 0x1000 4000jalfact 0x1000 4004….  Low Address 0x1000 6FEC 0 Pat.-Hen. pp. 136-138 and A-26/A-29

58 CMPUT 229 - Computer Organization and Architecture I58 Example fact(3) MIPS assembly: fact: sub $sp, $sp, 8 # Make room in stack for 2 more items sw $ra, 4($sp)# save the return address sw $a0, 0($sp)# save the argument n slt $t0, $a0, 1# if ($a0<1) then $t0  1 else $t0  0 beq $t0, $zero, L1# if n  1, go to L1 add $v0, $zero, 1# return 1 add $sp, $sp, 8# pop two items from the stack jr $ra# return to the instruction after jal L1: sub $a0, $a0, 1# subtract 1 from argument jal fact:# call fact(n-1) lw $a0, 0($sp)# just returned from jal: restore n lw $ra, 4($sp)# restore the return address add $sp, $sp, 8# pop two items from the stack mul $v0, $a0, $v0# return n*fact(n-1) jr $ra# return to the caller 1 $t0 6 $v0 3 $a0 Processor 0x1000 2000 $sp 0x1000 4004 $ra 0x1000 4004 3 0x1000 6FEC 2 1 $sp Memory  High Address 0x1000 3FFBadd$a0,$zero,3 0x1000 4000jalfact 0x1000 4004….  Low Address 0x1000 6FEC 0 Pat.-Hen. pp. 136-138 and A-26/A-29

59 CMPUT 229 - Computer Organization and Architecture I59 Example fact(3) MIPS assembly: fact: sub $sp, $sp, 8 # Make room in stack for 2 more items sw $ra, 4($sp)# save the return address sw $a0, 0($sp)# save the argument n slt $t0, $a0, 1# if ($a0<1) then $t0  1 else $t0  0 beq $t0, $zero, L1# if n  1, go to L1 add $v0, $zero, 1# return 1 add $sp, $sp, 8# pop two items from the stack jr $ra# return to the instruction after jal L1: sub $a0, $a0, 1# subtract 1 from argument jal fact:# call fact(n-1) lw $a0, 0($sp)# just returned from jal: restore n lw $ra, 4($sp)# restore the return address add $sp, $sp, 8# pop two items from the stack mul $v0, $a0, $v0# return n*fact(n-1) jr $ra# return to the caller 1 $t0 6 $v0 3 $a0 Processor 0x1000 2000 $sp 0x1000 4004 $ra 0x1000 4004 3 0x1000 6FEC 2 1 $sp Memory  High Address 0x1000 3FFBadd$a0,$zero,3 0x1000 4000jalfact 0x1000 4004….  Low Address 0x1000 6FEC 0 Pat.-Hen. pp. 136-138 and A-26/A-29

60 CMPUT 229 - Computer Organization and Architecture I60 Other Data Stored in the Stack $sp  High Address  Low Address $fp Before procedure call $sp  High Address  Low Address $fp After procedure call $sp  High Address  Low Address $fp During procedure call Saved argument registers Saved return reg. Saved registers Local arrays and structures Patt.-Hen. pp 139

61 CMPUT 229 - Computer Organization and Architecture I61 ASCII Code Patt.-Hen., pp 142

62 CMPUT 229 - Computer Organization and Architecture I62 A Procedure that Doesn’t Call Another Procedure void strcpy ( char x[ ], char y[ ]) { int i; i = 0; while ((x[i] = y[i]) != 0) i = i + 1; } Parameter Passing Convention base of array x[ ]  $a0 base of array y[ ]  $a1 Assumption i  $s0 MIPS assembly: strcpy subi $sp, $sp, 4 # Room in stack for 1 more item sw $s0, 0($sp)# save $s0 into stack add $s0, $zero, $zero# i  0 L1:add $t1, $a1, $s0# $t1  address of y[i] lb $t2, 0($t1)# $t2  y[i] add $t3, $a0, $s0# $t3  address of x[i] sb $t2, 0($t3)# x[i]  y[i] beq $t2, $zero, L2# if y[i] = 0, goto L2 add $s0, $s0, 1# i  i + 1 j L1# go to L1 L2:lw $s0, 0($sp)# restore $s0 addi $sp, $sp, 4# pop one word off stack jr $ra# return Patt.-Hen., pp 143

63 CMPUT 229 - Computer Organization and Architecture I63 A Procedure that Doesn’t Call Another Procedure Parameter Passing Convention base of array x[ ]  $a0 base of array y[ ]  $a1 Assumption i  $s0 MIPS assembly: strcpy subi $sp, $sp, 4 # Room in stack for 1 more item sw $s0, 0($sp)# save $s0 into stack add $s0, $zero, $zero# i  0 L1:add $t1, $a1, $s0# $t1  address of y[i] lb $t2, 0($t1)# $t2  y[i] add $t3, $a0, $s0# $t3  address of x[i] sb $t2, 0($t3)# x[i]  y[i] beq $t2, $zero, L2# if y[i] = 0, goto L2 add $s0, $s0, 1# i  i + 1 j L1# go to L1 L2:lw $s0, 0($sp)# restore $s0 addi $sp, $sp, 4# pop one word off stack jr $ra# return save $s0 in stack void strcpy ( char x[ ], char y[ ]) { int i; i = 0; while ((x[i] = y[i]) != 0) i = i + 1; } Patt.-Hen., pp 143

64 CMPUT 229 - Computer Organization and Architecture I64 A Procedure that Doesn’t Call Another Procedure Parameter Passing Convention base of array x[ ]  $a0 base of array y[ ]  $a1 Assumption i  $s0 MIPS assembly: strcpy subi $sp, $sp, 4 # Room in stack for 1 more item sw $s0, 0($sp)# save $s0 into stack add $s0, $zero, $zero# i  0 L1:add $t1, $a1, $s0# $t1  address of y[i] lb $t2, 0($t1)# $t2  y[i] add $t3, $a0, $s0# $t3  address of x[i] sb $t2, 0($t3)# x[i]  y[i] beq $t2, $zero, L2# if y[i] = 0, goto L2 add $s0, $s0, 1# i  i + 1 j L1# go to L1 L2:lw $s0, 0($sp)# restore $s0 addi $sp, $sp, 4# pop one word off stack jr $ra# return save $s0 in stack i  0 void strcpy ( char x[ ], char y[ ]) { int i; i = 0; while ((x[i] = y[i]) != 0) i = i + 1; } Patt.-Hen., pp 143

65 CMPUT 229 - Computer Organization and Architecture I65 A Procedure that Doesn’t Call Another Procedure Parameter Passing Convention base of array x[ ]  $a0 base of array y[ ]  $a1 Assumption i  $s0 MIPS assembly: strcpy subi $sp, $sp, 4 # Room in stack for 1 more item sw $s0, 0($sp)# save $s0 into stack add $s0, $zero, $zero# i  0 L1:add $t1, $a1, $s0# $t1  address of y[i] lb $t2, 0($t1)# $t2  y[i] add $t3, $a0, $s0# $t3  address of x[i] sb $t2, 0($t3)# x[i]  y[i] beq $t2, $zero, L2# if y[i] = 0, goto L2 add $s0, $s0, 1# i  i + 1 j L1# go to L1 L2:lw $s0, 0($sp)# restore $s0 addi $sp, $sp, 4# pop one word off stack jr $ra# return save $s0 in stack i  0 x[i]  y[i] void strcpy ( char x[ ], char y[ ]) { int i; i = 0; while ((x[i] = y[i]) != 0) i = i + 1; } Patt.-Hen., pp 143

66 CMPUT 229 - Computer Organization and Architecture I66 A Procedure that Doesn’t Call Another Procedure Parameter Passing Convention base of array x[ ]  $a0 base of array y[ ]  $a1 Assumption i  $s0 MIPS assembly: strcpy subi $sp, $sp, 4 # Room in stack for 1 more item sw $s0, 0($sp)# save $s0 into stack add $s0, $zero, $zero# i  0 L1:add $t1, $a1, $s0# $t1  address of y[i] lb $t2, 0($t1)# $t2  y[i] add $t3, $a0, $s0# $t3  address of x[i] sb $t2, 0($t3)# x[i]  y[i] beq $t2, $zero, L2# if y[i] = 0, goto L2 add $s0, $s0, 1# i  i + 1 j L1# go to L1 L2:lw $s0, 0($sp)# restore $s0 addi $sp, $sp, 4# pop one word off stack jr $ra# return save $s0 in stack y[i] = 0? i  0 x[i]  y[i] void strcpy ( char x[ ], char y[ ]) { int i; i = 0; while ((x[i] = y[i]) != 0) i = i + 1; } Patt.-Hen., pp 143

67 CMPUT 229 - Computer Organization and Architecture I67 A Procedure that Doesn’t Call Another Procedure Parameter Passing Convention base of array x[ ]  $a0 base of array y[ ]  $a1 Assumption i  $s0 MIPS assembly: strcpy subi $sp, $sp, 4 # Room in stack for 1 more item sw $s0, 0($sp)# save $s0 into stack add $s0, $zero, $zero# i  0 L1:add $t1, $a1, $s0# $t1  address of y[i] lb $t2, 0($t1)# $t2  y[i] add $t3, $a0, $s0# $t3  address of x[i] sb $t2, 0($t3)# x[i]  y[i] beq $t2, $zero, L2# if y[i] = 0, goto L2 add $s0, $s0, 1# i  i + 1 j L1# go to L1 L2:lw $s0, 0($sp)# restore $s0 addi $sp, $sp, 4# pop one word off stack jr $ra# return i  i + 1 save $s0 in stack no y[i] = 0? i  0 x[i]  y[i] void strcpy ( char x[ ], char y[ ]) { int i; i = 0; while ((x[i] = y[i]) != 0) i = i + 1; } Patt.-Hen., pp 143

68 CMPUT 229 - Computer Organization and Architecture I68 A Procedure that Doesn’t Call Another Procedure Parameter Passing Convention base of array x[ ]  $a0 base of array y[ ]  $a1 Assumption i  $s0 MIPS assembly: strcpy subi $sp, $sp, 4 # Room in stack for 1 more item sw $s0, 0($sp)# save $s0 into stack add $s0, $zero, $zero# i  0 L1:add $t1, $a1, $s0# $t1  address of y[i] lb $t2, 0($t1)# $t2  y[i] add $t3, $a0, $s0# $t3  address of x[i] sb $t2, 0($t3)# x[i]  y[i] beq $t2, $zero, L2# if y[i] = 0, goto L2 add $s0, $s0, 1# i  i + 1 j L1# go to L1 L2:lw $s0, 0($sp)# restore $s0 addi $sp, $sp, 4# pop one word off stack jr $ra# return i  i + 1 save $s0 in stack no y[i] = 0? yes restore $s0 return i  0 x[i]  y[i] void strcpy ( char x[ ], char y[ ]) { int i; i = 0; while ((x[i] = y[i]) != 0) i = i + 1; } Patt.-Hen., pp 143

69 CMPUT 229 - Computer Organization and Architecture I69 Immediate Operands Often times we need to add a known constant to a register addi$sp, $sp, 4# $sp  $sp + 4 529 4 OpCodersrtimmediate 00010111101 0000 0000 0000 0100 31 2615 020 1625 21 R29 = $sp Patt.-Hen., pp 145

70 CMPUT 229 - Computer Organization and Architecture I70 Comparing with Non-Zero Constants We also may need to compare the value stored in a register with a non-zero constant. For this we use the set-less-than immediate instruction: slti$t0, $s2, 10# if $s2 < 10 then $t0  1 else $t0  0 Patt.-Hen., pp 146

71 CMPUT 229 - Computer Organization and Architecture I71 Operating with Bigger constants addi$t0, $zero, # $t0  0 + If we want to load a constant into register $t0, we can use the following addi instruction Which is represented by the following binary representation 508 OpCodersrtimmediate 0001010000001000sccc cccc cccc cccc 31 2615 020 1625 21 What do we do when we want to load a constant whose value needs more than 16 bits to be represented? The constant will be sign extend, thus after this instruction, $t0 will contain ssss ssss ssss ssss sccc cccc cccc cccc Patt.-Hen., pp 147

72 CMPUT 229 - Computer Organization and Architecture I72 Load Upper Immediate For this situation MIPS has the load upper immediate instruction that loads a 16 bit constant into the upper half word of a register: lui$t0, 255# ($t0 is register R8) Which is represented by the following binary representation 508255 OpCodersrtimmediate 00010111101010000000 0000 1111 1111 31 2615 020 1625 21 After this lui instruction, the register $t0 constains: 0000 0000 1111 1111 0000 0000 0000 0000 upper halflower half Patt.-Hen., pp 147

73 CMPUT 229 - Computer Organization and Architecture I73 Example Write two MIPS instruction that will load the constant 64  1024+1 = 65536 +1 = 65537 into register $t0.

74 CMPUT 229 - Computer Organization and Architecture I74 Pseudo-Instruction A pseudo-instruction is an instruction that are accepted by the MIPS assembler, but that does not exist in the MIPS architecture. Example: The MIPS architecture does not have an instruction to move the content of register $t1 into register $t0. But the MIPS assembler accepts the following instruction: move$t0, $t1# $t0  $t1 Whenever the MIPS assembler encounters this instruction in an assembly program, it automatically transforms it into: add$t0, $zero, $t1# $t0  $t1 Patt.-Hen., pp 157

75 CMPUT 229 - Computer Organization and Architecture I75 Pseudo-Instruction Other examples include the bgt, bge, and ble branch instructions. For instance the instruction: blt$s5, $t2, Exit Is converted into the following instructions: slt$at, $s5, $t2 bne$at, $zero, Exit Where $at is an assembler temporary register reserved for the use of the assembler for conversion of pseudo-instructions into real instructions.

76 Patt-Hen., pp. 152


Download ppt "CMPUT 229 - Computer Organization and Architecture I1 CMPUT229 - Fall 2003 Topic4: Procedures José Nelson Amaral."

Similar presentations


Ads by Google