Quantcast
Channel: stardot.org.uk
Viewing all articles
Browse latest Browse all 2528

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

$
0
0
So here's a version that changes the procedure that prints the stack into a function, so we can call it from within an expression:

Code:

  680 NEXT  690 PRINT 1+(2*(3-(4/(5+(6*(7-(8+(10+(12/(1+FNstack))))))))))  700 END  710 DEF FNstack  720 PRINT '"S=";  730 CALL pstack  740 PRINT '"BSP=";  750 CALL bstack  760 =1
and the result of running it:
stack5.png
What happens if we use USR to call the stack printing? For this version I will include the full program because I have added some code to the assembler to print the 'S=' and 'BSP=' labels. That way we don't need to call a BASIC PRINT statement from the middle of an expression.

Code:

   10 REM > STACK2   20 OSWRCH=&FFEE   30 OSNEWL=&FFE7   40 DIM C% 200   50 FOR N%=0 TO 3 STEP 3   60   P%=C%   70   [OPT N%   80   .hexout   90   PHA  100   LSR A  110   LSR A  120   LSR A  130   LSR A  140   JSR hexnyb  150   PLA  160   AND #&0F  170   .hexnyb  180   CMP #10  190   BCC hexskp  200   ADC #&06  210   .hexskp  220   ADC #&30  230   JMP OSWRCH  240   .pstack  250   LDA #ASC("S")  260   JSR OSWRCH  270   LDA #ASC("=")  280   JSR OSWRCH  290   TSX  300   TXA  310   JSR hexout  320   JSR OSNEWL  330   INX  340   BEQ stkdone  350   .stkloop  360   LDA &0100,X  370   JSR hexout  380   LDA #&20  390   JSR OSWRCH  400   INX  410   BNE stkloop  420   .stkdone  430   JMP OSNEWL  440   .both  450   JSR pstack  460   .bstack  470   LDA #ASC("B")  480   JSR OSWRCH  490   LDA #ASC("S")  500   JSR OSWRCH  510   LDA #ASC("P")  520   JSR OSWRCH  530   LDA #ASC("=")  540   JSR OSWRCH  550   LDA &05  560   STA &71  570   JSR hexout  580   LDA &04  590   STA &70  600   JSR hexout  610   JSR OSNEWL  620   LDY #&00  630   .bloop  640   LDA &70  650   CMP &06  660   BNE bcont  670   LDA &71  680   CMP &07  690   BEQ bdone  700   .bcont  710   LDA (&70),y  720   JSR hexout  730   LDA #&20  740   JSR OSWRCH  750   INC &70  760   BNE bloop  770   INC &71  780   BNE bloop  790   .bdone  800   JMP OSNEWL  810   ]  820 NEXT  830 PRINT 1+(2*(3-(4/(5+(6*(7-(8+(10+(12/(USRboth))))))))))  840 END
stack6.png
This shows how the highly nested brackets have push a lot onto the machine stack. In the earlier example, when we called a BASIC FN from within the expression, the FN/PROC call mechanism had moved much of that to the BASIC stack.

Statistics: Posted by Coeus — Sat Feb 15, 2025 12:34 am



Viewing all articles
Browse latest Browse all 2528

Trending Articles