;***************************************************************** ;* This stationery serves as the framework for a * ;* user application (single file, absolute assembly application) * ;* For a more comprehensive program that * ;* demonstrates the more advanced functionality of this * ;* processor, please see the demonstration applications * ;* located in the examples subdirectory of the * ;* Freescale CodeWarrior for the HC12 Program directory * ;***************************************************************** ; export symbols XDEF Entry, _Startup ; export 'Entry' symbol ABSENTRY Entry ; for absolute assembly: mark this as application entry point ; Include derivative-specific definitions INCLUDE 'derivative.inc' ROMStart EQU $4000 ; absolute address to place my code/constant data ; variable/data section ORG RAMStart ; Start data at $1000 ; Insert here your data definition. Counter DC.W 10 ; Fibonacci number to compute: Fibonacci(10), must be greater or equal than 1 FiboRes DS.W 1 ; 1 word (16 bits) reserved for the result ; code section ORG ROMStart Entry: _Startup: LDS #RAMEnd+1 ; initialize the stack pointer. SP <- $3FFF+1 mainLoop: LDX Counter ; X contains counter CPX #24 bhi mainLoop ; larger values than 24 cause overflow! BSR CalcFibo STD FiboRes ; store result BRA mainLoop ; restart. ; ==================================================================== ; Subroutines ; ==================================================================== CalcFibo: ; Function to calculate fibonacci numbers. Argument is in X. pshx LDY #$00 ; second last LDD #$01 ; last DBEQ X,FiboDone ; loop once more (if X was 1, were done already) FiboLoop: LEAY D,Y ; overwrite second last with new value EXG D,Y ; exchange them -> order is correct again DBNE X,FiboLoop FiboDone: pulx RTS ; result in D