• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Nested subroutines calls processs

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi everyone,
Just come across the subroutines processors mechanism using CALL and RETURN instructions.
My problem is that I don't understand this stacking process when this will apply to nested subroutines,
what will be the return address of a subroutine when the CALL instruction will be executed?
what is the logic chain between CALL and RETURN here?. Any help will be much appreciated.
Thank you.
Marius
 
Saloon Keeper
Posts: 28320
210
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch, Marcus!

When a function is called, several things happen. Generally, working storage items in machine registers will be saved in memory, a block of new working storage sufficient to hold the subroutine's defined local variables is allocated, and the address of the next instruction following the call instruction is saved in memory.

In older machines, these units of storage had to be manually reserved by the compiler-generated code, but most modern-day CPUs are stack-oriented, so they can easily be allocated in an area called the "stack" (or call stack, program stack, etc.) as a unit called a frame woith a single instruction.

You might want to lookup stack frame where you'll probably be able to see graphic visualizations of this process.
 
It's a pleasure to see superheros taking such an interest in science. And this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic