Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- game:
- push ecx ; save the value in ecx
- xor byte [board + 19], 1 ; player_number is turned to its opposite (1 -> 0 or 0 -> 1)
- mov eax, 4 ; SYS_WRITE board
- mov ebx, 1
- mov ecx, board
- mov edx, 19
- int 0x80
- mov eax, 3 ; SYS_READ user_input
- mov ebx, 2
- mov ecx, board + 20
- mov edx, 2
- int 0x80
- sub byte [board + 20], 49 ; user_input is converted from ascii to equivalent integer and lowered by 1 (it is lowered so that input is 1-9 and not 0-8)
- mov eax, board + 7 ; board's address moved into eax register
- add al, [board + 20] ; adjust address based on user_input
- cmp al, 10 ; since the board has two new-lines in it, this adjusts the address based on them. (AL starts at 00 for the first address in .data)
- jl n
- inc al
- cmp al, 14
- jl n
- inc al
- n:
- mov bl, [board + 19] ; move player_number into bl, turn it into ascii, then place in the spot on the board that corresponds to player_input
- add bl, 48
- mov byte [eax], bl
- mov ecx, 8 ; prepare horizontal loop
- h:
- mov al, [board + ecx + 7] ; adds horizontal spaces together and checks them against 144 and 147 (if they equal either one they are all the same)
- add al, [board + ecx + 8]
- add al, [board + ecx + 9]
- cmp al, 144
- je exit
- cmp al, 147
- je exit
- sub ecx, 4 ; horizontal loop
- cmp ecx, 0
- jge h
- mov ecx, 2 ; prepare vertical loop
- v:
- mov al, [board + ecx + 7] ; same as previous but for vertical
- add al, [board + ecx + 11]
- add al, [board + ecx + 15]
- cmp al, 144
- je e
- cmp al, 147
- je e
- dec ecx ; vertical loop
- cmp ecx, 0
- jge v
- mov al, [board + 7] ; checks first diagonal
- add al, [board + 12]
- add al, [board + 17]
- cmp al, 144
- je e
- cmp al, 147
- je e
- mov al, [board + 9] ; checks second diagonal
- add al, [board + 12]
- add al, [board + 15]
- cmp al, 144
- je e
- cmp al, 147
- je e
- pop ecx ; loop
- inc cl
- cmp cl, 9
- jl g
- exit:
- mov eax, 0x1 ; sys_exit
- xor ebx, ebx
- int 0x80
- section .data
- board db 27,"[H",27,"[2J___",10,"___",10,"___",10,1,1
- ; 27,"[H",27,"[2J" is the code for a console clear. Having it at the start effectively clears the console each time the board is displayed
- ; "___",10,"___",10,"___",10 is the board
- ; 1,1 are 'variables' (player_number and user_input). Normally they would be in the .bss section, but to conserve space, I made them .data
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement