Chapter 7 B
Chapter 7 B
l PUSH
l Increment the memory address in the stack pointer (by
one) and stores the contents of the counter (PC+2) on the
top of the stack
l POP
l Discards the address of the top of the stack and
decrement the stack pointer by one
l The contents of the stack (21-bit address), pointed
by the stack pointer, are copied into three special
function registers
l TOSU (Top-of-Stack Upper), TOSH (High), and TOSL (Low)
TOSU TOSH TOSL
Instructions to Store and Retrieve Information
from the Stack
l What
is the value of PC, TOSU/H/L and
STKPTR as you execute each line?
nPC TOS STKPTR W
22 0 0 00
24 0 0 20
26 26 1 20
28 28 2 20
2A 26 1 20
2C 0 0 20
Subroutine Call
Org 0x40
2-Word Instructions
Parameter Passing
Before MAIN
MACRO Application
l Note COUNT is not defined in the MARCO
l It is the "arg” of the MACRO
l MACRO is assembled after every instance it is called
MACRO Application
l Reading/writing
values from/into the
program memory one byte at a time
TBLWT* / TBLWT*+ / TBLWT*-
Table Latch (8-bit)
Write into Memory
TBLPTR(U/H/L)= 00 00 40
0x000040 0x0002 TABLAT=0x02
Pointing to the address
Program
Memory W=0x02
(16-bit)
REG10=0x02
Table Example LAB: Modify this program such that
values 0xaa, 0xbb, 00cc stored in the
program memory are copied into
REG60,61,62, respectively
TBLPTR = 00 00 40
0x000040 0x0002 TABLAT=0x02
Pointing to the address
Program
Memory W=0x02
(16-bit)
REG10=0x02
Examine this code:
Reference: Huang
Division By Subtraction
References
l http://www.ece.msstate.edu/~reese/
ece3724/lectures/chap6_subr_ptrs.pdf
Subroutine Documentation and
Parameter Passing
l Parameter passing
l Information exchanged between a calling program and a
subroutine
l Subroutine documentation should include:
l Function of a subroutine: Brief description of what it does
l Input parameters: Information that should be provided by
calling program to subroutine
l Output parameters: Information or results provided by
subroutine to calling program
l Registers modified: List of registers changed by the
subroutine
l List of subroutines called: List of other subroutines called by
the called subroutine