News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Sudoku_Solver [help!]

Started by jenxin, November 29, 2011, 09:03:18 PM

Previous topic - Next topic

jenxin

Hi all. I posted a topic requesting help on a Sudoku checker awhile back. Now I have to write a Sudoku solver. I have wrote it so that, if the input is 's' or 'S', Solve_Sudoku_Matrix is called.
I just need some tips, and hints to get me started.

Help is appreciated, all comments welcomed.
This is due on Thursday. Thanks!


Here's What I need to implement it with;

[code]INCLUDE Irvine32.inc

.code

Main PROC
    ; Vladimir Goncharoff
    ; ECE 267: Computer Organization I
    ; University of Illinois at Chicago
    ; Fall 2011 Semester -- Program #2
    ; October 6, 2011


    ; This code draws a Sudoku matrix, allows the user to enter or erase numbers,
    ; and thus helps students debug their procedure "Test_Sudoku" (which is called
    ; by this procedure after each number is entered; an illegal entry causes that
    ; value to flash on the screen a few times and then disappear).
    ;
    ; The Sudoku matrix is stored as a contiguous string of 81 bytes. These bytes
    ; will only contain unsigned codes for values 0-9 (0 is an uninitialized cell).
    ; The bytes are in row-wise (left-to-right, top-to-down) scan format.
    ;
    ; The single parameter passed to procedure "Test_Sudoku" is the starting address
    ; of these 81 bytes in memory, which is passed in register edx.
    ;
    ; Procedure "Test_Sudoku" passes back eax=1 if the matrix is found to be valid
    ; according to Sudoku rules of legality, and eax=0 if not valid.
    ;


    .data
        Sudoku_Matrix BYTE 81 dup(0)
        Cursor_Row   BYTE  ?
        Cursor_Col   BYTE  ?
        Temp_Dword   DWORD ?
    .code


    call Draw_Sudoku_Matrix


    ; Position cursor in upper left cell of the Sudoku grid
    mov Cursor_Row,0
    mov Cursor_Col,0


Get_User_Input:

    ; Redraw the Sudoku matrix values on the display
    call Update_Sudoku_Matrix

    call Update_Cursor

    call ReadChar

    .IF (al=='l')||(al=='L')
        jmp Square_Left
    .ELSEIF (al=='r')||(al=='R')
        jmp Square_Right
    .ELSEIF (al=='u')||(al=='U')
        jmp Square_Up
    .ELSEIF (al=='d')||(al=='D')
        jmp Square_Down
    .ELSEIF (al=='0')||(al==' ')
        ; blank square
        mov al,' '
        call WriteChar
        mov al,0
        call Write_Sudoku_Matrix
        jmp Square_Right
    .ELSEIF (al=='s')||(al=='S')
   call Solve_Sudoku_Matrix
    .ELSEIF (al>='1')&&(al<='9')
        ; a number was entered
        sub al,'0'                 ; convert '1'-'9' to 1-9
        mov ah,al                  ; store the value in ah temporarily
        call Read_Sudoku_Matrix    ; AL returns the previous value at (Row,Col)
        ror ax,8                   ; swap AL and AH contents
        call Write_Sudoku_Matrix   ; AH stores previous value, user input sent to mem.

        pushad                     ; save all doubleword registers on stack
        mov edx,OFFSET Sudoku_Matrix
        call Test_Sudoku           ; EDX sends address of Sudoku_Matrix,
                                   ; EAX returns value of 1 (valid) or 0 (invalid)
        mov Temp_Dword,eax
        popad                      ; restore all doubleword registers


        mov eax,Temp_Dword         ; I had to do this for ease of testing many students' code...

        .IF (eax==1)
            ; legal input
            jmp Square_Right
        .ELSEIF (eax==0)
            ; illegal input - do not write the entered value in the matrix
            mov al,ah
            call Write_Sudoku_Matrix   ; previous value is restored
        .ELSE
            ; eax has returned neither 1 nor 0, so terminate the program
            jmp Quit
        .ENDIF
    .ENDIF

    jmp Get_User_Input


Square_Left:

    .IF (Cursor_Col==0)
        mov Cursor_Col,8
        jmp Square_Up
    .ELSE
        dec Cursor_Col
    .ENDIF
    call Get_User_Input


Square_Right:

    .IF (Cursor_Col==8)
        mov Cursor_Col,0
        jmp Square_Down
    .ELSE
        inc Cursor_Col
    .ENDIF
    call Get_User_Input


Square_Up:

    .IF (Cursor_Row==0)
        mov Cursor_Row,8
    .ELSE
        dec Cursor_Row
    .ENDIF
    call Get_User_Input


Square_Down:

    .IF (Cursor_Row==8)
        mov Cursor_Row,0
    .ELSE
        inc Cursor_Row
    .ENDIF
    jmp Get_User_Input


Quit:
    ;illegal value returned in eax from "Test_Sudoku" -- stop execution
    exit
Main ENDP


Draw_Sudoku_Matrix PROC
    ; Vladimir Goncharoff
    ; ECE 267: Computer Organization I
    ; University of Illinois at Chicago
    ; Fall 2011 Semester
    ; October 6, 2011
    ;
    ; This procedure draws the grid lines for a Sudoku matrix in the
    ; command window.

    .data
        String1 BYTE 20 dup(' '),0C9h
                BYTE  2 dup(2 dup(3 dup(0CDh),0D1h),3 dup(0CDh),0CBh)
                BYTE        2 dup(3 dup(0CDh),0D1h),3 dup(0CDh),0BBh,0
        String2 BYTE 20 dup(' '),0BAh
                BYTE  2 dup(2 dup(3 dup(020h),0B3h),3 dup(020h),0BAh)
                BYTE        2 dup(3 dup(020h),0B3h),3 dup(020h),0BAh,0
        String3 BYTE 20 dup(' '),0C7h
                BYTE  2 dup(2 dup(3 dup(0C4h),0C5h),3 dup(0C4h),0D7h)
                BYTE        2 dup(3 dup(0C4h),0C5h),3 dup(0C4h),0B6h,0
        String4 BYTE 20 dup(' '),0CCh
                BYTE  2 dup(2 dup(3 dup(0CDh),0D8h),3 dup(0CDh),0CEh)
                BYTE        2 dup(3 dup(0CDh),0D8h),3 dup(0CDh),0B9h,0
        String5 BYTE 20 dup(' '),0C8h
                BYTE  2 dup(2 dup(3 dup(0CDh),0CFh),3 dup(0CDh),0CAh)
                BYTE        2 dup(3 dup(0CDh),0CFh),3 dup(0CDh),0BCh,0
        String6 BYTE "   Cursor control:",0
        String7 BYTE "   U = move up",0
        String8 BYTE "   D = move down",0
        String9 BYTE "   L = move left",0
        StringA BYTE "   R = move right",0
        StringB BYTE "   Enter 1-9,",0
        StringC BYTE "   or 0/space",0
        StringD BYTE "   for blank",0

    .code

    call ClrScr
    call Crlf
    call Crlf
    call Crlf
    mov edx,OFFSET String1
    call WriteString
    call Crlf
    mov edx,OFFSET String2
    call WriteString
    call Crlf
    mov edx,OFFSET String3
    call WriteString
    call Crlf
    mov edx,OFFSET String2
    call WriteString
    call Crlf
    mov edx,OFFSET String3
    call WriteString
        mov edx,OFFSET StringB
        call WriteString
    call Crlf
    mov edx,OFFSET String2
    call WriteString
        mov edx,OFFSET StringC
        call WriteString
    call Crlf
    mov edx,OFFSET String4
    call WriteString
        mov edx,OFFSET StringD
        call WriteString
    call Crlf
    mov edx,OFFSET String2
    call WriteString
    call Crlf
    mov edx,OFFSET String3
    call WriteString
    call Crlf
    mov edx,OFFSET String2
    call WriteString
        mov edx,OFFSET String6
        call WriteString
    call Crlf
    mov edx,OFFSET String3
    call WriteString
        mov edx,OFFSET String7
        call WriteString
    call Crlf
    mov edx,OFFSET String2
    call WriteString
        mov edx,OFFSET String8
        call WriteString
    call Crlf
    mov edx,OFFSET String4
    call WriteString
        mov edx,OFFSET String9
        call WriteString
    call Crlf
    mov edx,OFFSET String2
    call WriteString
        mov edx,OFFSET StringA
        call WriteString
    call Crlf
    mov edx,OFFSET String3
    call WriteString
    call Crlf
    mov edx,OFFSET String2
    call WriteString
    call Crlf
    mov edx,OFFSET String3
    call WriteString
    call Crlf
    mov edx,OFFSET String2
    call WriteString
    call Crlf
    mov edx,OFFSET String5
    call WriteString
    call Crlf
    ret
Draw_Sudoku_Matrix ENDP


Update_Sudoku_Matrix PROC
    ; Vladimir Goncharoff
    ; ECE 267: Computer Organization I
    ; University of Illinois at Chicago
    ; Fall 2011 Semester
    ; October 6, 2011
    ;
    ; This procedure updates all of the numbers in the Sudoku matrix that is
    ; displayed in the command window, based on those stored in memory in array
    ; 'Sudoku_Matrix'.

    .data
        Cursor_Row_copy  BYTE  ?
        Cursor_Col_copy  BYTE  ?
    .code

    mov al,Cursor_Row                 ; save copy of the current cursor position
    mov Cursor_Row_copy,al
    mov al,Cursor_Col
    mov Cursor_Col_copy,al

    mov Cursor_Row,0
A1:     mov Cursor_Col,0
A2:         call Read_Sudoku_Matrix   ; AL returns value at (Cursor_Row,Cursor_Col)
            .IF (al==0)
                mov al,' '            ; display space character instead of zero
            .ELSE
                add al,'0'            ; convert 1-9 to '1'-'9'
            .ENDIF
            call Update_Cursor        ; display value inside the grid lines
            call WriteChar
            call Update_Cursor1       ; display value as it appears in linear memory
               .IF (al==' ')
                mov al,'0'            ; display zero instead of space character
            .ENDIF
            call WriteChar
       inc Cursor_Col
       cmp Cursor_Col,9
       jne A2
    inc Cursor_Row
    cmp Cursor_Row,9
    jne A1

    mov al,Cursor_Row_copy            ; restore cursor position
    mov Cursor_Row,al
    mov al,Cursor_Col_copy
    mov Cursor_Col,al
    ret
Update_Sudoku_Matrix ENDP


Read_Sudoku_Matrix PROC USES ecx edx
    ; Vladimir Goncharoff
    ; ECE 267: Computer Organization I
    ; University of Illinois at Chicago
    ; Fall 2011 Semester
    ; October 6, 2011
    ;
    ; This procedure reads and returns (in al) the Sudoku matrix value
    ; that is stored at location (Cursor_Row,Cursor_Col).  Cursor_Row
    ; and Cursor_Col are existing memory bytes in the range [0,8].
    ; The base address is "Sudoku_Matrix".
    ;
    mov edx,OFFSET Sudoku_Matrix
    mov ecx,0
    mov cl,Cursor_Row
    shl cl,3    ; CL <-- 8*Cursor_Row
    add cl,Cursor_Row  ; CL <-- CL + Cursor_Row = 9*Cursor_Row
    add cl,Cursor_Col  ; CL <-- 9*Cursor_Row + Cursor_Col = matrix offset
                       ;         to desired cell
    mov al,[edx+ecx]
    ret
Read_Sudoku_Matrix ENDP


Write_Sudoku_Matrix PROC USES ecx edx
    ; Vladimir Goncharoff
    ; ECE 267: Computer Organization I
    ; University of Illinois at Chicago
    ; Fall 2011 Semester
    ; October 6, 2011
    ;
    ; This procedure writes the value that is passed in al to the Sudoku
    ; matrix at location (Cursor_Row,Cursor_Col).  Cursor_Row and Cursor_Col
    ; are existing memory bytes in the range [0,8]. The base address is
    ; "Sudoku_Matrix".
    ;
    mov edx,OFFSET Sudoku_Matrix
    mov ecx,0
    mov cl,Cursor_Row
    shl cl,3    ; CL <-- 8*Cursor_Row
    add cl,Cursor_Row  ; CL <-- CL + Cursor_Row = 9*Cursor_Row
    add cl,Cursor_Col  ; CL <-- 9*Cursor_Row + Cursor_Col = matrix offset
                       ;         to desired cell
    add edx,ecx ; pointer <-- pointer + offset
    mov [edx],al
    ret
Write_Sudoku_Matrix ENDP

Solve_Sudoku_Matrix PROC

Solve_Sudoku_Matrix ENDP


Update_Cursor PROC USES edx
    ; Vladimir Goncharoff
    ; ECE 267: Computer Organization I
    ; University of Illinois at Chicago
    ; Fall 2011 Semester
    ; October 6, 2011
    ;
    ; input parameters: Cursor_Row,Cursor_Col (in memory)
    ; Cursor is moved to Sudoku Matrix location (Cursor_Row,Cursor_Col)
    ;
    mov dh,Cursor_Row
    shl dh,1
    add dh,4         ; dh <-- Yoffset + 2*Cursor_Row  (Yoffset=4)
    mov dl,Cursor_Col
    shl dl,2
    add dl,22        ; dl <-- Xoffset + 4*Cursor_Col  (Xoffset=22)
    call GotoXY
    ret
Update_Cursor ENDP


Update_Cursor1 PROC USES edx
    ; Vladimir Goncharoff
    ; ECE 267: Computer Organization I
    ; University of Illinois at Chicago
    ; Fall 2011 Semester
    ; October 6, 2011
    ;
    ; input parameters: Cursor_Row,Cursor_Col (in memory)
    ;
    ; Cursor is moved to a spot at left of the matrix grid to a position
    ; corresponding to coordinates (Cursor_Row,Cursor_Col)
    ;
    mov dh,Cursor_Row
    add dh,8             ; dh <-- Yoffset + Cursor_Row  (Yoffset=8)
    mov dl,Cursor_Col
    add dl,5             ; dl <-- Xoffset + Cursor_Col  (Xoffset=5)
    call GotoXY
    ret
Update_Cursor1 ENDP

Test_Sudoku PROC

    ; Vladimir Goncharoff
    ; ECE 267: Computer Organization I
    ; University of Illinois at Chicago
    ; Fall 2011 Semester
    ; October 10, 2011
    ;
    ; Solution to Program 2
    ;
    ; EDX passes the address to the Sudoku matrix.
    ; EAX returns 1 if the matrix is legal, or 0 if the matrix is not legal.

    .data
        ; Here is where we keep track of the number of times a given digit
        ; has appeared in a row, column, or sub-square:
        Value_Count BYTE 10 dup(?)   

        ; A copy of EDX will be stored here:
        Copy_of_Pointer DWORD ?
    .code


    mov Copy_of_Pointer,edx       ; save Copy_of_Pointer to Sudoku matrix

;---------------------------------------------------------------------------
    ; check row 0 for duplicate digits:

    mov edx,Copy_of_Pointer
    ; add offset for the starting square:
    add edx,9*0
   
    ; initialize pointer to Value_Count array:
    mov ebx,OFFSET Value_Count

    ; reset Value_Count array to all zeros:
    mov DWORD PTR [ebx+0],0
    mov DWORD PTR [ebx+4],0
    mov WORD  PTR [ebx+8],0

    mov eax,0

    mov al,[edx+0]               ; overwrite al (eax) with digit at this square
    inc BYTE PTR [ebx+eax]       ; increment counter for this digit
    mov al,[edx+1]               ; repeat for each of the remaining 8 squares
    inc BYTE PTR [ebx+eax]
    mov al,[edx+2]
    inc BYTE PTR [ebx+eax]
    mov al,[edx+3]
    inc BYTE PTR [ebx+eax]
    mov al,[edx+4]
    inc BYTE PTR [ebx+eax]
    mov al,[edx+5]
    inc BYTE PTR [ebx+eax]
    mov al,[edx+6]
    inc BYTE PTR [ebx+eax]
    mov al,[edx+7]
    inc BYTE PTR [ebx+eax]
    mov al,[edx+8]
    inc BYTE PTR [ebx+eax]

    ; check to see if any of the counter values exceeds 1:
    .IF     (BYTE PTR [ebx+1] > 1)
        jmp Illegal_Matrix_Detected
    .ELSEIF (BYTE PTR [ebx+2] > 1)
        jmp Illegal_Matrix_Detected
    .ELSEIF (BYTE PTR [ebx+3] > 1)
        jmp Illegal_Matrix_Detected
    .ELSEIF (BYTE PTR [ebx+4] > 1)
        jmp Illegal_Matrix_Detected
    .ELSEIF (BYTE PTR [ebx+5] > 1)
        jmp Illegal_Matrix_Detected
    .ELSEIF (BYTE PTR [ebx+6] > 1)
        jmp Illegal_Matrix_Detected
    .ELSEIF (BYTE PTR [ebx+7] > 1)
        jmp Illegal_Matrix_Detected
    .ELSEIF (BYTE PTR [ebx+8] > 1)
        jmp Illegal_Matrix_Detected
    .ELSEIF (BYTE PTR [ebx+9] > 1)
        jmp Illegal_Matrix_Detected
    .ENDIF
;---------------------------------------------------------------------------
    ; check row 1 for duplicate digits:

    mov edx,Copy_of_Pointer
    ; add offset for the starting square:
    add edx,9*1
   
    ; initialize pointer to Value_Count array:
    mov ebx,OFFSET Value_Count

    ; reset Value_Count array to all zeros:
    mov DWORD PTR [ebx+0],0
    mov DWORD PTR [ebx+4],0
    mov WORD  PTR [ebx+8],0

    mov eax,0

    mov al,[edx+0]               ; overwrite al (eax) with digit at this square
    inc BYTE PTR [ebx+eax]       ; increment counter for this digit
    mov al,[edx+1]               ; repeat for each of the remaining 8 squares
    inc BYTE PTR [ebx+eax]
    mov al,[edx+2]
    inc BYTE PTR [ebx+eax]
    mov al,[edx+3]
    inc BYTE PTR [ebx+eax]
    mov al,[edx+4]
    inc BYTE PTR [ebx+eax]
    mov al,[edx+5]
    inc BYTE PTR [ebx+eax]
    mov al,[edx+6]
    inc BYTE PTR [ebx+eax]
    mov al,[edx+7]
    inc BYTE PTR [ebx+eax]
    mov al,[edx+8]
    inc BYTE PTR [ebx+eax]

    ; check to see if any of the counter values exceeds 1:
    .IF     (BYTE PTR [ebx+1] > 1)
        jmp Illegal_Matrix_Detected
    .ELSEIF (BYTE PTR [ebx+2] > 1)
        jmp Illegal_Matrix_Detected
    .ELSEIF (BYTE PTR [ebx+3] > 1)
        jmp Illegal_Matrix_Detected
    .ELSEIF (BYTE PTR [ebx+4] > 1)
        jmp Illegal_Matrix_Detected
    .ELSEIF (BYTE PTR [ebx+5] > 1)
        jmp Illegal_Matrix_Detected
    .ELSEIF (BYTE PTR [ebx+6] > 1)
        jmp Illegal_Matrix_Detected
    .ELSEIF (BYTE PTR [ebx+7] > 1)
        jmp Illegal_Matrix_Detected
    .ELSEIF (BYTE PTR [ebx+8] > 1)
        jmp Illegal_Matrix_Detected
    .ELSEIF (BYTE PTR [ebx+9] > 1)
        jmp Illegal_Matrix_Detected
    .ENDIF
;---------------------------------------------------------------------------
    ; check row 2 for duplicate digits:

    mov edx,Copy_of_Pointer
    ; add offset for the starting square:
    add edx,9*2
   
    ; initialize pointer to Value_Count array:
    mov ebx,OFFSET Value_Count

    ; reset Value_Count array to all zeros:
    mov DWORD PTR [ebx+0],0
    mov DWORD PTR [ebx+4],0
    mov WORD  PTR [ebx+8],0

    mov eax,0

    mov al,[edx+0]               ; overwrite al (eax) with digit at this square
    inc BYTE PTR [ebx+eax]       ; increment counter for this digit
    mov al,[edx+1]               ; repeat for each of the remaining 8 squares
    inc BYTE PTR [ebx+eax]
    mov al,[edx+2]
    inc BYTE PTR [ebx+eax]
    mov al,[edx+3]
    inc BYTE PTR [ebx+eax]
    mov al,[edx+4]
    inc BYTE PTR [ebx+eax]
    mov al,[edx+5]
    inc BYTE PTR [ebx+eax]
    mov al,[edx+6]
    inc BYTE PTR [ebx+eax]
    mov al,[edx+7]
    inc BYTE PTR [ebx+eax]
    mov al,[edx+8]
    inc BYTE PTR [ebx+eax]

    ; check to see if any of the counter values exceeds 1:
    .IF     (BYTE PTR [ebx+1] > 1)
        jmp Illegal_Matrix_Detected
    .ELSEIF (BYTE PTR [ebx+2] > 1)
        jmp Illegal_Matrix_Detected
    .ELSEIF (BYTE PTR [ebx+3] > 1)
        jmp Illegal_Matrix_Detected
    .ELSEIF (BYTE PTR [ebx+4] > 1)
        jmp Illegal_Matrix_Detected
    .ELSEIF (BYTE PTR [ebx+5] > 1)
        jmp Illegal_Matrix_Detected
    .ELSEIF (BYTE PTR [ebx+6] > 1)
        jmp Illegal_Matrix_Detected
    .ELSEIF (BYTE PTR [ebx+7] > 1)
        jmp Illegal_Matrix_Detected
    .ELSEIF (BYTE PTR [ebx+8] > 1)
        jmp Illegal_Matrix_Detected
    .ELSEIF (BYTE PTR [ebx+9] > 1)
        jmp Illegal_Matrix_Detected
    .ENDIF
;---------------------------------------------------------------------------
    ; check row 3 for duplicate digits:

    mov edx,Copy_of_Pointer
    ; add offset for the starting square:
    add edx,9*3
   
    ; initialize pointer to Value_Count array:
    mov ebx,OFFSET Value_Count

    ; reset Value_Count array to all zeros:
    mov DWORD PTR [ebx+0],0
    mov DWORD PTR [ebx+4],0
    mov WORD  PTR [ebx+8],0

    mov eax,0

    mov al,[edx+0]               ; overwrite al (eax) with digit at this square
    inc BYTE PTR [ebx+eax]       ; increment counter for this digit
    mov al,[edx+1]               ; repeat for each of the remaining 8 squares
    inc BYTE PTR [ebx+eax]
    mov al,[edx+2]
    inc BYTE PTR [ebx+eax]
    mov al,[edx+3]
    inc BYTE PTR [ebx+eax]
    mov al,[edx+4]
    inc BYTE PTR [ebx+eax]
    mov al,[edx+5]
    inc BYTE PTR [ebx+eax]
    mov al,[edx+6]
    inc BYTE PTR [ebx+eax]
    mov al,[edx+7]
    inc BYTE PTR [ebx+eax]
    mov al,[edx+8]
    inc BYTE PTR [ebx+eax]

    ; check to see if any of the counter values exceeds 1:
    .IF     (BYTE PTR [ebx+1] > 1)
        jmp Illegal_Matrix_Detected
    .ELSEIF (BYTE PTR [ebx+2] > 1)
        jmp Illegal_Matrix_Detected
    .ELSEIF (BYTE PTR [ebx+3] > 1)
        jmp Illegal_Matrix_Detected
    .ELSEIF (BYTE PTR [ebx+4] > 1)
        jmp Illegal_Matrix_Detected
    .ELSEIF (BYTE PTR [ebx+5] > 1)
        jmp Illegal_Matrix_Detected
    .ELSEIF (BYTE PTR [ebx+6] > 1)
        jmp Illegal_Matrix_Detected
    .ELSEIF (BYTE PTR [ebx+7] > 1)
        jmp Illegal_Matrix_Detected
    .ELSEIF (BYTE PTR [ebx+8] > 1)
        jmp Illegal_Matrix_Detected
    .ELSEIF (BYTE PTR [ebx+9] > 1)
        jmp Illegal_Matrix_Detected
    .ENDIF
;---------------------------------------------------------------------------
    ; check row 4 for duplicate digits:

    mov edx,Copy_of_Pointer
    ; add offset for the starting square:
    add edx,9*4
   
    ; initialize pointer to Value_Count array:
    mov ebx,OFFSET Value_Count

    ; reset Value_Count array to all zeros:
    mov DWORD PTR [ebx+0],0
    mov DWORD PTR [ebx+4],0
    mov WORD  PTR [ebx+8],0

    mov eax,0

    mov al,[edx+0]               ; overwrite al (eax) with digit at this square
    inc BYTE PTR [ebx+eax]       ; increment counter for this digit
    mov al,[edx+1]               ; repeat for each of the remaining 8 squares
    inc BYTE PTR [ebx+eax]
    mov al,[edx+2]
    inc BYTE PTR [ebx+eax]
    mov al,[edx+3]
    inc BYTE PTR [ebx+eax]
    mov al,[edx+4]
    inc BYTE PTR [ebx+eax]
    mov al,[edx+5]
    inc BYTE PTR [ebx+eax]
    mov al,[edx+6]
    inc BYTE PTR [ebx+eax]
    mov al,[edx+7]
    inc BYTE PTR [ebx+eax]
    mov al,[edx+8]
    inc BYTE PTR [ebx+eax]

    ; check to see if any of the counter values exceeds 1:
    .IF     (BYTE PTR [ebx+1] > 1)
        jmp Illegal_Matrix_Detected
    .ELSEIF (BYTE PTR [ebx+2] > 1)
        jmp Illegal_Matrix_Detected
    .ELSEIF (BYTE PTR [ebx+3] > 1)
        jmp Illegal_Matrix_Detected
    .ELSEIF (BYTE PTR [ebx+4] > 1)
        jmp Illegal_Matrix_Detected
    .ELSEIF (BYTE PTR [ebx+5] > 1)
        jmp Illegal_Matrix_Detected
    .ELSEIF (BYTE PTR [ebx+6] > 1)
        jmp Illegal_Matrix_Detected
    .ELSEIF (BYTE PTR [ebx+7] > 1)
        jmp Illegal_Matrix_Detected
    .ELSEIF (BYTE PTR [ebx+8] > 1)
        jmp Illegal_Matrix_Detected
    .ELSEIF (BYTE PTR [ebx+9] > 1)
        jmp Illegal_Matrix_Detected
    .ENDIF
;---------------------------------------------------------------------------
    ; check row 5 for duplicate digits:

    mov edx,Copy_of_Pointer
    ; add offset for the starting square:
    add edx,9*5
   
    ; initialize pointer to Value_Count array:
    mov ebx,OFFSET Value_Count

    ; reset Value_Count array to all zeros:
    mov DWORD PTR [ebx+0],0
    mov DWORD PTR [ebx+4],0
    mov WORD  PTR [ebx+8],0

    mov eax,0

    mov al,[edx+0]               ; overwrite al (eax) with digit at this square
    inc BYTE PTR [ebx+eax]       ; increment counter for this digit
    mov al,[edx+1]               ; repeat for each of the remaining 8 squares
    inc BYTE PTR [ebx+eax]
    mov al,[edx+2]
    inc BYTE PTR [ebx+eax]
    mov al,[edx+3]
    inc BYTE PTR [ebx+eax]
    mov al,[edx+4]
    inc BYTE PTR [ebx+eax]
    mov al,[edx+5]
    inc BYTE PTR [ebx+eax]
    mov al,[edx+6]
    inc BYTE PTR [ebx+eax]
    mov al,[edx+7]
    inc BYTE PTR [ebx+eax]
    mov al,[edx+8]
    inc BYTE PTR [ebx+eax]

    ; check to see if any of the counter values exceeds 1:
    .IF     (BYTE PTR [ebx+1] > 1)
        jmp Illegal_Matrix_Detected
    .ELSEIF (BYTE PTR [ebx+2] > 1)
        jmp Illegal_Matrix_Detected
    .ELSEIF (BYTE PTR [ebx+3] > 1)
        jmp Illegal_Matrix_Detected
    .ELSEIF (BYTE PTR [ebx+4] > 1)
        jmp Illegal_Matrix_Detected
    .ELSEIF (BYTE PTR [ebx+5] > 1)
        jmp Illegal_Matrix_Detected
    .ELSEIF (BYTE PTR [ebx+6] > 1)
        jmp Illegal_Matrix_Detected
    .ELSEIF (BYTE PTR [ebx+7] > 1)
        jmp Illegal_Matrix_Detected
    .ELSEIF (BYTE PTR [ebx+8] > 1)
        jmp Illegal_Matrix_Detected
    .ELSEIF (BYTE PTR [ebx+9] > 1)
        jmp Illegal_Matrix_Detected
    .ENDIF
;---------------------------------------------------------------------------
    ; check row 6 for duplicate digits:

    mov edx,Copy_of_Pointer
    ; add offset for the starting square:
    add edx,9*6
   
    ; initialize pointer to Value_Count array:
    mov ebx,OFFSET Value_Count

    ; reset Value_Count array to all zeros:
    mov DWORD PTR [ebx+0],0
    mov DWORD PTR [ebx+4],0
    mov WORD  PTR [ebx+8],0

    mov eax,0

    mov al,[edx+0]               ; overwrite al (eax) with digit at this square
    inc BYTE PTR [ebx+eax]       ; increment counter for this digit
    mov al,[edx+1]               ; repeat for each of the remaining 8 squares
    inc BYTE PTR [ebx+eax]
    mov al,[edx+2]
    inc BYTE PTR [ebx+eax]
    mov al,[edx+3]
    inc BYTE PTR [ebx+eax]
    mov al,[edx+4]
    inc BYTE PTR [ebx+eax]
    mov al,[edx+5]
    inc BYTE PTR [ebx+eax]
    mov al,[edx+6]
    inc BYTE PTR [ebx+eax]
    mov al,[edx+7]
    inc BYTE PTR [ebx+eax]
    mov al,[edx+8]
    inc BYTE PTR [ebx+eax]

    ; check to see if any of the counter values exceeds 1:
    .IF     (BYTE PTR [ebx+1] > 1)
        jmp Illegal_Matrix_Detected
    .ELSEIF (BYTE PTR [ebx+2] > 1)
        jmp Illegal_Matrix_Detected
    .ELSEIF (BYTE PTR [ebx+3] > 1)
        jmp Illegal_Matrix_Detected
    .ELSEIF (BYTE PTR [ebx+4] > 1)
        jmp Illegal_Matrix_Detected
    .ELSEIF (BYTE PTR [ebx+5] > 1)
        jmp Illegal_Matrix_Detected
    .ELSEIF (BYTE PTR [ebx+6] > 1)
        jmp Illegal_Matrix_Detected
    .ELSEIF (BYTE PTR [ebx+7] > 1)
        jmp Illegal_Matrix_Detected
    .ELSEIF (BYTE PTR [ebx+8] > 1)
        jmp Illegal_Matrix_Detected
    .ELSEIF (BYTE PTR [ebx+9] > 1)
        jmp Illegal_Matrix_Detected
    .ENDIF
;---------------------------------------------------------------------------
    ; check row 7 for duplicate digits:

    mov edx,Copy_of_Pointer
    ; add offset for the starting square:
    add edx,9*7
   
    ; initialize pointer to Value_Count array:
    mov ebx,OFFSET Value_Count

    ; reset Value_Count array to all zeros:
    mov DWORD PTR [ebx+0],0
    mov DWORD PTR [ebx+4],0
    mov WORD  PTR [ebx+8],0

    mov eax,0

    mov al,[edx+0]               ; overwrite al (eax) with digit at this square
    inc BYTE PTR [ebx+eax]       ; increment counter for this digit
    mov al,[edx+1]               ; repeat for each of the remaining 8 squares
    inc BYTE PTR [ebx+eax]
    mov al,[edx+2]
    inc BYTE PTR [ebx+eax]
    mov al,[edx+3]
    inc BYTE PTR [ebx+eax]
    mov al,[edx+4]
    inc BYTE PTR [ebx+eax]
    mov al,[edx+5]
    inc BYTE PTR [ebx+eax]
    mov al,[edx+6]
    inc BYTE PTR [ebx+eax]
    mov al,[edx+7]
    inc BYTE PTR [ebx+eax]
    mov al,[edx+8]
    inc BYTE PTR [ebx+eax]

    ; check to see if any of the counter values exceeds 1:
    .IF     (BYTE PTR [ebx+1] > 1)
        jmp Illegal_Matrix_Detected
    .ELSEIF (BYTE PTR [ebx+2] > 1)
        jmp Illegal_Matrix_Detected
    .ELSEIF (BYTE PTR [ebx+3] > 1)
        jmp Illegal_Matrix_Detected
    .ELSEIF (BYTE PTR [ebx+4] > 1)
        jmp Illegal_Matrix_Detected
    .ELSEIF (BYTE PTR [ebx+5] > 1)
        jmp Illegal_Matrix_Detected
    .ELSEIF (BYTE PTR [ebx+6] > 1)
        jmp Illegal_Matrix_Detected
    .ELSEIF (BYTE PTR [ebx+7] > 1)
        jmp Illegal_Matrix_Detected
    .ELSEIF (BYTE PTR [ebx+8] > 1)
        jmp Illegal_Matrix_Detected
    .ELSEIF (BYTE PTR [ebx+9] > 1)
        jmp Illegal_Matrix_Detected
    .ENDIF
;---------------------------------------------------------------------------
    ; check row 8 for duplicate digits:

    mov edx,Copy_of_Pointer
    ; add offset for the starting square:
    add edx,9*8
   
    ; initialize pointer to Value_Count array:
    mov ebx,OFFSET Value_Count

    ; reset Value_Count array to all zeros:
    mov DWORD PTR [ebx+0],0
    mov DWORD PTR [ebx+4],0
    mov WORD  PTR [ebx+8],0

    mov eax,0

    mov al,[edx+0]               ; overwrite al (eax) with digit at this square
    inc BYTE PTR [ebx+eax]       ; increment counter for this digit
    mov al,[edx+1]               ; repeat for each of the remaining 8 squares
    inc BYTE PTR [ebx+eax]
    mov al,[edx+2]
    inc BYTE PTR [ebx+eax]
    mov al,[edx+3]
    inc BYTE PTR [ebx+eax]
    mov al,[edx+4]
    inc BYTE PTR [ebx+eax]
    mov al,[edx+5]
    inc BYTE PTR [ebx+eax]
    mov al,[edx+6]
    inc BYTE PTR [ebx+eax]
    mov al,[edx+7]
    inc BYTE PTR [ebx+eax]
    mov al,[edx+8]
    inc BYTE PTR [ebx+eax]

    ; check to see if any of the counter values exceeds 1:
    .IF     (BYTE PTR [ebx+1] > 1)
        jmp Illegal_Matrix_Detected
    .ELSEIF (BYTE PTR [ebx+2] > 1)
        jmp Illegal_Matrix_Detected
    .ELSEIF (BYTE PTR [ebx+3] > 1)
        jmp Illegal_Matrix_Detected
    .ELSEIF (BYTE PTR [ebx+4] > 1)
        jmp Illegal_Matrix_Detected
    .ELSEIF (BYTE PTR [ebx+5] > 1)
        jmp Illegal_Matrix_Detected
    .ELSEIF (BYTE PTR [ebx+6] > 1)
        jmp Illegal_Matrix_Detected
    .ELSEIF (BYTE PTR [ebx+7] > 1)
        jmp Illegal_Matrix_Detected
    .ELSEIF (BYTE PTR [ebx+8] > 1)
        jmp Illegal_Matrix_Detected
    .ELSEIF (BYTE PTR [ebx+9] > 1)
        jmp Illegal_Matrix_Detected
    .ENDIF
;---------------------------------------------------------------------------
    ; check column 0 for duplicate digits:

    mov edx,Copy_of_Pointer
    ; add offset for the starting square:
    add edx,0
   
    ; initialize pointer to Value_Count array:
    mov ebx,OFFSET Value_Count

    ; reset Value_Count array to all zeros:
    mov DWORD PTR [ebx+0],0
    mov DWORD PTR [ebx+4],0
    mov WORD  PTR [ebx+8],0

    mov eax,0

    mov al,[edx+0]               ; overwrite al (eax) with digit at this square
    inc BYTE PTR [ebx+eax]       ; increment counter for this digit
    mov al,[edx+9]               ; repeat for each of the remaining 8 squares
    inc BYTE PTR [ebx+eax]
    mov al,[edx+18]
    inc BYTE PTR [ebx+eax]
    mov al,[edx+27]
    inc BYTE PTR [ebx+eax]
    mov al,[edx+36]
    inc BYTE PTR [ebx+eax]
    mov al,[edx+45]
    inc BYTE PTR [ebx+eax]
    mov al,[edx+54]
    inc BYTE PTR [ebx+eax]
    mov al,[edx+63]
    inc BYTE PTR [ebx+eax]
    mov al,[edx+72]
    inc BYTE PTR [ebx+eax]

    ; check to see if any of the counter values exceeds 1:
    .IF     (BYTE PTR [ebx+1] > 1)
        jmp Illegal_Matrix_Detected
    .ELSEIF (BYTE PTR [ebx+2] > 1)
        jmp Illegal_Matrix_Detected
    .ELSEIF (BYTE PTR [ebx+3] > 1)
        jmp Illegal_Matrix_Detected
    .ELSEIF (BYTE PTR [ebx+4] > 1)
        jmp Illegal_Matrix_Detected
    .ELSEIF (BYTE PTR [ebx+5] > 1)
        jmp Illegal_Matrix_Detected
    .ELSEIF (BYTE PTR [ebx+6] > 1)
        jmp Illegal_Matrix_Detected
    .ELSEIF (BYTE PTR [ebx+7] > 1)
        jmp Illegal_Matrix_Detected
    .ELSEIF (BYTE PTR [ebx+8] > 1)
        jmp Illegal_Matrix_Detected
    .ELSEIF (BYTE PTR [ebx+9] > 1)
        jmp Illegal_Matrix_Detected
    .ENDIF
;---------------------------------------------------------------------------
    ; check column 1 for duplicate digits:

    mov edx,Copy_of_Pointer
    ; add offset for the starting square:
    add edx,1
   
    ; initialize pointer to Value_Count array:
    mov ebx,OFFSET Value_Count

    ; reset Value_Count array to all zeros:
    mov DWORD PTR [ebx+0],0
    mov DWORD PTR [ebx+4],0
    mov WORD  PTR [ebx+8],0

    mov eax,0

    mov al,[edx+0]               ; overwrite al (eax) with digit at this square
    inc BYTE PTR [ebx+eax]       ; increment counter for this digit
    mov al,[edx+9]               ; repeat for each of the remaining 8 squares
    inc BYTE PTR [ebx+eax]
    mov al,[edx+18]
    inc BYTE PTR [ebx+eax]
    mov al,[edx+27]
    inc BYTE PTR [ebx+eax]
    mov al,[edx+36]
    inc BYTE PTR [ebx+eax]
    mov al,[edx+45]
    inc BYTE PTR [ebx+eax]
    mov al,[edx+54]
    inc BYTE PTR [ebx+eax]
    mov al,[edx+63]
    inc BYTE PTR [ebx+eax]
    mov al,[edx+72]
    inc BYTE PTR [ebx+eax]

    ; check to see if any of the counter values exceeds 1:
    .IF     (BYTE PTR [ebx+1] > 1)
        jmp Illegal_Matrix_Detected
    .ELSEIF (BYTE PTR [ebx+2] > 1)
        jmp Illegal_Matrix_Detected
    .ELSEIF (BYTE PTR [ebx+3] > 1)
        jmp Illegal_Matrix_Detected
    .ELSEIF (BYTE PTR [ebx+4] > 1)
        jmp Illegal_Matrix_Detected
    .ELSEIF (BYTE PTR [ebx+5] > 1)
        jmp Illegal_Matrix_Detected
    .ELSEIF (BYTE PTR [ebx+6] > 1)
        jmp Illegal_Matrix_Detected
    .ELSEIF (BYTE PTR [ebx+7] > 1)
        jmp Illegal_Matrix_Detected
    .ELSEIF (BYTE PTR [ebx+8] > 1)
        jmp Illegal_Matrix_Detected
    .ELSEIF (BYTE PTR [ebx+9] > 1)
        jmp Illegal_Matrix_Detected
    .ENDIF
;---------------------------------------------------------------------------
    ; check column 2 for duplicate digits:

    mov edx,Copy_of_Pointer
    ; add offset for the starting square:
    add edx,2
   
    ; initialize pointer to Value_Count array:
    mov ebx,OFFSET Value_Count

    ; reset Value_Count array to all zeros:
    mov DWORD PTR [ebx+0],0
    mov DWORD PTR [ebx+4],0
    mov WORD  PTR [ebx+8],0

    mov eax,0

    mov al,[edx+0]               ; overwrite al (eax) with digit at this square
    inc BYTE PTR [ebx+eax]       ; increment counter for this digit
    mov al,[edx+9]               ; repeat for each of the remaining 8 squares
    inc BYTE PTR [ebx+eax]
    mov al,[edx+18]
    inc BYTE PTR [ebx+eax]
    mov al,[edx+27]
    inc BYTE PTR [ebx+eax]
    mov al,[edx+36]
    inc BYTE PTR [ebx+eax]
    mov al,[edx+45]
    inc BYTE PTR [ebx+eax]
    mov al,[edx+54]
    inc BYTE PTR [ebx+eax]
    mov al,[edx+63]
    inc BYTE PTR [ebx+eax]
    mov al,[edx+72]
    inc BYTE PTR [ebx+eax]

    ; check to see if any of the counter values exceeds 1:
    .IF     (BYTE PTR [ebx+1] > 1)
        jmp Illegal_Matrix_Detected
    .ELSEIF (BYTE PTR [ebx+2] > 1)
        jmp Illegal_Matrix_Detected
    .ELSEIF (BYTE PTR [ebx+3] > 1)
        jmp Illegal_Matrix_Detected
    .ELSEIF (BYTE PTR [ebx+4] > 1)
        jmp Illegal_Matrix_Detected
    .ELSEIF (BYTE PTR [ebx+5] > 1)
        jmp Illegal_Matrix_Detected
    .ELSEIF (BYTE PTR [ebx+6] > 1)
        jmp Illegal_Matrix_Detected
    .ELSEIF (BYTE PTR [ebx+7] > 1)
        jmp Illegal_Matrix_Detected
    .ELSEIF (BYTE PTR [ebx+8] > 1)
        jmp Illegal_Matrix_Detected
    .ELSEIF (BYTE PTR [ebx+9] > 1)
        jmp Illegal_Matrix_Detected
    .ENDIF
;---------------------------------------------------------------------------
    ; check column 3 for duplicate digits:

    mov edx,Copy_of_Pointer
    ; add offset for the starting square:
    add edx,3
   
    ; initialize pointer to Value_Count array:
    mov ebx,OFFSET Value_Count

    ; reset Value_Count array to all zeros:
    mov DWORD PTR [ebx+0],0
    mov DWORD PTR [ebx+4],0
    mov WORD  PTR [ebx+8],0

    mov eax,0

    mov al,[edx+0]               ; overwrite al (eax) with digit at this square
    inc BYTE PTR [ebx+eax]       ; increment counter for this digit
    mov al,[edx+9]               ; repeat for each of the remaining 8 squares
    inc BYTE PTR [ebx+eax]
    mov al,[edx+18]
    inc BYTE PTR [ebx+eax]
    mov al,[edx+27]
    inc BYTE PTR [ebx+eax]
    mov al,[edx+36]
    inc BYTE PTR [ebx+eax]
    mov al,[edx+45]
    inc BYTE PTR [ebx+eax]
    mov al,[edx+54]
    inc BYTE PTR [ebx+eax]
    mov al,[edx+63]
    inc BYTE PTR [ebx+eax]
    mov al,[edx+72]
    inc BYTE PTR [ebx+eax]

    ; check to see if any of the counter values exceeds 1:
    .IF     (BYTE PTR [ebx+1] > 1)
        jmp Illegal_Matrix_Detected
    .ELSEIF (BYTE PTR [ebx+2] > 1)
        jmp Illegal_Matrix_Detected
    .ELSEIF (BYTE PTR [ebx+3] > 1)
        jmp Illegal_Matrix_Detected
    .ELSEIF (BYTE PTR [ebx+4] > 1)
        jmp Illegal_Matrix_Detected
    .ELSEIF (BYTE PTR [ebx+5] > 1)
        jmp Illegal_Matrix_Detected
    .ELSEIF (BYTE PTR [ebx+6] > 1)
        jmp Illegal_Matrix_Detected
    .ELSEIF (BYTE PTR [ebx+7] > 1)
        jmp Illegal_Matrix_Detected
    .ELSEIF (BYTE PTR [ebx+8] > 1)
        jmp Illegal_Matrix_Detected
    .ELSEIF (BYTE PTR [ebx+9] > 1)
        jmp Illegal_Matrix_Detected
    .ENDIF
;---------------------------------------------------------------------------
    ; check column 4 for duplicate digits:

    mov edx,Copy_of_Pointer
    ; add offset for the starting square:
    add edx,4
   
    ; initialize pointer to Value_Count array:
    mov ebx,OFFSET Value_Count

    ; reset Value_Count array to all zeros:
    mov DWORD PTR [ebx+0],0
    mov DWORD PTR [ebx+4],0
    mov WORD  PTR [ebx+8],0

    mov eax,0

    mov al,[edx+0]               ; overwrite al (eax) with digit at this square
    inc BYTE PTR [ebx+eax]       ; increment counter for this digit
    mov al,[edx+9]               ; repeat for each of the remaining 8 squares
    inc BYTE PTR [ebx+eax]
    mov al,[edx+18]
    inc BYTE PTR [ebx+eax]
    mov al,[edx+27]
    inc BYTE PTR [ebx+eax]
    mov al,[edx+36]
    inc BYTE PTR [ebx+eax]
    mov al,[edx+45]
    inc BYTE PTR [ebx+eax]
    mov al,[edx+54]
    inc BYTE PTR [ebx+eax]
    mov al,[edx+63]
    inc BYTE PTR [ebx+eax]
    mov al,[edx+72]
    inc BYTE PTR [ebx+eax]

    ; check to see if any of the counter values exceeds 1:
    .IF     (BYTE PTR [ebx+1] > 1)
        jmp Illegal_Matrix_Detected
    .ELSEIF (BYTE PTR [ebx+2] > 1)
        jmp Illegal_Matrix_Detected
    .ELSEIF (BYTE PTR [ebx+3] > 1)
        jmp Illegal_Matrix_Detected
    .ELSEIF (BYTE PTR [ebx+4] > 1)
        jmp Illegal_Matrix_Detected
    .ELSEIF (BYTE PTR [ebx+5] > 1)
        jmp Illegal_Matrix_Detected
    .ELSEIF (BYTE PTR [ebx+6] > 1)
        jmp Illegal_Matrix_Detected
    .ELSEIF (BYTE PTR [ebx+7] > 1)
        jmp Illegal_Matrix_Detected
    .ELSEIF (BYTE PTR [ebx+8] > 1)
        jmp Illegal_Matrix_Detected
    .ELSEIF (BYTE PTR [ebx+9] > 1)
        jmp Illegal_Matrix_Detected
    .ENDIF
;---------------------------------------------------------------------------
    ; check column 5 for duplicate digits:

    mov edx,Copy_of_Pointer
    ; add offset for the starting square:
    add edx,5
   
    ; initialize pointer to Value_Count array:
    mov ebx,OFFSET Value_Count

    ; reset Value_Count array to all zeros:
    mov DWORD PTR [ebx+0],0
    mov DWORD PTR [ebx+4],0
    mov WORD  PTR [ebx+8],0

    mov eax,0

    mov al,[edx+0]               ; overwrite al (eax) with digit at this square
    inc BYTE PTR [ebx+eax]       ; increment counter for this digit
    mov al,[edx+9]               ; repeat for each of the remaining 8 squares
    inc BYTE PTR [ebx+eax]
    mov al,[edx+18]
    inc BYTE PTR [ebx+eax]
    mov al,[edx+27]
    inc BYTE PTR [ebx+eax]
    mov al,[edx+36]
    inc BYTE PTR [ebx+eax]
    mov al,[edx+45]
    inc BYTE PTR [ebx+eax]
    mov al,[edx+54]
    inc BYTE PTR [ebx+eax]
    mov al,[edx+63]
    inc BYTE PTR [ebx+eax]
    mov al,[edx+72]
    inc BYTE PTR [ebx+eax]

    ; check to see if any of the counter values exceeds 1:
    .IF     (BYTE PTR [ebx+1] > 1)
        jmp Illegal_Matrix_Detected
    .ELSEIF (BYTE PTR [ebx+2] > 1)
        jmp Illegal_Matrix_Detected
    .ELSEIF (BYTE PTR [ebx+3] > 1)
        jmp Illegal_Matrix_Detected
    .ELSEIF (BYTE PTR [ebx+4] > 1)
        jmp Illegal_Matrix_Detected
    .ELSEIF (BYTE PTR [ebx+5] > 1)
        jmp Illegal_Matrix_Detected
    .ELSEIF (BYTE PTR [ebx+6] > 1)
        jmp Illegal_Matrix_Detected
    .ELSEIF (BYTE PTR [ebx+7] > 1)
        jmp Illegal_Matrix_Detected
    .ELSEIF (BYTE PTR [ebx+8] > 1)
        jmp Illegal_Matrix_Detected
    .ELSEIF (BYTE PTR [ebx+9] > 1)
        jmp Illegal_Matrix_Detected
    .ENDIF
;---------------------------------------------------------------------------
    ; check column 6 for duplicate digits:

    mov edx,Copy_of_Pointer
    ; add offset for the starting square:
    add edx,6
   
    ; initialize pointer to Value_Count array:
    mov ebx,OFFSET Value_Count

    ; reset Value_Count array to all zeros:
    mov DWORD PTR [ebx+0],0
    mov DWORD PTR [ebx+4],0
    mov WORD  PTR [ebx+8],0

    mov eax,0

    mov al,[edx+0]               ; overwrite al (eax) with digit at this square
    inc BYTE PTR [ebx+eax]       ; increment counter for this digit
    mov al,[edx+9]               ; repeat for each of the remaining 8 squares
    inc BYTE PTR [ebx+eax]
    mov al,[edx+18]
    inc BYTE PTR [ebx+eax]
    mov al,[edx+27]
    inc BYTE PTR [ebx+eax]
    mov al,[edx+36]
    inc BYTE PTR [ebx+eax]
    mov al,[edx+45]
    inc BYTE PTR [ebx+eax]
    mov al,[edx+54]
    inc BYTE PTR [ebx+eax]
    mov al,[edx+63]
    inc BYTE PTR [ebx+eax]
    mov al,[edx+72]
    inc BYTE PTR [ebx+eax]

    ; check to see if any of the counter values exceeds 1:
    .IF     (BYTE PTR [ebx+1] > 1)
        jmp Illegal_Matrix_Detected
    .ELSEIF (BYTE PTR [ebx+2] > 1)
        jmp Illegal_Matrix_Detected
    .ELSEIF (BYTE PTR [ebx+3] > 1)
        jmp Illegal_Matrix_Detected
    .ELSEIF (BYTE PTR [ebx+4] > 1)
        jmp Illegal_Matrix_Detected
    .ELSEIF (BYTE PTR [ebx+5] > 1)
        jmp Illegal_Matrix_Detected
    .ELSEIF (BYTE PTR [ebx+6] > 1)
        jmp Illegal_Matrix_Detected
    .ELSEIF (BYTE PTR [ebx+7] > 1)
        jmp Illegal_Matrix_Detected
    .ELSEIF (BYTE PTR [ebx+8] > 1)
        jmp Illegal_Matrix_Detected
    .ELSEIF (BYTE PTR [ebx+9] > 1)
        jmp Illegal_Matrix_Detected
    .ENDIF
;---------------------------------------------------------------------------
    ; check column 7 for duplicate digits:

    mov edx,Copy_of_Pointer
    ; add offset for the starting square:
    add edx,7
   
    ; initialize pointer to Value_Count array:
    mov ebx,OFFSET Value_Count

    ; reset Value_Count array to all zeros:
    mov DWORD PTR [ebx+0],0
    mov DWORD PTR [ebx+4],0
    mov WORD  PTR [ebx+8],0

    mov eax,0

    mov al,[edx+0]               ; overwrite al (eax) with digit at this square
    inc BYTE PTR [ebx+eax]       ; increment counter for this digit
    mov al,[edx+9]               ; repeat for each of the remaining 8 squares
    inc BYTE PTR [ebx+eax]
    mov al,[edx+18]
    inc BYTE PTR [ebx+eax]
    mov al,[edx+27]
    inc BYTE PTR [ebx+eax]
    mov al,[edx+36]
    inc BYTE PTR [ebx+eax]
    mov al,[edx+45]
    inc BYTE PTR [ebx+eax]
    mov al,[edx+54]
    inc BYTE PTR [ebx+eax]
    mov al,[edx+63]
    inc BYTE PTR [ebx+eax]
    mov al,[edx+72]
    inc BYTE PTR [ebx+eax]

    ; check to see if any of the counter values exceeds 1:
    .IF     (BYTE PTR [ebx+1] > 1)
        jmp Illegal_Matrix_Detected
    .ELSEIF (BYTE PTR [ebx+2] > 1)
        jmp Illegal_Matrix_Detected
    .ELSEIF (BYTE PTR [ebx+3] > 1)
        jmp Illegal_Matrix_Detected
    .ELSEIF (BYTE PTR [ebx+4] > 1)
        jmp Illegal_Matrix_Detected
    .ELSEIF (BYTE PTR [ebx+5] > 1)
        jmp Illegal_Matrix_Detected
    .ELSEIF (BYTE PTR [ebx+6] > 1)
        jmp Illegal_Matrix_Detected
    .ELSEIF (BYTE PTR [ebx+7] > 1)
        jmp Illegal_Matrix_Detected
    .ELSEIF (BYTE PTR [ebx+8] > 1)
        jmp Illegal_Matrix_Detected
    .ELSEIF (BYTE PTR [ebx+9] > 1)
        jmp Illegal_Matrix_Detected
    .ENDIF
;---------------------------------------------------------------------------
    ; check column 8 for duplicate digits:

    mov edx,Copy_of_Pointer
    ; add offset for the starting square:
    add edx,8
   
    ; initialize pointer to Value_Count array:
    mov ebx,OFFSET Value_Count

    ; reset Value_Count array to all zeros:
    mov DWORD PTR [ebx+0],0
    mov DWORD PTR [ebx+4],0
    mov WORD  PTR [ebx+8],0

    mov eax,0

    mov al,[edx+0]               ; overwrite al (eax) with digit at this square
    inc BYTE PTR [ebx+eax]       ; increment counter for this digit
    mov al,[edx+9]               ; repeat for each of the remaining 8 squares
    inc BYTE PTR [ebx+eax]
    mov al,[edx+18]
    inc BYTE PTR [ebx+eax]
    mov al,[edx+27]
    inc BYTE PTR [ebx+eax]
    mov al,[edx+36]
    inc BYTE PTR [ebx+eax]
    mov al,[edx+45]
    inc BYTE PTR [ebx+eax]
    mov al,[edx+54]
    inc BYTE PTR [ebx+eax]
    mov al,[edx+63]
    inc BYTE PTR [ebx+eax]
    mov al,[edx+72]
    inc BYTE PTR [ebx+eax]

    ; check to see if any of the counter values exceeds 1:
    .IF     (BYTE PTR [ebx+1] > 1)
        jmp Illegal_Matrix_Detected
    .ELSEIF (BYTE PTR [ebx+2] > 1)
        jmp Illegal_Matrix_Detected
    .ELSEIF (BYTE PTR [ebx+3] > 1)
        jmp Illegal_Matrix_Detected
    .ELSEIF (BYTE PTR [ebx+4] > 1)
        jmp Illegal_Matrix_Detected
    .ELSEIF (BYTE PTR [ebx+5] > 1)
        jmp Illegal_Matrix_Detected
    .ELSEIF (BYTE PTR [ebx+6] > 1)
        jmp Illegal_Matrix_Detected
    .ELSEIF (BYTE PTR [ebx+7] > 1)
        jmp Illegal_Matrix_Detected
    .ELSEIF (BYTE PTR [ebx+8] > 1)
        jmp Illegal_Matrix_Detected
    .ELSEIF (BYTE PTR [ebx+9] > 1)
        jmp Illegal_Matrix_Detected
    .ENDIF
;---------------------------------------------------------------------------
    ; check upper-left sub-square for duplicate digits:

    mov edx,Copy_of_Pointer
    ; add offset for the starting square:
    add edx,0
   
    ; initialize pointer to Value_Count array:
    mov ebx,OFFSET Value_Count

    ; reset Value_Count array to all zeros:
    mov DWORD PTR [ebx+0],0
    mov DWORD PTR [ebx+4],0
    mov WORD  PTR [ebx+8],0

    mov eax,0

    mov al,[edx+0]               ; overwrite al (eax) with digit at this square
    inc BYTE PTR [ebx+eax]       ; increment counter for this digit
    mov al,[edx+1]               ; repeat for each of the remaining 8 squares
    inc BYTE PTR [ebx+eax]
    mov al,[edx+2]
    inc BYTE PTR [ebx+eax]
    mov al,[edx+9]
    inc BYTE PTR [ebx+eax]
    mov al,[edx+10]
    inc BYTE PTR [ebx+eax]
    mov al,[edx+11]
    inc BYTE PTR [ebx+eax]
    mov al,[edx+18]
    inc BYTE PTR [ebx+eax]
    mov al,[edx+19]
    inc BYTE PTR [ebx+eax]
    mov al,[edx+20]
    inc BYTE PTR [ebx+eax]

    ; check to see if any of the counter values exceeds 1:
    .IF     (BYTE PTR [ebx+1] > 1)
        jmp Illegal_Matrix_Detected
    .ELSEIF (BYTE PTR [ebx+2] > 1)
        jmp Illegal_Matrix_Detected
    .ELSEIF (BYTE PTR [ebx+3] > 1)
        jmp Illegal_Matrix_Detected
    .ELSEIF (BYTE PTR [ebx+4] > 1)
        jmp Illegal_Matrix_Detected
    .ELSEIF (BYTE PTR [ebx+5] > 1)
        jmp Illegal_Matrix_Detected
    .ELSEIF (BYTE PTR [ebx+6] > 1)
        jmp Illegal_Matrix_Detected
    .ELSEIF (BYTE PTR [ebx+7] > 1)
        jmp Illegal_Matrix_Detected
    .ELSEIF (BYTE PTR [ebx+8] > 1)
        jmp Illegal_Matrix_Detected
    .ELSEIF (BYTE PTR [ebx+9] > 1)
        jmp Illegal_Matrix_Detected
    .ENDIF
;---------------------------------------------------------------------------
    ; check upper-middle sub-square for duplicate digits:

    mov edx,Copy_of_Pointer
    ; add offset for the starting square:
    add edx,3
   
    ; initialize pointer to Value_Count array:
    mov ebx,OFFSET Value_Count

    ; reset Value_Count array to all zeros:
    mov DWORD PTR [ebx+0],0
    mov DWORD PTR [ebx+4],0
    mov WORD  PTR [ebx+8],0

    mov eax,0

    mov al,[edx+0]               ; overwrite al (eax) with digit at this square
    inc BYTE PTR [ebx+eax]       ; increment counter for this digit
    mov al,[edx+1]               ; repeat for each of the remaining 8 squares
    inc BYTE PTR [ebx+eax]
    mov al,[edx+2]
    inc BYTE PTR [ebx+eax]
    mov al,[edx+9]
    inc BYTE PTR [ebx+eax]
    mov al,[edx+10]
    inc BYTE PTR [ebx+eax]
    mov al,[edx+11]
    inc BYTE PTR [ebx+eax]
    mov al,[edx+18]
    inc BYTE PTR [ebx+eax]
    mov al,[edx+19]
    inc BYTE PTR [ebx+eax]
    mov al,[edx+20]
    inc BYTE PTR [ebx+eax]

    ; check to see if any of the counter values exceeds 1:
    .IF     (BYTE PTR [ebx+1] > 1)
        jmp Illegal_Matrix_Detected
    .ELSEIF (BYTE PTR [ebx+2] > 1)
        jmp Illegal_Matrix_Detected
    .ELSEIF (BYTE PTR [ebx+3] > 1)
        jmp Illegal_Matrix_Detected
    .ELSEIF (BYTE PTR [ebx+4] > 1)
        jmp Illegal_Matrix_Detected
    .ELSEIF (BYTE PTR [ebx+5] > 1)
        jmp Illegal_Matrix_Detected
    .ELSEIF (BYTE PTR [ebx+6] > 1)
        jmp Illegal_Matrix_Detected
    .ELSEIF (BYTE PTR [ebx+7] > 1)
        jmp Illegal_Matrix_Detected
    .ELSEIF (BYTE PTR [ebx+8] > 1)
        jmp Illegal_Matrix_Detected
    .ELSEIF (BYTE PTR [ebx+9] > 1)
        jmp Illegal_Matrix_Detected
    .ENDIF
;---------------------------------------------------------------------------
    ; check upper-right sub-square for duplicate digits:

    mov edx,Copy_of_Pointer
    ; add offset for the starting square:
    add edx,6
   
    ; initialize pointer to Value_Count array:
    mov ebx,OFFSET Value_Count

    ; reset Value_Count array to all zeros:
    mov DWORD PTR [ebx+0],0
    mov DWORD PTR [ebx+4],0
    mov WORD  PTR [ebx+8],0

    mov eax,0

    mov al,[edx+0]               ; overwrite al (eax) with digit at this square
    inc BYTE PTR [ebx+eax]       ; increment counter for this digit
    mov al,[edx+1]               ; repeat for each of the remaining 8 squares
    inc BYTE PTR [ebx+eax]
    mov al,[edx+2]
    inc BYTE PTR [ebx+eax]
    mov al,[edx+9]
    inc BYTE PTR [ebx+eax]
    mov al,[edx+10]
    inc BYTE PTR [ebx+eax]
    mov al,[edx+11]
    inc BYTE PTR [ebx+eax]
    mov al,[edx+18]
    inc BYTE PTR [ebx+eax]
    mov al,[edx+19]
    inc BYTE PTR [ebx+eax]
    mov al,[edx+20]
    inc BYTE PTR [ebx+eax]

    ; check to see if any of the counter values exceeds 1:
    .IF     (BYTE PTR [ebx+1] > 1)
        jmp Illegal_Matrix_Detected
    .ELSEIF (BYTE PTR [ebx+2] > 1)
        jmp Illegal_Matrix_Detected
    .ELSEIF (BYTE PTR [ebx+3] > 1)
        jmp Illegal_Matrix_Detected
    .ELSEIF (BYTE PTR [ebx+4] > 1)
        jmp Illegal_Matrix_Detected
    .ELSEIF (BYTE PTR [ebx+5] > 1)
        jmp Illegal_Matrix_Detected
    .ELSEIF (BYTE PTR [ebx+6] > 1)
        jmp Illegal_Matrix_Detected
    .ELSEIF (BYTE PTR [ebx+7] > 1)
        jmp Illegal_Matrix_Detected
    .ELSEIF (BYTE PTR [ebx+8] > 1)
        jmp Illegal_Matrix_Detected
    .ELSEIF (BYTE PTR [ebx+9] > 1)
        jmp Illegal_Matrix_Detected
    .ENDIF
;---------------------------------------------------------------------------
    ; check middle-left sub-square for duplicate digits:

    mov edx,Copy_of_Pointer
    ; add offset for the starting square:
    add edx,27
   
    ; initialize pointer to Value_Count array:
    mov ebx,OFFSET Value_Count

    ; reset Value_Count array to all zeros:
    mov DWORD PTR [ebx+0],0
    mov DWORD PTR [ebx+4],0
    mov WORD  PTR [ebx+8],0

    mov eax,0

    mov al,[edx+0]               ; overwrite al (eax) with digit at this square
    inc BYTE PTR [ebx+eax]       ; increment counter for this digit
    mov al,[edx+1]               ; repeat for each of the remaining 8 squares
    inc BYTE PTR [ebx+eax]
    mov al,[edx+2]
    inc BYTE PTR [ebx+eax]
    mov al,[edx+9]
    inc BYTE PTR [ebx+eax]
    mov al,[edx+10]
    inc BYTE PTR [ebx+eax]
    mov al,[edx+11]
    inc BYTE PTR [ebx+eax]
    mov al,[edx+18]
    inc BYTE PTR [ebx+eax]
    mov al,[edx+19]
    inc BYTE PTR [ebx+eax]
    mov al,[edx+20]
    inc BYTE PTR [ebx+eax]

    ; check to see if any of the counter values exceeds 1:
    .IF     (BYTE PTR [ebx+1] > 1)
        jmp Illegal_Matrix_Detected
    .ELSEIF (BYTE PTR [ebx+2] > 1)
        jmp Illegal_Matrix_Detected
    .ELSEIF (BYTE PTR [ebx+3] > 1)
        jmp Illegal_Matrix_Detected
    .ELSEIF (BYTE PTR [ebx+4] > 1)
        jmp Illegal_Matrix_Detected
    .ELSEIF (BYTE PTR [ebx+5] > 1)
        jmp Illegal_Matrix_Detected
    .ELSEIF (BYTE PTR [ebx+6] > 1)
        jmp Illegal_Matrix_Detected
    .ELSEIF (BYTE PTR [ebx+7] > 1)
        jmp Illegal_Matrix_Detected
    .ELSEIF (BYTE PTR [ebx+8] > 1)
        jmp Illegal_Matrix_Detected
    .ELSEIF (BYTE PTR [ebx+9] > 1)
        jmp Illegal_Matrix_Detected
    .ENDIF
;---------------------------------------------------------------------------
    ; check center sub-square for duplicate digits:

    mov edx,Copy_of_Pointer
    ; add offset for the starting square:
    add edx,30
   
    ; initialize pointer to Value_Count array:
    mov ebx,OFFSET Value_Count

    ; reset Value_Count array to all zeros:
    mov DWORD PTR [ebx+0],0
    mov DWORD PTR [ebx+4],0
    mov WORD  PTR [ebx+8],0

    mov eax,0

    mov al,[edx+0]               ; overwrite al (eax) with digit at this square
    inc BYTE PTR [ebx+eax]       ; increment counter for this digit
    mov al,[edx+1]               ; repeat for each of the remaining 8 squares
    inc BYTE PTR [ebx+eax]
    mov al,[edx+2]
    inc BYTE PTR [ebx+eax]
    mov al,[edx+9]
    inc BYTE PTR [ebx+eax]
    mov al,[edx+10]
    inc BYTE PTR [ebx+eax]
    mov al,[edx+11]
    inc BYTE PTR [ebx+eax]
    mov al,[edx+18]
    inc BYTE PTR [ebx+eax]
    mov al,[edx+19]
    inc BYTE PTR [ebx+eax]
    mov al,[edx+20]
    inc BYTE PTR [ebx+eax]

    ; check to see if any of the counter values exceeds 1:
    .IF     (BYTE PTR [ebx+1] > 1)
        jmp Illegal_Matrix_Detected
    .ELSEIF (BYTE PTR [ebx+2] > 1)
        jmp Illegal_Matrix_Detected
    .ELSEIF (BYTE PTR [ebx+3] > 1)
        jmp Illegal_Matrix_Detected
    .ELSEIF (BYTE PTR [ebx+4] > 1)
        jmp Illegal_Matrix_Detected
    .ELSEIF (BYTE PTR [ebx+5] > 1)
        jmp Illegal_Matrix_Detected
    .ELSEIF (BYTE PTR [ebx+6] > 1)
        jmp Illegal_Matrix_Detected
    .ELSEIF (BYTE PTR [ebx+7] > 1)
        jmp Illegal_Matrix_Detected
    .ELSEIF (BYTE PTR [ebx+8] > 1)
        jmp Illegal_Matrix_Detected
    .ELSEIF (BYTE PTR [ebx+9] > 1)
        jmp Illegal_Matrix_Detected
    .ENDIF
;---------------------------------------------------------------------------
    ; check middle-right sub-square for duplicate digits:

    mov edx,Copy_of_Pointer
    ; add offset for the starting square:
    add edx,33
   
    ; initialize pointer to Value_Count array:
    mov ebx,OFFSET Value_Count

    ; reset Value_Count array to all zeros:
    mov DWORD PTR [ebx+0],0
    mov DWORD PTR [ebx+4],0
    mov WORD  PTR [ebx+8],0

    mov eax,0

    mov al,[edx+0]               ; overwrite al (eax) with digit at this square
    inc BYTE PTR [ebx+eax]       ; increment counter for this digit
    mov al,[edx+1]               ; repeat for each of the remaining 8 squares
    inc BYTE PTR [ebx+eax]
    mov al,[edx+2]
    inc BYTE PTR [ebx+eax]
    mov al,[edx+9]
    inc BYTE PTR [ebx+eax]
    mov al,[edx+10]
    inc BYTE PTR [ebx+eax]
    mov al,[edx+11]
    inc BYTE PTR [ebx+eax]
    mov al,[edx+18]
    inc BYTE PTR [ebx+eax]
    mov al,[edx+19]
    inc BYTE PTR [ebx+eax]
    mov al,[edx+20]
    inc BYTE PTR [ebx+eax]

    ; check to see if any of the counter values exceeds 1:
    .IF     (BYTE PTR [ebx+1] > 1)
        jmp Illegal_Matrix_Detected
    .ELSEIF (BYTE PTR [ebx+2] > 1)
        jmp Illegal_Matrix_Detected
    .ELSEIF (BYTE PTR [ebx+3] > 1)
        jmp Illegal_Matrix_Detected
    .ELSEIF (BYTE PTR [ebx+4] > 1)
        jmp Illegal_Matrix_Detected
    .ELSEIF (BYTE PTR [ebx+5] > 1)
        jmp Illegal_Matrix_Detected
    .ELSEIF (BYTE PTR [ebx+6] > 1)
        jmp Illegal_Matrix_Detected
    .ELSEIF (BYTE PTR [ebx+7] > 1)
        jmp Illegal_Matrix_Detected
    .ELSEIF (BYTE PTR [ebx+8] > 1)
        jmp Illegal_Matrix_Detected
    .ELSEIF (BYTE PTR [ebx+9] > 1)
        jmp Illegal_Matrix_Detected
    .ENDIF
;---------------------------------------------------------------------------
    ; check lower-left sub-square for duplicate digits:

    mov edx,Copy_of_Pointer
    ; add offset for the starting square:
    add edx,54
   
    ; initialize pointer to Value_Count array:
    mov ebx,OFFSET Value_Count

    ; reset Value_Count array to all zeros:
    mov DWORD PTR [ebx+0],0
    mov DWORD PTR [ebx+4],0
    mov WORD  PTR [ebx+8],0

    mov eax,0

    mov al,[edx+0]               ; overwrite al (eax) with digit at this square
    inc BYTE PTR [ebx+eax]       ; increment counter for this digit
    mov al,[edx+1]               ; repeat for each of the remaining 8 squares
    inc BYTE PTR [ebx+eax]
    mov al,[edx+2]
    inc BYTE PTR [ebx+eax]
    mov al,[edx+9]
    inc BYTE PTR [ebx+eax]
    mov al,[edx+10]
    inc BYTE PTR [ebx+eax]
    mov al,[edx+11]
    inc BYTE PTR [ebx+eax]
    mov al,[edx+18]
    inc BYTE PTR [ebx+eax]
    mov al,[edx+19]
    inc BYTE PTR [ebx+eax]
    mov al,[edx+20]
    inc BYTE PTR [ebx+eax]

    ; check to see if any of the counter values exceeds 1:

clive

Quote from: jenxinHi all. I posted a topic requesting help on a Sudoku checker awhile back. Now I have to write a Sudoku solver. I have wrote it so that, if the input is 's' or 'S', Solve_Sudoku_Matrix is called.  I just need some tips, and hints to get me started.

Well I think the forum ate some of it, perhaps if it used loops and subroutines with parameters it might be shorter and efficient. Your prof doesn't appear to have figured this out.

So what's your algorithm for solving a Sudoku puzzle? Cause that seems like about half the homework assignment. Like I suggested before, write it in a language you are familiar with. Demonstrate that it works, and provide that code, and a couple of test cases in your final submission. That way even if you get mired in the assembly solution it will be because your assembler coding skills are lacking, rather than a total failure in your method.

Generally I think you should solve it iteratively. At least one method is to identify all the un-assigned squares, and which values they can't possibly hold, based or row/column/cell rules. When you have only one possible value, assign it to the entry. After doing that for one round, repeat until you can no longer assign. At that point you've either solved, or dead-locked.

QuoteThis is due on Thursday.

It shouldn't take more than a couple of hours.
It could be a random act of randomness. Those happen a lot as well.

qWord

checking of rows and columns could be simplified enormous:
xor edi,edi
.while edi < 9
    ; check row N(=EDI) for duplicate digits:
    mov edx,Copy_of_Pointer
    ; add offset for the starting square:
    lea edx,[edi*8+edi] ; edx = N*9
   
    mov ebx,OFFSET Value_Count
    mov DWORD PTR [ebx+0],0
    mov DWORD PTR [ebx+4],0
    mov WORD  PTR [ebx+8],0
    xor esi,esi
    .while esi < 9
        movzx eax,BYTE ptr [edx+esi]
        add BYTE ptr [ebx+eax],80h
        jc Illegal_Matrix_Detected
        inc esi
    .endw
    inc edi
.endw

xor edi,edi
.while edi < 9
    mov edx,Copy_of_Pointer
    add edx,edi
   
    mov ebx,OFFSET Value_Count
    mov DWORD PTR [ebx+0],0
    mov DWORD PTR [ebx+4],0
    mov WORD  PTR [ebx+8],0
    xor esi,esi
    .while esi < 9
        lea eax,[esi*8+esi]
        movzx eax,BYTE ptr [edx+eax]
        add BYTE ptr [ebx+eax],80h
        jc Illegal_Matrix_Detected
        inc esi
    .endw
    inc edi
.endw
FPU in a trice: SmplMath
It's that simple!

jenxin

Yeah the professor wrote it. I agree that the row's and columns could be simplified.

My professor provided a flowchart for us, but there are some confusing things I need help with.

How would I store a pointer to the last square that was modified?

Once I get that, it might be easier.

clive

Quote from: jenxinHow would I store a pointer to the last square that was modified?

Use a spare register, or save it to a variable you've created to hold it.

To be honest I don't think it's important, you can go through the array completely in each round, either counting the values you assigned, or flagging you did at least one.
It could be a random act of randomness. Those happen a lot as well.

jenxin

so far this is what I got

I can't copy the register edx into my variable.

Here's what I have so far.

Solve_Sudoku_Matrix PROC USES ecx edx

LOCAL P1:DWORD

    mov edx,OFFSET Sudoku_Matrix
    mov ecx,0
    mov cl,Cursor_Row
    shl cl,3    ; CL <-- 8*Cursor_Row
    add cl,Cursor_Row  ; CL <-- CL + Cursor_Row = 9*Cursor_Row
    add cl,Cursor_Col  ; CL <-- 9*Cursor_Row + Cursor_Col = matrix offset
                       ;         to desired cell
    add edx,ecx ; pointer <-- pointer + offset

mov P1,edx
mov bl,[P1]
.if bl=='0'
jmp solvebox
.else
jmp checklimit
jnz increment
.endif

ret

solvebox:
checklimit:
increment:
Solve_Sudoku_Matrix ENDP



clive

You can't indirect like that, the value must be in a register
Quotemov P1,edx ; save pointer
mov bl,[edx]
..
mov edx,P1 ; restore pointer
mov bh,[edx]
It could be a random act of randomness. Those happen a lot as well.

jenxin

I don't really understand.. I still get the same error, (Invalid operation).

clive

Seems fine under 6.15, although I don't have Irvine and assort clutter in tow...

00000000 start   PROC
LOCAL P1:DWORD

00000006  89 55 FC         mov P1,edx ; save pointer
00000009  8A 1A         mov bl,[edx]

        ; ..

0000000B  8B 55 FC         mov edx,P1 ; restore pointer
0000000E  8A 3A         mov bh,[edx]

00000010  6A 00         push 0
00000012  E8 00000000 E         call ExitProcess

00000017 start   ENDP
It could be a random act of randomness. Those happen a lot as well.

jenxin

I'm just going to use edx. instead of using P1.

Here's my progress so far.. Am I on the right track?

Solve_Sudoku_Matrix PROC USES ecx edx

LOCAL P1:BYTE
mov P1, 0
mov edx,OFFSET Sudoku_Matrix

   mov ecx,edx
   mov bl,[ecx]
   .if bl=='0'
   jmp solvebox
   .else
   jmp checklimit
   .endif

ret

solvebox:
.if P1>0&&P1<10
mov al, P1
       mov ah,al                  ; store the value in ah temporarily
       call Read_Sudoku_Matrix    ; AL returns the previous value at (Row,Col)
       ror ax,8                   ; swap AL and AH contents
       call Write_Sudoku_Matrix   ; AH stores previous value, user input sent to mem.

       pushad                     ; save all doubleword registers on stack
       mov edx,OFFSET Sudoku_Matrix
       call Test_Sudoku           ; EDX sends address of Sudoku_Matrix,
                                  ; EAX returns value of 1 (valid) or 0 (invalid)
       mov Temp_Dword,eax
       popad                      ; restore all doubleword registers


       mov eax,Temp_Dword         ; I had to do this for ease of testing many students' code...

jmp solvebox
.else
jmp nosolution

.endif

checklimit:

increment:

nosolution:

conclusion:

sub ecx, Sudoku_Matrix
.if ecx>80
mov eax,1
.endif

ret

Solve_Sudoku_Matrix ENDP


clive

So is the goal to solve a single box withing the matrix, or to solve the whole matrix?
It could be a random act of randomness. Those happen a lot as well.

jenxin

My goal is to solve the whole matrix. I have no clue how to do this though.

clive

Algorithmically how do you solve it manually?

Be aware the following code is flawed, as AH is being destroyed

      mov eax,Temp_Dword         ; I had to do this for ease of testing many students' code...

        .IF (eax==1)
            ; legal input
            jmp Square_Right
        .ELSEIF (eax==0)
            ; illegal input - do not write the entered value in the matrix
            mov al,ah
            call Write_Sudoku_Matrix   ; previous value is restored
        .ELSE
            ; eax has returned neither 1 nor 0, so terminate the program
            jmp Quit
        .ENDIF
It could be a random act of randomness. Those happen a lot as well.

jenxin

I was thinking that you could do this by bruteforcing it. He told the class that the easiest was is to do this recursively, although it may take longer. And yes, the code is flawed, he told the class that he changed it so that it no longer puts the old value back in.

jenxin

My professor told us that we only need to store a pointer to the last square that was modified. but i don;'t think this'll work out for anything other then a blank sudoku.. To make a brute forcer, I have to push every pointer into a stack... And then backtrack for every value that doesn't work(how to do this..?). This'll take a long time compared to his method(which i dont think works).