Thread: test
View Single Post
Old Jul 14th, 2006, 2:16 PM   #1
lostcauz
Hobbyist Programmer
 
Join Date: Nov 2004
Location: 1691 miles East of L.A.
Posts: 159
Rep Power: 4 lostcauz is on a distinguished road
test

asm Syntax (Toggle Plain Text)
  1. .686
  2. .model flat, stdcall
  3. option casemap :none
  4.  
  5. include \masm32\include\windows.inc
  6. include \masm32\macros\macros.asm
  7. include \masm32\include\masm32.inc
  8. include \masm32\include\kernel32.inc
  9. include \masm32\include\user32.inc
  10. includelib \masm32\lib\user32.lib
  11. includelib \masm32\lib\masm32.lib
  12. includelib \masm32\lib\kernel32.lib
  13.  
  14. .data
  15. ; strings -n- things
  16. cmp_win db 'The computer has won.',0Dh,0Ah,0
  17. plr_win db 'The player has won.',0Dh,0Ah,0
  18. itsa_tie db 'You have battled to a tie.',0Dh,0Ah,0
  19. s_about db 0Dh,0Ah,' |== TIC/TAC/TOE in assembler by lostcauz ==|',0
  20. s_format db ' ',0
  21. board_view db '---------',0
  22. two_newlines db 0Dh,0Ah,0Dh,0Ah,0
  23. one_newline db 0Dh,0Ah,0
  24. buffer db 'EEE',0
  25. ; counter
  26. num_moves db 0
  27. num_wins db 0h,0h,0h
  28. ; dword variables
  29. board_state dd 00000000h
  30. game_over_bit dd 00040000h
  31. turn_bit dd 00080000h
  32.  
  33. ; =============================================== TABLES ===================================================
  34. ; win tables represent board states that cause victory
  35. cmp_win_table dd 00000015h,00000540h,00001041h,00001110h,00004104h,00010101h,00010410h,00015000h
  36. plr_win_table dd 0000002Ah,00000A80h,00002082h,00002220h,00008208h,00020202h,00020820h,0002A000h
  37.  
  38. ; value tables represent squares being occupied
  39. comptr_values dd 00000001h,00000004h,00000010h,00000040h,00000100h,00000400h,00001000h,00004000h,00010000h
  40. player_values dd 00000002h,00000008h,00000020h,00000080h,00000200h,00000800h,00002000h,00008000h,00020000h
  41.  
  42. ; Artificial Intelligence table (I chose a playable level of difficulty)
  43. ai_comp_moves dd 00000014h,00001040h,00010100h,00000028h,00002080h,00020200h
  44. dd 00000011h,00004100h,00000022h,00008200h
  45. dd 00000005h,00010400h,00001100h,0000000Ah,00020800h,00002200h
  46. dd 00000500h,00001001h,00000A00h,00002002h
  47. dd 00000440h,00004004h,00010001h,00001010h,00000880h,00008008h,00020002h,00002020h
  48. dd 00000140h,00010010h,00000280h,00020020h
  49. dd 00014000h,00000041h,00000110h,00028000h,00000082h,00000220h
  50. dd 00011000h,00000104h,00022000h,00000208h
  51. dd 00005000h,00000410h,00000101h,0000A000h,00000820h,00000202h
  52. ; ===========================================================================================================
  53. .code
  54.  
  55. start:
  56. print addr s_about
  57. xor eax,eax ; start new game
  58. mov board_state,eax ; clear board_state
  59. mov num_moves,al ; clear num_moves
  60.  
  61. game_loop:
  62. call get_move ; get next move
  63. call show_board ; show board...
  64. mov eax,board_state ; load current board state
  65. and eax,game_over_bit ; and to see if game is over
  66. cmp eax,game_over_bit ; if bit is set, game over
  67. jne game_loop ; continue
  68.  
  69. mov eax,sval(input("Press <enter> to continue, any letter first to quit. "))
  70. or eax,eax ; quit?
  71. jnz byby ; yep... time ta jet.
  72.  
  73. mov ecx,board_state
  74. and ecx,turn_bit
  75. cmp ecx,turn_bit
  76. jne start
  77. xor ecx,ecx ; clear current state of board
  78. mov num_moves,cl
  79. xor ecx,turn_bit ; toggle turn switch
  80. mov board_state,ecx ; save state
  81. jmp game_loop ; play it again.
  82.  
  83. byby:
  84. exit ; i'm outta here....
  85.  
  86. ; ============================= get_move ====================================
  87. get_move:
  88. mov ecx,board_state ; load current state of board
  89. add num_moves,1 ; increment move counter
  90. xor ecx,turn_bit ; toggle turn switch
  91. mov board_state,ecx ; save state
  92. and ecx,turn_bit ; gotta take turns
  93. cmp ecx,turn_bit ; ...
  94. je cmp_turn ; computer turn
  95. jmp plr_turn ; player turn
  96.  
  97. mov_ret:
  98. cmp num_moves,9 ; 9 total moves in this game
  99. jb @f ; continue playing
  100. mov eax,game_over_bit ; 9 moves reached
  101. mov ecx,board_state ; load current state
  102. and ecx,eax ; see if game_over_bit is set yet
  103. cmp ecx,eax ; ...
  104. je c_up ; get out, the win came on move 9
  105. add board_state,eax ; set the game_over_bit
  106.  
  107. @@: cmp num_moves,5 ; 5 moves before we need to test for win
  108. jb c_up ; just leave
  109. call test_win ; better see if there's a winner
  110.  
  111. c_up:
  112. ret ; return to caller
  113.  
  114. ; ========================= players turn ================================
  115. plr_turn:
  116. print addr two_newlines ; couple newlines
  117.  
  118. @@: xor eax,eax ; zero the register, prolly not necessary
  119. mov eax,sval(input("Enter your move 1-9 : "))
  120. or eax,eax ; did the dummy enter '0' anyhow?
  121. jz @b ; yep...
  122.  
  123. mov ecx,board_state ; load current state
  124. sub eax,1 ; adjust per array
  125. cmp eax,8 ; did the waferhead enter > 9?
  126. ja @b ; yep...
  127.  
  128. mov ebx,ecx ; need to make sure nobody owns this square
  129. and ebx,[player_values+eax*4] ; and board state with table position value
  130. cmp ebx,[player_values+eax*4] ; determine if it is set
  131. je @b ; player owns the square
  132.  
  133. mov ebx,ecx ; load board state
  134. and ebx,[comptr_values+eax*4] ; and with table position value
  135. cmp ebx,[comptr_values+eax*4] ; determine if it is set
  136. je @b ; computer owns the square
  137.  
  138. add ecx,[player_values+eax*4] ; update state with new move
  139. mov board_state,ecx ; save new board state
  140. jmp mov_ret
  141.  
  142. ; ======================== computers turn ===============================
  143. cmp_turn:
  144. print addr two_newlines ; couple newlines
  145. mov ebx,-4 ; prepare for loop
  146.  
  147. try_cmp:
  148. add ebx,4 ; increment computer value table position
  149. mov eax,board_state ; load board state... yawn...
  150. and eax,[comptr_values+ebx] ; and state with comptr_values table pointer
  151. cmp eax,[comptr_values+ebx] ; test if bit was set
  152. je try_cmp ; computer already owns this square
  153. mov eax,board_state ; reload board state
  154. and eax,[player_values+ebx] ; and with player value table
  155. cmp eax,[player_values+ebx] ; bit set?
  156. je try_cmp ; player owns this square
  157.  
  158. ; ========================== AI begins =========================
  159. mov eax,board_state ; The square is empty
  160. cmp ebx,0
  161. jne @f
  162. and eax,[ai_comp_moves] ; check winning combinations
  163. cmp eax,[ai_comp_moves]
  164. je ai_move ; is this a winning move? or the best move?
  165. mov eax,board_state
  166. and eax,[ai_comp_moves+04h]
  167. cmp eax,[ai_comp_moves+04h]
  168. je ai_move
  169. mov eax,board_state
  170. and eax,[ai_comp_moves+08h]
  171. cmp eax,[ai_comp_moves+08h]
  172. je ai_move
  173. ; made it this far, it's not a win to move here.
  174. mov eax,board_state ; look for a block now.
  175. and eax,[ai_comp_moves+0Ch] ; We must block or player can win
  176. cmp eax,[ai_comp_moves+0Ch]
  177. je ai_move
  178. mov eax,board_state
  179. and eax,[ai_comp_moves+010h]
  180. cmp eax,[ai_comp_moves+010h]
  181. je ai_move
  182. mov eax,board_state
  183. and eax,[ai_comp_moves+014h]
  184. cmp eax,[ai_comp_moves+014h]
  185. je ai_move
  186. jmp try_cmp ; try another more interesting square
  187.  
  188. @@: cmp ebx,4
  189. jne @f
  190. mov eax,board_state
  191. and eax,[ai_comp_moves+018h] ; check winning combinations
  192. cmp eax,[ai_comp_moves+018h]
  193. je ai_move ; is this a winning move? or the best move?
  194. mov eax,board_state
  195. and eax,[ai_comp_moves+01Ch]
  196. cmp eax,[ai_comp_moves+01Ch]
  197. je ai_move
  198. ; blocking code
  199. mov eax,board_state ; load board state
  200. and eax,[ai_comp_moves+020h] ; and with player aggression
  201. cmp eax,[ai_comp_moves+020h] ; determine if player is in a '1 move to win' situation
  202. je ai_move ; We must block or player can win
  203. mov eax,board_state ; ...
  204. and eax,[ai_comp_moves+024h] ; another '1 move to win' situation for the player
  205. cmp eax,[ai_comp_moves+024h] ; hopefully it's not set...
  206. je ai_move ; it's set, play the block.
  207. jmp try_cmp ; try another more interesting square
  208.  
  209. @@: cmp ebx,8
  210. jne @f
  211. mov eax,board_state
  212. and eax,[ai_comp_moves+028h] ; check winning combinations
  213. cmp eax,[ai_comp_moves+028h]
  214. je ai_move ; is this a winning move?
  215. mov eax,board_state
  216. and eax,[ai_comp_moves+02Ch]
  217. cmp eax,[ai_comp_moves+02Ch]
  218. je ai_move
  219. mov eax,board_state
  220. and eax,[ai_comp_moves+030h]
  221. cmp eax,[ai_comp_moves+030h]
  222. je ai_move
  223. ; blocking code
  224. mov eax,board_state ; load board state
  225. and eax,[ai_comp_moves+034h] ; and with player aggression
  226. cmp eax,[ai_comp_moves+034h] ; determine if player is in a '1 move to win' situation
  227. je ai_move ; We must block or player can win
  228. mov eax,board_state ; ...
  229. and eax,[ai_comp_moves+038h] ; another '1 move to win' situation for the player
  230. cmp eax,[ai_comp_moves+038h] ; hopefully it's not set...
  231. je ai_move ; it's set, play the block.
  232. mov eax,board_state ; ...
  233. and eax,[ai_comp_moves+03Ch]
  234. cmp eax,[ai_comp_moves+03Ch] ; hopefully it's not set...
  235. je ai_move ; it's set, play the block.
  236. jmp try_cmp ; try another more interesting square
  237.  
  238. @@: cmp ebx,12
  239. jne @f
  240. mov eax,board_state
  241. and eax,[ai_comp_moves+040h] ; check winning combinations
  242. cmp eax,[ai_comp_moves+040h]
  243. je ai_move ; is this a winning move? or the best move?
  244. mov eax,board_state
  245. and eax,[ai_comp_moves+044h]
  246. cmp eax,[ai_comp_moves+044h]
  247. je ai_move
  248. ; blocking code
  249. mov eax,board_state ; load board state
  250. and eax,[ai_comp_moves+048h]
  251. cmp eax,[ai_comp_moves+048h]
  252. je ai_move ; We must block or player can win
  253. mov eax,board_state ; ...
  254. and eax,[ai_comp_moves+04Ch] ; another '1 move to win' situation for the player
  255. cmp eax,[ai_comp_moves+04Ch] ; hopefully it's not set...
  256. je ai_move ; it's set, play the block.
  257. jmp try_cmp ; try another more interesting square
  258.  
  259. @@: cmp ebx,16
  260. jne @f
  261. mov eax,board_state
  262. and eax,[ai_comp_moves+050h] ; check winning combinations
  263. cmp eax,[ai_comp_moves+050h]
  264. je ai_move ; is this a winning move?
  265. mov eax,board_state
  266. and eax,[ai_comp_moves+054h]
  267. cmp eax,[ai_comp_moves+054h]
  268. je ai_move
  269. mov eax,board_state
  270. and eax,[ai_comp_moves+058h]
  271. cmp eax,[ai_comp_moves+058h]
  272. je ai_move
  273. mov eax,board_state
  274. and eax,[ai_comp_moves+05Ch]
  275. cmp eax,[ai_comp_moves+05Ch]
  276. je ai_move
  277. ; blocking code
  278. mov eax,board_state ; load board state
  279. and eax,[ai_comp_moves+060h] ; and with player aggression
  280. cmp eax,[ai_comp_moves+060h] ; determine if player is in a '1 move to win' situation
  281. je ai_move ; We must block or player can win
  282. mov eax,board_state ; ...
  283. and eax,[ai_comp_moves+064h]
  284. cmp eax,[ai_comp_moves+064h]
  285. je ai_move ; it's set, play the block.
  286. mov eax,board_state ; ...
  287. and eax,[ai_comp_moves+068h] ; another '1 move to win' situation for the player
  288. cmp eax,[ai_comp_moves+068h] ; hopefully it's not set...
  289. je ai_move ; it's set, play the block.
  290. mov eax,board_state ; ...
  291. and eax,[ai_comp_moves+06Ch] ; another '1 move to win' situation for the player
  292. cmp eax,[ai_comp_moves+06Ch] ; hopefully it's not set...
  293. je ai_move ; it's set, play the block.
  294. jmp try_cmp ; try another more interesting square
  295.  
  296. @@: cmp ebx,20
  297. jne @f
  298. mov eax,board_state
  299. and eax,[ai_comp_moves+070h] ; check winning combinations
  300. cmp eax,[ai_comp_moves+070h]
  301. je ai_move
  302. mov eax,board_state
  303. and eax,[ai_comp_moves+074h]
  304. cmp eax,[ai_comp_moves+074h]
  305. je ai_move
  306.  
  307. mov eax,board_state ; ...
  308. and eax,[ai_comp_moves+078h]
  309. cmp eax,[ai_comp_moves+078h] ; hopefully it's not set...
  310. je ai_move ; it's set, play the block.
  311. mov eax,board_state
  312. and eax,[ai_comp_moves+07Ch]
  313. cmp eax,[ai_comp_moves+07Ch]
  314. je ai_move ; it's set, play the block.
  315. jmp try_cmp ; try another more interesting square
  316.  
  317. @@: cmp ebx,24
  318. jne @f
  319. mov eax,board_state
  320. and eax,[ai_comp_moves+080h] ; check winning combinations
  321. cmp eax,[ai_comp_moves+080h]
  322. je ai_move
  323. mov eax,board_state
  324. and eax,[ai_comp_moves+084h]
  325. cmp eax,[ai_comp_moves+084h]
  326. je ai_move
  327. mov eax,board_state
  328. and eax,[ai_comp_moves+088h]
  329. cmp eax,[ai_comp_moves+088h]
  330. je ai_move
  331. ; blocking code
  332. mov eax,board_state ; load board state
  333. and eax,[ai_comp_moves+08Ch] ; and with player aggression
  334. cmp eax,[ai_comp_moves+08Ch]
  335. je ai_move ; We must block or player can win
  336. mov eax,board_state
  337. and eax,[ai_comp_moves+090h]
  338. cmp eax,[ai_comp_moves+090h] ; hopefully it's not set...
  339. je ai_move ; it's set, play the block.
  340. mov eax,board_state
  341. and eax,[ai_comp_moves+094h]
  342. cmp eax,[ai_comp_moves+094h] ; hopefully it's not set...
  343. je ai_move ; it's set, play the block.
  344. jmp try_cmp ; try another interesting square
  345.  
  346. @@: cmp ebx,28
  347. jne @f
  348. mov eax,board_state
  349. and eax,[ai_comp_moves+098h] ; check winning combinations
  350. cmp eax,[ai_comp_moves+098h]
  351. je ai_move ; is this a winning move? or the best move?
  352. mov eax,board_state
  353. and eax,[ai_comp_moves+09Ch]
  354. cmp eax,[ai_comp_moves+09Ch]
  355. je ai_move
  356.  
  357. mov eax,board_state ; ...
  358. and eax,[ai_comp_moves+0A0h] ; another '1 move to win' situation for the player
  359. cmp eax,[ai_comp_moves+0A0h] ; hopefully it's not set...
  360. je ai_move ; it's set, play the block.
  361. mov eax,board_state ; ...
  362. and eax,[ai_comp_moves+0A4h]
  363. cmp eax,[ai_comp_moves+0A4h] ; hopefully it's not set...
  364. je ai_move ; it's set, play the block.
  365. jmp try_cmp ; try another more interesting square
  366.  
  367. ; (final square), try an advantageous sequence here after testing wins/blocks
  368. @@: cmp ebx,32
  369. jne @f
  370. mov eax,board_state
  371. and eax,[ai_comp_moves+0A8h] ; check winning combinations
  372. cmp eax,[ai_comp_moves+0A8h]
  373. je ai_move
  374. mov eax,board_state
  375. and eax,[ai_comp_moves+0ACh]
  376. cmp eax,[ai_comp_moves+0ACh]
  377. je ai_move
  378. mov eax,board_state
  379. and eax,[ai_comp_moves+0B0h]
  380. cmp eax,[ai_comp_moves+0B0h]
  381. je ai_move
  382. ; blocking code
  383. mov eax,board_state ; load board state
  384. and eax,[ai_comp_moves+0B4h]
  385. cmp eax,[ai_comp_moves+0B4h] ; determine if player is in a '1 move to win' situation
  386. je ai_move ; We must block or player can win
  387. mov eax,board_state ; ...
  388. and eax,[ai_comp_moves+0B8h]
  389. cmp eax,[ai_comp_moves+0B8h]
  390. je ai_move ; it's set, play the block.
  391. mov eax,board_state ; ...
  392. and eax,[ai_comp_moves+0BCh]
  393. cmp eax,[ai_comp_moves+0BCh] ; hopefully it's not set...
  394. je ai_move ; it's set, play the block.
  395.  
  396. ; now just make a move in a decent sequence - 4,0,5,6,1,8,3,2,7
  397. mov eax,board_state ; load board state..
  398. and eax,[comptr_values+010h] ; center square
  399. cmp eax,[comptr_values+010h] ; test if bit was set
  400. je @f ; computer already owns this square
  401. mov eax,board_state ; reload board state
  402. and eax,[player_values+010h] ; and with player value table
  403. cmp eax,[player_values+010h] ; bit set?
  404. je @f ; player owns this square
  405. mov ebx,010h
  406. jmp ai_move
  407.  
  408. @@: mov eax,board_state ; load board state..
  409. and eax,[comptr_values] ; upper-left square
  410. cmp eax,[comptr_values] ; test if bit was set
  411. je @f ; computer already owns this square
  412. mov eax,board_state ; reload board state
  413. and eax,[player_values] ; and with player value table
  414. cmp eax,[player_values] ; bit set?
  415. je @f ; player owns this square
  416. xor ebx,ebx
  417. jmp ai_move
  418.  
  419. @@: mov eax,board_state ; load board state..
  420. and eax,[comptr_values+014h] ; middle-right square
  421. cmp eax,[comptr_values+014h] ; test if bit was set
  422. je @f ; computer already owns this square
  423. mov eax,board_state ; reload board state
  424. and eax,[player_values+014h] ; and with player value table
  425. cmp eax,[player_values+014h] ; bit set?
  426. je @f ; player owns this square
  427. mov ebx,014h
  428. jmp ai_move
  429.  
  430. @@: mov eax,board_state ; load board state..
  431. and eax,[comptr_values+018h] ; lower-left square
  432. cmp eax,[comptr_values+018h] ; test if bit was set
  433. je @f ; computer already owns this square
  434. mov eax,board_state ; reload board state
  435. and eax,[player_values+018h] ; and with player value table
  436. cmp eax,[player_values+018h] ; bit set?
  437. je @f ; player owns this square
  438. mov ebx,018h
  439. jmp ai_move
  440.  
  441. @@: mov eax,board_state ; load board state..
  442. and eax,[comptr_values+04h] ; upper-center square
  443. cmp eax,[comptr_values+04h] ; test if bit was set
  444. je @f ; computer already owns this square
  445. mov eax,board_state ; reload board state
  446. and eax,[player_values+04h] ; and with player value table
  447. cmp eax,[player_values+04h] ; bit set?
  448. je @f ; player owns this square
  449. mov ebx,04h
  450. jmp ai_move
  451.  
  452. @@: mov eax,board_state ; load board state..
  453. and eax,[comptr_values+020h] ; lower-right square
  454. cmp eax,[comptr_values+020h] ; test if bit was set
  455. je @f ; computer already owns this square
  456. mov eax,board_state ; reload board state
  457. and eax,[player_values+020h]
  458. cmp eax,[player_values+020h] ; bit set?
  459. je @f ; player owns this square
  460. mov ebx,020h
  461. jmp ai_move
  462.  
  463. @@: mov eax,board_state ; load board state..
  464. and eax,[comptr_values+0Ch] ; middle-left square
  465. cmp eax,[comptr_values+0Ch] ; test if bit was set
  466. je @f ; computer already owns this square
  467. mov eax,board_state ; reload board state
  468. and eax,[player_values+0Ch]
  469. cmp eax,[player_values+0Ch] ; bit set?
  470. je @f ; player owns this square
  471. mov ebx,0Ch
  472. jmp ai_move
  473.  
  474. @@: mov eax,board_state ; load board state..
  475. and eax,[comptr_values+08h] ; upper-right square
  476. cmp eax,[comptr_values+08h] ; test if bit was set
  477. je @f ; computer already owns this square
  478. mov eax,board_state ; reload board state
  479. and eax,[player_values+08h]
  480. cmp eax,[player_values+08h] ; bit set?
  481. je @f ; player owns this square
  482. mov ebx,08h
  483. jmp ai_move
  484.  
  485. @@: mov ebx,01Ch ; lower-left square
  486.  
  487. ai_move:
  488. mov eax,board_state
  489. add eax,[comptr_values+ebx] ; set the bit
  490. mov board_state,eax ; save new board state
  491. ;print str$([comptr_values+ebx]) ; debugging...
  492. jmp mov_ret ; cruise...
  493.  
  494. ; =============================== test_win =====================================
  495. test_win:
  496. push ebx ; preserve registers
  497. mov ecx,board_state ; load current state of board
  498. xor edx,edx ; counter for table traversal
  499.  
  500. traverse:
  501. mov ebx,ecx ; load for manipulation
  502. mov eax,ecx ; load for manipulation
  503. and ebx,[cmp_win_table+edx] ; and cmp_win_table for computer win
  504. and eax,[plr_win_table+edx] ; and plr_win_table for player win
  505. cmp ebx,[cmp_win_table+edx] ; test result with cmp_win_table
  506. je computa ; equal, computer wins
  507. cmp eax,[plr_win_table+edx] ; test result with plr_win_table
  508. je playa ; equal, player wins
  509. add edx,4 ; increment counter
  510. cmp edx,32
  511. jb traverse ; continue
  512.  
  513. and ecx,game_over_bit ; determine if all moves are exhausted
  514. cmp ecx,game_over_bit ; ...
  515. jne clean ; nope, next move
  516. print addr itsa_tie ; must be a tie..
  517. print addr two_newlines ; couple newlines
  518. add byte ptr[num_wins+2],1
  519.  
  520. score:
  521. print chr$(" Computer: ") ; print scores
  522. xor eax,eax
  523. mov al,byte ptr[num_wins]
  524. print str$(eax)
  525. print chr$(" Player: ")
  526. xor eax,eax
  527. mov al,byte ptr[num_wins+1]
  528. print str$(eax)
  529. print chr$(" Ties: ")
  530. xor eax,eax
  531. mov al,byte ptr[num_wins+2]
  532. print str$(eax)
  533.  
  534. clean:
  535. print addr one_newline
  536. pop ebx ; clean up
  537. ret ; return
  538.  
  539. computa:
  540. print addr cmp_win ; computer wins
  541. print addr two_newlines ; couple newlines
  542. mov eax,game_over_bit ; game over
  543. add board_state,eax ; update board state
  544. add byte ptr[num_wins],1
  545. jmp score ; clean up
  546.  
  547. playa:
  548. print addr plr_win ; player wins
  549. print addr two_newlines ; couple newlines
  550. mov eax,game_over_bit ; game over
  551. add board_state,eax ; update board state
  552. add byte ptr[num_wins+1],1
  553. jmp score
  554.  
  555. ; =============================== show_board ==================================
  556. show_board:
  557. push ebx ; preserve registers
  558. push esi ; continue housekeeping
  559. push edi ; ...
  560. mov ecx,board_state ; load current state
  561. lea esi,comptr_values ; address computer values
  562. lea edi,player_values ; address player values
  563. xor ebx,ebx ; counter for table traversal
  564. sub esi,4 ; prepare fer computer_value table cipherin'
  565. sub edi,4 ; prepare fer player_value table cipherin'
  566.  
  567. l1:
  568. mov eax,ecx ; load board state for testing
  569. add esi,4 ; update pointer to computer values table
  570. mov edx,ecx ; load board state for testing against player
  571. add edi,4 ; update pointer to player values table
  572. and eax,[esi] ; computer == 'O'
  573. and edx,[edi] ; player == 'X'
  574. cmp eax,[esi] ; computer owns the square
  575. je c_square ; ...
  576. cmp edx,[edi] ; player owns the square
  577. je p_square ; ...
  578. mov byte ptr[board_view+ebx],'-' ; unoccupied square
  579.  
  580. pr_ret:
  581. add ebx,1 ; increment base index for board_view
  582. cmp ebx,9 ; last one?
  583. jnz l1 ; continue
  584.  
  585. print addr one_newline ; newline
  586. lea edi,buffer ; buffer helps break down board_view for print
  587. lea esi,board_view ; load effective address board_view
  588. mov ax,[esi] ; load first word
  589. stosw ; store word
  590. mov al,[esi+2] ; load next byte
  591. stosb ; store byte
  592. print addr s_format ; formatting
  593. print addr buffer ; print 1 word and 1 byte
  594. print addr one_newline ; newline
  595.  
  596. lea edi,buffer ; reload buffer
  597. mov ax,[esi+3] ; load word
  598. stosw ; store word
  599. mov al,[esi+5] ; load byte
  600. stosb ; store byte
  601. print addr s_format ; formatting
  602. print addr buffer ; print the 3 characters in buffer
  603. print addr one_newline ; newline
  604.  
  605. lea edi,buffer ; reload
  606. mov ax,[esi+6] ; load word
  607. stosw ; store it
  608. mov al,[esi+8] ; load byte
  609. stosb ; store byte
  610. print addr s_format ; formatting
  611. print addr buffer ; print 3 characters
  612. print addr one_newline ; newline
  613. pop edi ; sweep...
  614. pop esi ; mop...
  615. pop ebx ; and wax...
  616. ret ; return to caller
  617.  
  618. p_square:
  619. mov byte ptr[board_view+ebx],'X' ; set players square
  620. jmp pr_ret ; return
  621.  
  622. c_square:
  623. mov byte ptr[board_view+ebx],'O' ; set computers square
  624. jmp pr_ret ; return
  625.  
  626. end start