Task

Solve the   Towers of Hanoi   problem with recursion.




100H: /* ITERATIVE TOWERS OF HANOI; TRANSLATED FROM TINY BASIC (VIA ALGOL W) */
 
   /* CP/M BDOS SYSTEM CALL                                                  */
   BDOS: PROCEDURE( FN, ARG ); DECLARE FN BYTE, ARG ADDRESS; GOTO 5; END;
   /* I/O ROUTINES                                                           */
   PR$CHAR:   PROCEDURE( C ); DECLARE C BYTE;    CALL BDOS( 2, C );  END;
   PR$STRING: PROCEDURE( S ); DECLARE S ADDRESS; CALL BDOS( 9, S );  END;
 
   DECLARE ( D, N, X, S, T ) ADDRESS;
   /* FIXED NUMBER OF DISCS: 4 */
   N = 1;
   DO D = 1 TO 4;
       N = N + N;
   END;
   DO X = 1 TO N - 1;
       /* AS IN ALGOL W, WE CAN USE PL/M'S BIT ABD MOD OPERATORS             */
       S =   ( X AND ( X - 1 ) )       MOD 3;
       T = ( ( X OR  ( X - 1 ) ) + 1 ) MOD 3;
       CALL PR$STRING( .'MOVE DISC ON PEG $' );
       CALL PR$CHAR( '1' + S );
       CALL PR$STRING( .' TO PEG $' );
       CALL PR$CHAR( '1' + T );
       CALL PR$STRING( .( 0DH, 0AH, '$' ) );
   END;
EOF