Learn the HC11 assembly recursive application by instance

zhaozj2021-02-11  227

Recurrence is an important technique in the advanced language. It is more basic in Functional Language, but rarely uses directly in assembly language. Most compilers are automatically converted into loops when the recursive function is encountered. However, it is important to understand how to use recursive in assembly.

I have talked about how to use the recursive calculation of Sigmarx using the SBC, and interested friends can take a look here. Stack is an important element in recursive, all temporary results are temporarily saved in the stack, then push it again step by step. The operation of Sigmarx on HC11 is implemented using recursive syntax:

Function: sigmarx; sigmarx (n) = n sigmarx (n-2), sigmarx (0) = 0, sigmarx (1) = 1; N is located in b; return value is located in IX Sigmarx: CMPB # 0; 1st Base Case , IF n = 0 BGT CONE; if n> 0 Check 2nd base case ldx # 0; else retun value is 0 rts conong # 1; 2nd base case bgt reccCall; if n> 1 goto recursive part ldx # 1; Else RETURN VALUE IS 1 RTS Recall: Pshb; Save Parameter on The Stack Decb Decb JSR SigmarX; Recursive Call Pulb; Restore The Value from The Stack ABX; ABX Will Do ix = IX B RTS

It's as simple, and each time you save the parameters, the calculation results are put on IX.

转载请注明原文地址:https://www.9cbs.com/read-5015.html

New Post(0)