1 / 14

Computer Architecture

Computer Architecture. MIPS Instruction Set Architecture ( Supporting Procedures ). 0 $zero constant 0. 16 $s0 permanent. (For variables in a high-level language program). 1 $at reserved for assembler. · · ·. 2 $v0 return values. 23 $s7. 3 $v1.

reuben
Télécharger la présentation

Computer Architecture

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. Computer Architecture MIPS Instruction Set Architecture ( Supporting Procedures )

  2. 0 $zero constant 0 16 $s0 permanent (For variables in a high-level language program) 1 $at reserved for assembler ··· 2 $v0 return values 23 $s7 3 $v1 24 $t8 temporary 4 $a0 arguments 25 $t9 5 $a1 26 $k0 OS kernel (reserved) 6 $a2 27 $k1 7 $a3 28 $gpglobal pointer 8 $t0 temporary 29 $sp stack pointer · · · 30 $fp frame pointer 15 $t7 31 $ra return address MIPS Register Naming

  3. Calling Convention (Caller Save) Callee Caller • allocate stack frame • save (live) registers • set up arguments • save return address • and jump to the callee • restore saved registers • place return value • free stack frame • restore and jump to the • return address

  4. Calling Convention (Callee Save) Callee Caller • set up arguments • save return address • and jump to the callee • allocate stack frame • save registers(that may • be modified in the callee) • place return value • restore saved registers • free stack frame • restore and jump to the • return address

  5. MIPS Calling Convention (Hybrid) Callee Caller • allocate stack frame: • $sp ← $sp – frame size • save callee-saved registers • (that may be modified in the • callee) : $s0~$s7 • save (live) caller-saved registers: • $t0~$t9, $a0~$a3, $v0~$v1, $ra • set up arguments : first four in • $a0~$a3, rest on stack • execute jal instruction • restore caller-saved registers • place return value in $v0~$v1 • restore callee-saved registers • free stack frame : • $sp ← $sp + frame size • return by jr $ra

  6. MIPS Register Convention 0 $zero constant 0 16 $s0 permanent (callee saves) (For variables in a high-level language program) 1 $at reserved for assembler ··· 2 $v0 function return value 23 $s7 3 $v1 (caller saves) 24 $t8 temporary(caller saves) 4 $a0 arguments (caller saves) 25 $t9 5 $a1 26 $k0 OS kernel (reserved) 6 $a2 27 $k1 7 $a3 28 $gpglobal pointer (caller saves) 8 $t0 temporary (caller saves) 29 $sp stack pointer (preserved) · · · • $fp frame pointer ($s8 for cc) • (callee saves) 15 $t7 31 $ra return address(jal) (caller saves)

  7. Compiling a Leaf Procedure Assembly C int leaf_example ( int g, int h, int i, int j ) { int f ; f = ( g + h ) – ( i + j ); return f; } Actually Not needed

  8. Stack Allocation FIGURE 3.12 Illustration of the stack allocation (a)before, (b)during, and (c)after the procedure call

  9. Compiling a Non-Leaf Procedure C Assembly int nonleaf_example (int arg) { int result; result = arg + leaf_example(5,4,3,2); return result; }

  10. Compiling a Recursive Procedure C Assembly int fact ( int n ) { if ( n < 1 ) return (1) ; else return ( n * fact ( n – 1) ); }

  11. Compiling and Starting a Program

  12. Object File Example

  13. MIPS Memory Allocation

  14. Executable File Example

More Related