Lecture_3_new - Lecture 3 Instruction Set Architecture (II)...

Info iconThis preview shows pages 1–9. Sign up to view the full content.

View Full Document Right Arrow Icon
Lecture 3 Instruction Set Architecture (II) 1
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Procedures ± int f1 (int i, int j, int k, int g) :::: ll { :::: add $3, $4, 1; return 1; callee } int f2 (int s1, int s2) ll { :::::: dd 3 4 $3 caller add $3, $4, $3 i = f1 (3,4,5, 6); add $2, $3, $3 :::: } ow to pass parameters & results? 2 ± How to pass parameters & results? ± How to preserve caller register values? ± How to alter control? (I.e. go to callee, return from callee)
Background image of page 2
Procedures ow to pass parameters & results ± How to pass parameters & results ² $a0-$a3: four argument registers. What if # of parameters is larger than 4? – push to the stack ² $v0-$v1: two value registers in which to return values ± How to preserve caller register values? se tack ² Use stack ² Caller saved register ² Callee saved register ± How to switch control? ² How to go to the callee al procedure address ump and link) ± Jal procedure_address (jump and link) ² Store the the return address (PC +4 ) at $ra ² set PC = procedure_addres ow to return from the callee 3 ² How to return from the callee ² Callee exectues jr $ra
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Procedure Call Stack (Frame) ::::::::::::: Higher memory address ::::::::::::::: $fp saved argument registers Procedure Frame Saved callee saved registers Stack grows saved return registers g Local arrays and structures $sp Lower memory address 4 • Frame pointer points to the first word of the procedure frame
Background image of page 4
Procedure Call Stack (Frame) $fp Æ $fp Æ $sp Æ $fp Æ $sp Æ $sp Æ f th d ll d i th d ll ft th d ll 5 Before the procedure call during the procedure call after the procedure call
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Procedure Calling Convention ± Calling Procedure ² Step-1: pass the argument ² Step-2: save caller-saved registers ² Step-3: Execute a jal instruction :::::::: $a0 4 foo1 () passing argument li $a0, 4 sw $t3, 4($sp) # save $t3 jal foo $t3 4($sp) # restore $t3 { :::::::: i= i+1; x=foo(4); # passing argument lw $t3, 4($sp) # restore $t3 add $t3, $v0, $t3 () ; i = x + i } 6 ::::::
Background image of page 6
Procedure Calling Convention alled Procedure bi $ $ 32 ± Called Procedure ² Step-1: establish stack frame ± subi $sp, $sp <frame-size> subi $sp, $sp, 32 sw $ra, 20($sp) sw $fp, 16($sp) di $fp $sp 28 ² Step-2: saved callee saved registers ± $ra, $fp,$s0-$s7 addi $fp, $sp, 28 ::::: ::::: ::: ² Step-3: establish frame pointer ± Add $fp, $sp, <frame-size>-4 n return from a call ::::: addi $v0, $zero, 1 $fp, 16($sp) ± On return from a call ² Step-1: put returned values in gister $v0 $v1 lw lw $ra, 20($sp) addi $sp, $sp,32 jr $ra register $v0, $v1. ² Step-2: restore callee-saved registers tep- : pop the stack 7 ² Step 3: pop the stack ² Step-4: return: jr $ra
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
reserved Registers 0 zero constant 0 Preserved Registers 16 s0 callee saves 1 at reserved for assembler 2 v0 expression evaluation & . . . 23 s7 3 v1 function results 4 a0 arguments 1 24 t8 temporary (cont d) 25 t9 6 0 served for OS kernel 5 a1 6a 2 3 26 k0 reserved for OS kernel 27 k1 8 p ointer to global area 7 a3 8 t0 temporary: caller saves 28 gp Pointer to global area 29 sp Stack pointer 0 ame pointer . . .
Background image of page 8
Image of page 9
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 43

Lecture_3_new - Lecture 3 Instruction Set Architecture (II)...

This preview shows document pages 1 - 9. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online