Coding techniques - Recursion.

ZX Magazine #07
 /----------------                
 | Coding Techniques |                
 ----------------/                
                                          
 Excursion to recursion (ts) Radio amateur VK 
                                          
  And so, what kind of beast is recursion and with
what do they eat it with? Recursion is a challenge
program itself. So it's the simplest
recursion- 10 GO SUB 10 .                  
  However, from the recursion there must be some
way out, otherwise what's the point in it?
By the way, I forgot to say that my variables
procedures are not my variables (ts) Some of
great ones.Common, but there is no such thing in Vasik
garbage that would save variables, according to
So let's move on to PASSAL.                 
                                          
  Program recursion;                      
  Procedure rec(n:integer);               
  Begin                                   
   If n>1 then rec(n-1);                  
 WriteLn(n)                             
  End;                                    
  (*Main*)                              
  Begin                                   
   Rec(10)                                
  End.Result: 10 9 8 7 6 5 4 3 2 1          
                                          
  But PASSAL is why PASSAL is because even at
they don't do anything on the pussy, and that's why
Let's switch to assembler.                    
                                          
  "Recursion in assembly language ??? %-|", - Pro-
sit you. “Yeah, why not,” I’ll answer.
I.  Nothing is impossible. For example and
to continue the topic, I’ll give you a small
print library.                       
                                          
  Entry point: BPR, function number in GS.   
                                          
     Let's go!                           
                                          
BPR PUSH BC,DE,HL,AF                 
         LD A,C                           
         SR 1                             
         JR NZ,BPR0                       
         POP AF                           
         PUSH AF                          
         RST #10                          
BPR_ POP AF,HL,DE,BC                  
         RET                              
                                          
BPR0 CP 2                             
         JR NZ,BPR1                       
         LD A,22                          
         LD C,1CALL BPR ;HERE IS THE RECURSION
         LD A,D                           
         CALL BPR                         
         LD A,E                           
         JR BPR                           
                                          
BPR1 LD A,(HL)                        
AND (HL)                         
       JR Z,BPR_                          
         LD C,1                           
         CALL BPR                         
         JR BPR1                          
                                          
  1: Character printing. A = symbol.          
  2:Print installation. B D = X, E = Y.     
  3:Print text, in HL = text address,  
     0 - end marker.                    
                                          
 Looks like that's all :)                       

Share your thoughts about the article