Tic Tac Toe
RepositoryTo improve my assembly skills, I have set myself the goal of writing Tic Tac Toe in assembly. I use the emu8086 emulator to test my assembly code. This project helped me a lot to learn more about the internal structure of a CPU. I learned how to use methods and loops in assembly, how to better handle user inputs and error handling in assembly. With this project I also learned how the 32 bit addresses inside a program look like and how to assign values to them.
Game initialisation
Here is the INIT method. This method initialises and declares all needed variables, in order to start the game without encountering any errors.
1INIT: ; init all variables
2 MOV PLAYER, 50
3 MOV MOVES, 0
4 MOV DONE, 0
5 MOV DR, 0
6
7 MOV C1, 49
8 MOV C2, 50
9 MOV C3, 51
10 MOV C4, 52
11 MOV C5, 53
12 MOV C6, 54
13 MOV C7, 55
14 MOV C8, 56
15 MOV C9, 57
16
17 JMP PLRCHANGEChecking Rules
This is a section of my CHECK method. This method goes over all possible combinations and checks if a Tic Tac Toe has come along somewhere. If that happens it assigns the winner. This method runs after every turn of both players.
1CHECK: ; 8 possible combinations
2 CHECK1: ; checking combo combo 1, 2, 3
3 MOV AL, C1
4 MOV BL, C2
5 MOV CL, C3
6
7 CMP AL, BL
8 JNZ CHECK2
9
10 CMP BL, CL
11 JNZ CHECK2
12
13 MOV DONE, 1
14 JMP BOARD
15
16 CHECK2: ; checking combo 4, 5, 6
17 MOV AL, C4
18 MOV BL, C5
19 MOV CL, C6
20
21 CMP AL, BL
22 JNZ CHECK3
23
24 CMP BL, CL
25 JNZ CHECK3
26
27 MOV DONE, 1
28 JMP BOARD
29
30 CHECK3: ; checking combo 7, 8, 9
31 MOV AL, C4
32 MOV BL, C5
33 MOV CL, C6
34
35 CMP AL, BL
36 JNZ CHECK4
37
38 CMP BL, CL
39 JNZ CHECK4
40
41 MOV DONE, 1
42 JMP BOARDHandling invalid Inputs
This here is my TAKEN method. This method makes sure that no invalid inputs are made. If an invalid input is made, it overwrites the last input with an empty line
1TAKEN:
2 DEC MOVES ; set cursor
3 MOV AH, 4
4 MOV DH, 16
5 MOV DL, 20
6 INT 10h
7
8 LEA DX, TKN ; cell taken display
9 MOV AH, 9
10 INT 21h
11
12 MOV AH, 7
13 INT 21h ; set cursor
14 MOV AH, 2
15 MOV DH, 16
16 MOV DL, 20
17 INT 10h
18
19 LEA DX, EMP ; empty line to overwrite
20 MOV AH, 9
21 INT 21h ; set cursor
22 MOV AH, 2
23 MOV DH, 16
24 MOV DL, 20
25 INT 10h
26
27 JMP INPUT