Quantcast
Viewing all articles
Browse latest Browse all 2543

programming • Re: BBC BASIC 8 Bit procedures: large speed overhead, due to recursion support?

As a comparison, I thought I'd check out Z80 BBC BASIC. Here's the Z80 version of the last program, the one with all the brackets:

Code:

   10 OSWRCH=&FFEE   20 OSNEWL=&FFE7   30 DIM C% 200   40 FOR N%=0 TO 3 STEP 3   50   P%=C%   60   [OPT N%   70   .hexout   80   LD   C,A   90   RRA  100   RRA  110   RRA  120   RRA  130   CALL hexnyb  140   LD   A,C  150   .hexnyb  160   AND  &0F  170   ADD  A,&90  180   DAA  190   ADC  A,&40  200   DAA  210   JP   OSWRCH  220   .pstack  230   LD   A,&53  240   CALL OSWRCH  250   LD   A,&50  260   CALL OSWRCH  270   LD   A,&3D  280   CALL OSWRCH  290   LD   HL,&0000  300   ADD  HL,SP  310   LD   DE,&DC00  320   LD   A,H  330   CALL hexout  340   LD   A,L  350   CALL hexout  360   CALL OSNEWL  370   .ploop  380   LD   A,D  390   CP   H  400   JR   NZ,pcont  410   LD   A,E  420   CP   L  430   JR   Z,pdone  440   .pcont  450   LD   B,(HL)  460   INC  HL  470   LD   A,(HL)  480   INC  HL  490   CALL hexout  500   LD   A,B  510   CALL hexout  520   LD   A,&20  530   CALL OSWRCH  540   JR   ploop  550   .pdone  560   JP   OSNEWL  570   ]  580 NEXT  590 PRINT 1+(2*(3-(4/(5+(6*(7-(8+(10+(12/(USRpstack))))))))))
This version prints the stack contents as 16-bit words as all the Z80 PUSH and POP instructions work with 16-bit words. Here's the result of running it:
stack1.png
and here is a revised tail for the recursive function call with passed parameter:

Code:

  590 PROCrecurse(0)  600 END  610 DEF PROCrecurse(R%)  620 IF R%=10 CALL pstack ELSE PROCrecurse(R%+1)  630 ENDPROC
which gives this output:
stack2.png
This looks to me to be using the machine stack for more and has probably dispensed with the separate stack for BASIC. The Z80 has a 16-bit stack point so the stack is not restricted to 256 bytes and can grow down from HIMEM while the program and variables grow up from PAGE.

Statistics: Posted by Coeus — Mon Feb 17, 2025 1:00 am



Viewing all articles
Browse latest Browse all 2543

Trending Articles