*-----------------------------------------------------------* * Program Number: 3 * * Written by : Nathan Balon * * Student # : 3210 1717 * * Class : CIS 310 * * Date Created : 2/20/2004 * * Description : The program is a maze. * * * *-----------------------------------------------------------* ORG $400 BSR PRT_HEAD Print the heading info for program LEA MAZE,A0 load the maze BSR MOVE Recursively move through maze, to get out DONE_MOV BSR PRT_CRLF Print a blank line BSR PRT_ITEM Print a list of all the coordinates moved BSR PRT_CRLF Print a blank line BSR PRT_MAZE Print the map of the maze, with moves as 9's BSR PRT_CRLF Print a blank line EXIT STOP #$2700 Exit the program ***************************************************************** *---------------------------------------------------------------* * * * Sub-routines * * * *---------------------------------------------------------------* ***************************************************************** * *----------------------------------------------------------------* * Move the rat to the next availiable location in the maze. * *----------------------------------------------------------------* MOVE BSR ADD_STK Add initial location CONT_MOV ADDA.W #COLS,A0 Move pointer to the row below MOVE.B (A0),D0 get the contents pointed to by A0 CMP.B #'0',D0 check if it equals 0 BEQ ADD_STK ADDA.W #1,A0 Move the pointer 1 column over MOVE.B (A0),D0 get the contents pointed to by A0 CMP.B #'0',D0 check if it equals 0 BEQ ADD_STK SUBA.L #COLS,A0 Move the pointer up 1 row MOVE.B (A0),D0 get the contents pointed to by A0 CMP.B #'0',D0 check if it equals 0 BEQ ADD_STK LEA NO_OUT,A1 If this location is reach noway out the maze MOVE.B #0,D0 Print message saying that there isn't away out MOVE.W #21,D1 TRAP #15 DONE BRA DONE_MOV Exit the function, done moving *----------------------------------------------------------------* * If a zero is found in the maze add the location to a list * * so it can be printed at the end of the program. * *----------------------------------------------------------------* ADD_STK MOVE.L A0,(A2)+ Add location in maze to stack a2 MOVE.B #$39,(A0) move '9' to the maze location MOVE.B CNT,D2 ADD.B #1,D2 Add 1 to number of items on the stack MOVE.B D2,CNT CMPA #END,A0 If maze location == the end BNE ELSE LEA END_MES,A1 If the maze was succesfully exited MOVE.B #0,D0 Print a message say the rat made it out MOVE.W #39,D1 TRAP #15 BRA DONE ELSE BRA CONT_MOV Else continue moving through the maze * *----------------------------------------------------------------* * Display the maze on the screen with 9's for each location * * moved to. * *----------------------------------------------------------------* PRT_MAZE BSR PRT_CRLF Print a blank line MOVE.B #0,D0 set print option MOVE.W #COLS,D1 set number of char to print LEA MAZE,A1 MOVE.B #8,D3 use D3 as a counter to print 8 rows CONTIN TST.L D3 test if D3 == 0 BEQ EXIT_PRT if D3 == 0 exit the print function TRAP #15 Print the row LEA COLS(A1),A1 move to the next row to print SUB.B #1,D3 decrement the counter BRA CONTIN loop EXIT_PRT RTS EXIT Print maze function *----------------------------------------------------------------* * Print out the location that were moved to in the maze * *----------------------------------------------------------------* PRT_ITEM CLR.L D2 clear register D0 CLR.L D1 clear register D1 MOVE.B CNT,D2 Get the total # of location in stack SUB.B #1,D2 subtact one from stack count MOVE.B D2,D3 move stack count to D# MULU.W #4,d3 Muliple by 4 to get total byte SUBA.L d3,a2 move to end of stack, to print in correct order AGAIN BSR PRT_LBR print a left brace move.l (A2)+,D1 get maze location SUB.L #MAZE,d1 sub. maze location from begining of maze MOVE.L D1,D4 DIVU #COLS,D4 div. maze location by the # of columns MOVE.W D4,D1 move the row number to D1 MOVE.B #3,D0 set print option TRAP #15 Print row number BSR PRT_COM Print a comma MOVE #3,D0 set print option SWAP D4 swap D4 to get remainder MOVE.W D4,D1 move remainder to D1 TRAP #15 Prints the column number BSR PRT_RBR Print right brace SUB.B #1,D2 subtact 1 from stack count BEQ END_IT If zero stop printing elements BSR PRT_ARRW Print an arrow between maze locations BRA AGAIN Print the next location END_IT RTS *---------------------------------------------------------------* * Sub-routine PRT_HEAD, print the heading of the program, * * including name, class, semester. * *---------------------------------------------------------------* PRT_HEAD MOVE.B #0,D0 Set print option LEA NAME,A1 Display my name MOVE.W #12,D1 TRAP #15 LEA CLASS,A1 Display the class MOVE.W #7,D1 TRAP #15 LEA TIME,A1 Display the class time MOVE.W #12,D1 TRAP #15 BSR PRT_CRLF Display a blank line RTS *---------------------------------------------------------------* * Sub-routines for helper functions to print common stings * * that are used in the program. *---------------------------------------------------------------* PRT_CRLF MOVE.B #6,D0 the function to print a CRLF MOVE.B #$0D,D1 TRAP #15 MOVE.B #$0A,D1 TRAP #15 RTS PRT_SP MOVE.B #6,D0 the function prints a space MOVE.B #$20,D1 TRAP #15 RTS PRT_ARRW LEA ARROW,A1 the function to print an arrow MOVE.B #1,D0 MOVE.W #2,D1 TRAP #15 RTS PRT_LBR MOVE.B #6,D0 the function to print a left brace MOVE.B #$28,D1 TRAP #15 RTS PRT_RBR MOVE.B #6,D0 the function to print a right brace MOVE.B #$29,D1 TRAP #15 RTS PRT_COM MOVE.B #6,D0 the function to print a comma MOVE.B #$2C,D1 TRAP #15 RTS ************************************************************* *-----------------------------------------------------------* * * * Data Section of program * * * *-----------------------------------------------------------* ************************************************************* ORG $1000 Data section S * Heading data for program * NAME DC.B 'Nathan Balon' my name CLASS DC.B 'CIS 310' class TIME DC.B 'Winter, 2004' semester * * messages to diplay on succes or failure * of exit from the maze. * END_MES DC.B 'The rat found the way out of the maze!!' NO_OUT DC.B 'No way out the maze!!' * * The Maze that the rat must try to get through. * MAZE EQU * ROW0 DC.B '0111111111111' ROW1 DC.B '1001101101111' ROW2 DC.B '1100010110001' ROW3 DC.B '1110111111111' ROW4 DC.B '1111011111111' ROW5 DC.B '1111100000011' ROW6 DC.B '1111111111101' ROW7 DC.B '1111111111110' * * information about the maze * ROWS EQU 8 The number of rows in the maze COLS EQU 13 The number of columns in the maze END EQU MAZE+((ROWS*COLS)-1) Ending postion of the maze * * CNT DS.B 1 Count for the number of items in the stack ARROW DC.B '->' END $400