4-13
PROGRAMMING CONSIDERATIONS
4.5.4
Linking Subroutines
Parameters are passed to subroutines via the stack. Parameters are pushed into the stack from the
rightmost parameter to the left. The 8-bit parameters are pushed into the stack with the high-order
byte undefined. The 32-bit parameters are pushed onto the stack as two 16-bit values; the most-
significant half of the parameter is pushed into the stack first. As an example, consider the fol-
lowing procedure:
void example_procedure (char param1, long param2, int param3);
When this procedure is entered at run-time, the stack will contain the parameters in the following
order:
If a procedure returns a value to the calling code (as opposed to modifying more global variables)
the result is returned in the temporary storage space (TMPREG0, in this example) starting at 1CH.
TMPREG0 is viewed as either an 8-, 16-, 32-, or 64-bit variable, depending on the type of the
procedure.
The standard calling convention adopted by the C programming language has several key fea-
tures:
•
Procedures can always assume that the eight or sixteen bytes of register file memory
starting at 1CH can be used as temporary storage within the body of the procedure.
•
Code that calls a procedure must assume that the procedure modifies the eight or sixteen
bytes of register file memory starting at 1CH.
•
Code that calls a procedure must assume that the procedure modifies the processor status
word (PSW) condition flags because procedures do not save and restore the PSW.
•
Function results from procedures are always returned in the variable TMPREG0.
The C programming language allows the definition of interrupt procedures, which are executed
when a predefined interrupt request occurs. Interrupt procedures do not conform to the rules of
normal procedures. Parameters cannot be passed to these procedures and they cannot return re-
sults. Since interrupt procedures can execute essentially at any time, they must save and restore
both the PSW and TMPREG0.
param3
low word of param2
high word of param2
undefined;param1
return address
←
Stack Pointer
Summary of Contents for 80C196NU
Page 1: ...8XC196NP 80C196NU Microcontroller User s Manual...
Page 2: ...8XC196NP 80C196NU Microcontroller User s Manual August 1995 Order Number 272479 002...
Page 18: ...1 Guide to This Manual...
Page 19: ......
Page 31: ......
Page 32: ...2 Architectural Overview...
Page 33: ......
Page 48: ...3 Advanced Math Features...
Page 49: ......
Page 56: ...4 Programming Considerations...
Page 57: ......
Page 72: ...5 Memory Partitions...
Page 73: ......
Page 106: ...6 Standard and PTS Interrupts...
Page 107: ......
Page 144: ...7 I O Ports...
Page 145: ......
Page 165: ......
Page 166: ...8 Serial I O SIO Port...
Page 167: ......
Page 183: ......
Page 184: ...9 Pulse width Modulator...
Page 185: ......
Page 196: ...10 Event Processor Array EPA...
Page 197: ......
Page 225: ......
Page 226: ...11 Minimum Hardware Considerations...
Page 227: ......
Page 239: ......
Page 240: ...12 Special Operating Modes...
Page 241: ......
Page 255: ......
Page 256: ...13 Interfacing with External Memory...
Page 257: ......
Page 303: ......
Page 304: ...A Instruction Set Reference...
Page 305: ......
Page 373: ......
Page 374: ...B Signal Descriptions...
Page 375: ......
Page 390: ...C Registers...
Page 391: ......
Page 447: ......
Page 448: ...Glossary...
Page 449: ......
Page 458: ...Index...
Page 459: ......