Assembler trick: call by falling through

On several occasions, when programming in assembler, we meet this sequence where the last instruction of a subroutine is a call immediately followed by a return instruction.

my_subroutine1:
;some instructions
call my_function1
ret

my_function1:
;some instructions
ret

The routine ‘my_function1’ can be implemented directly inline:

my_subroutine1:
;some instructions

        ;call by falling through
my_function1:
;some instructions
ret     ;reuse the return instruction for my_subroutine1

 

 

 

 

Advertisements
This entry was posted in Software and tagged , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s