SudokusWeb to asm!

When we started working on our sudoku solving assembly (PIC16F648A) program we found we needed a simple way to load the initial data of the sudoku (in order to have something to solve!).

(For those who have read the post “The Data Memory Map”, the following will make more sense)
Loading the initial data of the sudoku basically consists of storing the input data about columns 1-3 at bank 0 (using 2 bytes per sudoku cell), moving on to bank 1, writing input data about columns 4-6, moving on to bank 2 and writing input data about columns 7-9.

The first time we did it manually, but that was a hell of a job. So we looked for a website that could supply us with daily sudokus, from very easy to expert, found one, and wrote a Perl program that, taking one of that site’s images as input, produces the assembly code we need as output.

Then we just paste this code into the part of our sudoku solving assembly program that’s destined to ‘input’, and voila, we can test different sudokus really easily.

Here you can download the source code of this program, as well as an example image to test it.

By the way, the example sudoku that comes in that .rar is already solved by our program. =D
Expect a post about the solver itself soon! (Among a few others hardware-related posts, yay!)

3 Responses to “SudokusWeb to asm!”

  1. Cool.
    Very good point that GD library to scan numbers from a sudoku image.

    What does exactly instructions BSF and BCF?
    I see that it is for selecting banks, do not? but I haven’t found any logic in how you use them.

    BCF STATUS,RP0
    BCF STATUS,RP1
    ; first block
    BSF STATUS,RP0
    BCF STATUS,RP1
    ;second block
    BSF STATUS,RP1
    BCF STATUS,RP0
    ;third block
    BCF STATUS,RP0
    BCF STATUS,RP1

    Regards.

  2. Hey, thanks. =)

    I’ll give you some information about BSF and BCF:

    BSF f,b (Bit Set f, sets the bit ‘b’ in register ‘f’)
    BCF f,b (Bit Clear f, clears the bit ‘b’ in register ‘f’)

    The STATUS register has two bits (RP1, RP0) that select which bank we can access:
    RP1-RP0->Bank
    0 0 -> 0
    0 1 -> 1
    1 0 -> 2
    1 1 -> 3

    In that code example you pasted, each block of two lines is setting the bank to 0, then 1, then 2. Finally, it’s set back to bank 0.

    Hope that makes it clearer. =)

  3. Absolutely.

    I’m waiting your next post. ;-)

Leave a Reply