simple subroutine linkage n.
Download
Skip this Video
Loading SlideShow in 5 Seconds..
Simple Subroutine Linkage PowerPoint Presentation
Download Presentation
Simple Subroutine Linkage

Loading in 2 Seconds...

play fullscreen
1 / 14

Simple Subroutine Linkage - PowerPoint PPT Presentation


  • 152 Views
  • Uploaded on

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

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'Simple Subroutine Linkage' - drea


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.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
function calls
Function Calls
  • Function callsimplemented as jumps
generality
Generality
  • Function called from more than one place can't hardcode return jump

Infinite loop…

slide4
JAL
  • jal: Jump And Link
    • Store "next" instruction to $ra register
      • Next instruction is one after branch delay currentAddress+8
slide5
JR
  • jr : Jump Register
    • Jump to address stored in register
calling convention
Calling Convention
  • Calling Convention
    • Agreement for howsubroutines work
      • How we pass info
      • What registers wecan use
    • Differs betweenplatforms,compilers, etc…
simple linkage
Simple Linkage
  • Simple Linkage Convention:
    • jal/jr
    • Registers usage:
simple function
Simple function
  • Read an integer:

intgetInt();

readIntsSimple.mas

with parameter
With parameter
  • Read an integer with parameter:

intgetInt(char* prompt);

readIntsParameter.mas

multi paramer function
Multi-Paramer Function
  • Read an integer with parameter:

intaddThree(int x, int y, int z);

readIntsSumFunction.mas

nested function calls
Nested Function Calls
  • An attempt tocall one functionfrom another:
nested workaround
Nested Workaround
  • One possible workaround…
    • Store our return address before calling other function
nested workaround1
Nested Workaround
  • Limitations:
    • What if other function messes with registers?
    • Still can't handle recursive functions