Ch10 The STACK and Subroutines Slides
Ch10 The STACK and Subroutines Slides
10.1 THE
CH. 10: THE STACK AND SUBROUTINES
10.1 THE
CH. 10: THE STACK AND SUBROUTINES
10.1 THE
CH. 10: THE STACK AND SUBROUTINES
10.1 THE
CH. 10: THE STACK AND SUBROUTINES
10.1 THE
CH. 10: THE STACK AND SUBROUTINES
SP
10.1 THE
CH. 10: THE STACK AND SUBROUTINES
- .w: SP – 2 SP
SP
- .w: SP + 2 SP
10.1 THE
CH. 10: THE STACK AND SUBROUTINES
10.1 THE
CH. 10: THE STACK AND SUBROUTINES
SP
10.1 THE
CH. 10: THE STACK AND SUBROUTINES
10.1 THE
CH. 10: THE STACK AND SUBROUTINES
Step 2: Type in the following code into the main.asm file where the
comments say “Main loop here.”
Image Courtesy of
Recording Connection of Canada
10.1 THE
CH. 10: THE STACK AND SUBROUTINES
Step 5: Open the Register Viewer so that you can see SP and
R4 → R7. Open the Memory Browser and go to 0x3000. Then scroll up
so you can see the values 2FFEh and 2FFCh.
Image Courtesy of
Recording Connection of Canada
10.1 THE
CH. 10: THE STACK AND SUBROUTINES
10.1 THE
EMBEDDED SYSTEMS DESIGN
www.youtube.com/c/DigitalLogicProgramming_LaMeres
10.2 SUBROUTINES
• Subroutine – a piece of code
that will be used repeatedly in a
program; typically accomplishes
a very specific task.
10.2
CH. 10: THE STACK AND SUBROUTINES
10.2 SUBROUTINES
• Whenever the subroutine is
needed, it can be executed by
jumping to it.
10.2
CH. 10: THE STACK AND SUBROUTINES
10.2 SUBROUTINES
• A subroutine starts with an
address label to mark its
location in memory.
• Additional steps must be taken
when jumping to a subroutine
because while the starting
address of the subroutine is
always the same, the return
address in the main program Main Program
will vary depending on where
in the main program it is called. Subroutine 1
Subroutine 2
10.2
CH. 10: THE STACK AND SUBROUTINES
10.2 SUBROUTINES
• Call – instruction that is used
to jump to the subroutine
address label and handles
storing the return address on
the stack prior to jumping to
the subroutine address.
10.2
CH. 10: THE STACK AND SUBROUTINES
10.2 SUBROUTINES
• Variables can be passed to subroutines using three different
approaches:
Image Courtesy of
Recording Connection of Canada
10.2
CH. 10: THE STACK AND SUBROUTINES
10.1 THE
CH. 10: THE STACK AND SUBROUTINES
Step 2: Type in the following code into the main.asm file where the
comments say “Main loop here.”
Image Courtesy of
Recording Connection of Canada
10.2
CH. 10: THE STACK AND SUBROUTINES
Step 5: Open the Register Viewer so that you can see PC, SP, and R4.
Open the Memory Browser and go to 0x3000. Then scroll up so you can
see the first location on the stack (address 2FFEh).
Image Courtesy of
Recording Connection of Canada
10.1 THE
CH. 10: THE STACK AND SUBROUTINES
10.1 THE
CH. 10: THE STACK AND SUBROUTINES
Image Courtesy of
Recording Connection of Canada
10.1 THE
EMBEDDED SYSTEMS DESIGN
www.youtube.com/c/DigitalLogicProgramming_LaMeres