From e473c545a45578c5c09dff52108eb82f70ddf6d0 Mon Sep 17 00:00:00 2001 From: Jali Date: Sun, 3 Aug 2025 13:59:31 +0200 Subject: [PATCH] Refactor code. --- src/SUDOKU.ASM | 34 ++++++++++++++++++++++++++++++++++ src/SUDOKU.MAC | 33 --------------------------------- 2 files changed, 34 insertions(+), 33 deletions(-) create mode 100644 src/SUDOKU.ASM delete mode 100644 src/SUDOKU.MAC diff --git a/src/SUDOKU.ASM b/src/SUDOKU.ASM new file mode 100644 index 0000000..7e35006 --- /dev/null +++ b/src/SUDOKU.ASM @@ -0,0 +1,34 @@ +;-*-MIDAS-*- + TITLE SUDOKU SOLVER + +;Define the accumulators +A=1 ;The primary accumulator. +B=2 ;Other ACs. +C=3 +X=4 ; X and Y are used for indexing +Y=5 ; loops etc. + +;Set up the stack +P=17 +PDLLEN==20 ;Size of the stack. +PDL BLOCK PDLLEN ;Reserve the stack memory. + +BPTR==440700 ;Define a byte pointer. +CHTTYO==1 ;Define a channel for TTY output. + +START: MOVE P,[-PDLLEN,,PDL-1] ;Initialize the stack. + .OPEN CHTTYO,[.UAO,,'TTY] ;Open the output channel. + .LOSE %LSFIL ;Gobble up error messages. + MOVE A,[BPTR,,HELLO] ;Load A with a byte pointer to HELLO. + JRST DONE ;Jump to the end of the program. +OUTSTR: HRLI A,BTPR ;Ensure, A is a byte pointer. +OUT: ILDB B,A ;Load the next byte from A. + JUMPE B,OUTEX ;Exit the routine, if all bytes are done. + .IOT CHTTYO,B ;Print a character. + JRST OUT ;Jump back to print the next character. +OUTEX: .IOT CHTTYO,[^M] ;Print carriage return and + .IOT CHTTYO,[^J] ;newline characters. + POPJ P, ;Return from the subroutine. +DONE: ;Exit point for the program. +HELLO: ASCIZ /HELLO WORLD/ ;Define example string. +END START diff --git a/src/SUDOKU.MAC b/src/SUDOKU.MAC deleted file mode 100644 index 49fbb93..0000000 --- a/src/SUDOKU.MAC +++ /dev/null @@ -1,33 +0,0 @@ -;-*-MIDAS-*- - TITLE SUDOKU SOLVER -P=17 ;Defines AC 17 as the stack pointer. - -A=1 ;Define two accumulators -B=2 ;A and B -CHTTYO==1 ;Output channel number - -PDLLEN==100 ;Length of push down stack -PDL: BLOCK PDLLEN ;Storage for push down stack - -START: MOVE P,[-PDLLEN,,PDL-1] ;Initialize the stack - .CALL [SETZ ? SIXBIT/OPEN/ ;Open the TTY channels - [.UAI,,CHTTYO] ? [SIXBIT/TTY/] ((SETZ))] - .LOSE %LSFIL - - -L: MOVE A, [440700,,HELLO] ;Load the address of the string into A - PUSHJ P, OUTSTR ;Print the string. - JRST L ;Keep looping - -;Subroutine to output the ASCIZ which starts in the word -;whose address is in A. Clobbers A. -OUTSTR: HRLI A, 440700 ;Make A into a byte pointer to fetch a string -OUTST1: ILDB B, A ;Fetch the next character of string into B - JUMPE B, CPOPJ ;If it is the terminator, return - .IOT CHTTYO,B ;Else output the character - JRST OUTST1 ;and loop around. - -CPOPJ: POPJ P, ;Return - -HELLO: ASCIZ /HELLO WORLD/ - END START