Motorola M68000 User's Guide Page 115

  • Download
  • Add to my manuals
  • Print
  • Page
    / 256
  • Table of contents
  • BOOKMARKS
  • Rated. / 5. Based on customer reviews
Page view 114
Subroutines 101
JSR BIGEST
JSR BIGEST
Each time the JSR instruction is executed, the instructions of the subrou
tine BIGEST are executed. How does the program find these instructions?
The label BIGEST is used to tell the JSR instruction where to find the
subroutine. This can be thought of as equivalent to a simple JMP BIGEST
instruction. So far this is easy. But now consider what happens after the
steps of BIGEST are executed. How do we get back to the instruction
after the JSR? Which JSR? There may be quite a few. The answer lies
with the use of the stack and the RTS instruction.
Prior to transferring control to the subroutine, the JSR instruction
places the address of the instruction that immediately follows the JSR
instruction itself on the stack. This is the instruction that should be
executed when the instructions of the subroutine are completed. When
the RTS instruction is executed in the subroutine, this return address is
popped from the stack and placed in the program counter (PC). This
acts like another JMP instruction. Now control returns to the part of
the program that called the subroutine, with execution continuing at the
proper instruction. Figure 8 shows the sequence of events for a typical
subroutine call.
Figure 8 Subroutine call. END
Page view 114
1 2 ... 110 111 112 113 114 115 116 117 118 119 120 ... 255 256

Comments to this Manuals

No comments