How to resolve the algorithm Towers of Hanoi step by step in the PL/M programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Towers of Hanoi step by step in the PL/M programming language

Table of Contents

Problem Statement

Solve the   Towers of Hanoi   problem with recursion.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Towers of Hanoi step by step in the PL/M programming language

Source code in the pl/m programming language

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

  

You may also check:How to resolve the algorithm Range expansion step by step in the Ada programming language
You may also check:How to resolve the algorithm Modular inverse step by step in the dc programming language
You may also check:How to resolve the algorithm Rock-paper-scissors step by step in the Nim programming language
You may also check:How to resolve the algorithm Sum and product of an array step by step in the PicoLisp programming language
You may also check:How to resolve the algorithm Stem-and-leaf plot step by step in the Raku programming language