1 / 14

Simple Subroutine Linkage

Simple Subroutine Linkage. Function Calls. Function calls implemented as jumps. Generality. Function called from more than one place can't hardcode return jump. Infinite loop…. JAL. jal : Jump And Link Store "next" instruction to $ ra register

drea
Download Presentation

Simple Subroutine Linkage

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. Simple Subroutine Linkage

  2. Function Calls • Function callsimplemented as jumps

  3. Generality • Function called from more than one place can't hardcode return jump Infinite loop…

  4. JAL • jal: Jump And Link • Store "next" instruction to $ra register • Next instruction is one after branch delay currentAddress+8

  5. JR • jr : Jump Register • Jump to address stored in register

  6. Calling Convention • Calling Convention • Agreement for howsubroutines work • How we pass info • What registers wecan use • … • Differs betweenplatforms,compilers, etc…

  7. Simple Linkage • Simple Linkage Convention: • jal/jr • Registers usage:

  8. Simple function • Read an integer: intgetInt(); readIntsSimple.mas

  9. With parameter • Read an integer with parameter: intgetInt(char* prompt); readIntsParameter.mas

  10. Multi-Paramer Function • Read an integer with parameter: intaddThree(int x, int y, int z); readIntsSumFunction.mas

  11. Nested Function Calls • An attempt tocall one functionfrom another:

  12. Nested Function Calls • What we got

  13. Nested Workaround • One possible workaround… • Store our return address before calling other function

  14. Nested Workaround • Limitations: • What if other function messes with registers? • Still can't handle recursive functions

More Related