I don't want to loose my previous work, so i post what i think could be the most interesting part: the move generator. I hope that somebody can have some idea from this. In fact, i want to talk just about the heart of this function. As all of you know, in C it is hard to use cpu status flags but in assembly this is natural. so i've found a way to test for validity of a move in very few assembly lines of code:
I "call" a macro that test the content of destination square of a move and some bit flags in eax. The bit flags contains this bits:
E.......WB
the White/Black bits can be everywhere, in eax, while the bit to know if a square is empty (E) is the upper most (most significant bit). To simplify, suppose to use just 8 bits and to test white moves. I set bits E/W both to 1:
eax = 10000010
any piece in the board is saved with its color bit.
If you test eax (test is a non destructive and) with a square content:
10000010 color flags in eax
00000001 black piece
00000000
and => z set => valid capture
10000010 color flags in eax
00000010 white piece
00000010
g set => invalid move (g is "greater than zero" bit)
10000010 color flags in eax
10000000 empty square
10000000
s set => move in empty square (s is "sign" bit)
10000010 color flags in eax
00000011 illegal square (both W/B set)
00000010
g set => illegal
So, with just one test command you can find three different results:
Code: Select all
TESTM macro delta, finedir
; eax: color flags
; ecx: piece index
; edx: square index
; and bit color z: preso pezzo ---\___legale
; s: vuota ---/
; g: illegale
test eax, [edx+delta]
jg finedir ; invalid move
PUSHM delta ; store pseudo-legal move for capture or empty square (PUSHM is another macro)
jns finedir ; capture so for sliding pieces, this is the last move
; here we follow calling the macro again, for sliding pieces
endm
Sample of calling this macro:
Code: Select all
TEST_DIR macro delta
local @m_finedir
TESTM delta*1,@m_finedir
TESTM delta*2,@m_finedir
TESTM delta*3,@m_finedir
TESTM delta*4,@m_finedir
TESTM delta*5,@m_finedir
TESTM delta*6,@m_finedir
TESTM delta*7,@m_finedir
@m_finedir:
endm
TEST_DIR4 macro delta1,delta2,delta3,delta4
TEST_DIR delta1
TEST_DIR delta2
TEST_DIR delta3
TEST_DIR delta4
endm
MuoviDonna proc ; move queen
TEST_DIR4 N,S,E,W
TEST_DIR4 NE,SE,NW,SW
ret
endp
Hoping this could help somebody. Please, let me know if you use this in your own program.