
Application Note
AN1218 Rev. 2
40
***** Load up stack before entering the subroutine
* Stack is given the 8-bit number to be cubed, X_IN
* Next, 3 bytes must be made available to the stack
* for the 24 bit output of the routine
* 3 pushes are made to illustrate this point
START LDA X_IN ;A
←
(X_IN)
PSHA ;push parameter X_IN onto stack
CLRA ;zero must be pushed on stack
; allocation for return answer
PSHA ;push Y_Low byte onto stack
PSHA ;push Y_Med byte onto stack
PSHA ;push Y_High byte onto stack
***** Jump to the cube subroutine
JSR CUBE ;jump sub to CUBE, Y = X_IN^3
*****
* location. Pull the answers off the stack when needed.
When subroutine is over, reset stack pointer to original
AIS #$04 ;SP
←
(SP) + $04
BRA DONE ;branch to the end of this
;example
***** CUBE subroutine
***** Given X_IN, find Y = X^3
* Save X,H, and A on stack
* Decrement stack for 2 bytes
CUBE PSHX ;push X onto stack
PSHH ;push H onto stack
PSHA ;push A onto stack
AIS #-2 ;decrement stack for local var
* Run the math routine
* Square X_IN, answer is X:A
LDA 11T,SP ;A = X_IN
LDX 11T,SP ;X = X_IN
MUL ;X:A = (X)*(A)
* Store away the high byte answer, X, to var1
STX 1,SP ;store high answ to var1
* Multiply 16 bit result by X_IN
* Multiply X_IN by low byte of 16-bit square
LDX 11T,SP ;X = X_IN
MUL ;X:A = (X)*(A)
F
Freescale Semiconductor, Inc.
For More Information On This Product,
Go to: www.freescale.com
n
.