Original Post
I tried to convert a little function to assembler: I keep having errors should be the same as I know the problem must be something with the sign of a char, but i don't know when a char is interpreted signed or unsigned. I think that after asm line 4 (imul bl //ax=move*4): ax is a signed 2 byte value. I guess i have to make it an unsigned 4 byte value? I've also read that to return a value you can do: asm mov eax, RETURN_VALUE asm ret Because eax is used for returning data. But how is the difference made between a pointer and a value? if a function gets a value, it must know what type it is. and I guess asm xor eax, eax asm movs al, INVALID_MOVE asm ret is wrong again (trying to load signed byte into unsigned 4-byte var [Edited by - Kwak on August 17, 2006 7:11:54 AM]
char _fPlaceFallthrough[64];
MoveMessage putPion(char move)
{
__asm
{
xor eax, eax //eax = 0
movs al, move //al = move
movs bl, 4 //bl=4
imul bl //ax = move*4 // now is eax = move*4
add eax, offset _fPlaceFallthrough //eax = &_fPlaceFallthrough[move*4]
movs bl,[eax] //bl = _fPlaceFallthrough[move*4]
cmp bl,-3 //if (getFallthrough(move*4)!=-3)
jnz validMove // goto validMove
mov message, INVALID_MOVE
jmp endAsm
validMove:
dec [eax] // _fPlaceFallthrough[move*4]--;
dec [eax +1] // _fPlaceFallthrough[move*4 + 1]--;
dec [eax +2] // _fPlaceFallthrough[move*4 + 2]--;
dec [eax +3] // _fPlaceFallthrough[move*4 + 3]--;
}
if (message==INVALID_MOVE)
return INVALID_MOVE;
else
return VALID_MOVE;
}
MoveMessage putPion(char move)
{
char place = move*4;
if (getFallthrough(place)==-3)
return INVALID_MOVE;
_fPlaceFallthrough[place]--;
_fPlaceFallthrough[place + 1]--;
_fPlaceFallthrough[place + 2]--;
_fPlaceFallthrough[place + 3]--;
return VALID_MOVE;
}