Name: Anonymous 2009-06-03 15:18
I'm trying to get this game to work, but it wont. Sorry for the sloppy failure code.
.data
message BYTE "X wins!", 0
board SBYTE 'X', 'O', 'X',
'O', 'O', 'O',
'X', ' ', ' '
row SBYTE 0
col SBYTE 0
count SBYTE 0
xwins SBYTE 0
.code
main PROC
call Clrscr
mov esi, OFFSET board
;--------check for ROW wins
L1:
mov bl, row ;row coord in bl
L2: mov cl, col ;col coord in cl
mov eax, 0 ;clear eax
mov al, 3 ;cells per row
mul bl ;times row
add al, col ;plus col => offset in bytes
mov dl, [esi + eax] ;get char from array
.if (dl == 'X') ;if it's an X
inc count ;add 1 to the count
.endif
inc col ;move to next column
cmp col, 3 ;is it column 4?
jl L2 ;if not, go back up
.if (count == 3) ;if count is 3
mov xwins, 1 ;x wins
.endif
mov count, 0 ;clear count
mov col, 0 ;start back at column 0
inc row ;move to next row
cmp row, 3 ;is it row 4?
jl L1 ;if not, do that row
mov col, 0 ;reset row and col
mov row, 0
L3:
mov cl, col ;col coord in cl
L4: mov bl, row ;row coord in bl
mov eax, 0
mov al, 3
mul bl
add al, col
mov dl, [esi + eax]
.if (dl == 'X')
inc count
.endif
inc row ;move to next row
cmp row, 3 ;is it row 4?
jl L4 ;if not, do next row
.if (count == 3)
mov xwins, 1
.endif
mov count, 0
mov row, 0 ;reset for next row
inc col ;move to next col
cmp col, 3 ;is it col 4?
jl L3 ;if not, do next col
cmp xwins, 0 ;no wins for X?
jng L5 ;then end it
mov edx, OFFSET message ;else print message
call writestring
call crlf
L5:
exit
main ENDP
xWin PROC
xWin ENDP
END main