Programming Exercise I: Showing a Tic-Tac-Toe Game


Absolutely no copying others’ works

Development Requirements
When start developing the exercise, have to use:
  • MASM (Microsoft Macro Assembler) assembly language and
  • Microsoft Visual Studio to develop and test your exercise.
An online tic-tac-toe game is here.

Due Date† and Submission Method
On or before Monday, October 19, 2026 and upload the source code (no documentation needed) to the Blackboard section:
Use the template from Using MASM and replace the assembly code by . If the code does not work, a demonstration will be requested by the instructor.

†Since related topics may not be covered completely by the due date, no penalty will be applied if submitted after the due date. However, you may lag behind if you are not able to submit it by then. In addition, the Exam I will cover the materials from the Programming Exercise I.

Objective
Design and implement an MASM assembly program, which displays a tic-tac-toe game. The purpose of this exercise is to get students ready for assembly programming and the second exercise, playing a tic-tac-toe game.



Requirements
The 3×3 tic-tac-toe game includes the following requirements:

Programming Hints
The four essential components of software are (i) algorithms, (ii) data structures, (iii) programming languages, and (iv) code, where algorithms are the most critical one. In addition, using appropriate data structures could save a great deal of coding work, especially for assembly coding. The following hints are from the instructor and you do not necessarily have to use them: Execution Examples
The following list shows some execution examples:

Examples of Exercise I Execution

Start Showing a Tic-Tac-Toe Game.

You (User) pick a piece: (X or O)   X 

     | |       1|2|3
    -----      -----
     | |       4|5|6
    -----      -----
     | |       7|8|9

You (User) enter the next move: (1..9)  5 

     | |       1|2|3
    -----      -----
     |X|       4|5|6
    -----      -----
     | |       7|8|9

Continue?: (Y or N)  Y 

I (System) enter the next move: 3

     | |O      1|2|3
    -----      -----
     |X|       4|5|6
    -----      -----
     | |       7|8|9

Continue?: (Y or N)  Y 

You (User) enter the next move: (1..9)  8 

     | |O      1|2|3
    -----      -----
     |X|       4|5|6
    -----      -----
     |X|       7|8|9

Continue?: (Y or N)  N 

New game?: (Y or N)  Y 


Start Showing a Tic-Tac-Toe Game.

I (System) make the move: 4

     | |       1|2|3
    -----      -----
    X| |       4|5|6
    -----      -----
     | |       7|8|9

Continue?: (Y or N)  Y 

You (User) enter the next move: (1..9)  9 

     | |       1|2|3
    -----      -----
    X| |       4|5|6
    -----      -----
     | |O      7|8|9

Continue?: (Y or N)  Y 

I (System) enter the next move: 7

     | |       1|2|3
    -----      -----
    X| |       4|5|6
    -----      -----
    X| |O      7|8|9

Continue?: (Y or N)  N 

New game?: (Y or N)  N 

C:\ASM-workspace\Ex1\Debug\Project.exe (process 41384) exited with code 0 (0x0).
Press any key to close this window . . .


Possible Instructions to Be Used
The following directives and instructions may be used in this exercise, but you are not limited to them. For instruction syntax, check
MASM Instruction Reference.

No. Directive Description
1 [name] BYTE initializer Defining byte
2 [name] DWORD initializer Defining doubleword
3 END [procid] Marks the last line of the program to be assembled.
4 ENDP Marks the end of a procedure.
5 .IF
.ELSEIF
.ELSE
.ENDIF
IF statement
6 OFFSET n Returns the offset of a data label.
7 label PROC Identifies the beginning of a procedure.
8 PROC … USES Lists the names of all registers modified within a procedure.
9 PROTO Creates a prototype for an existing procedure.
10 PTR Override the declared size of an operand.
No. Instruction Description
1 add r/m32, imm32 Add:

  r/m32: a 32-bit register or a 32-bit memory operand
  imm32: a constant 32-bit value
  Check MASM General-purpose Registers

  Example: add eax, temp
2 cmp r/m32, imm32 Compare two operands:

  Example: cmp eax, 10
3 dec r/m32 Decrement by 1:

  Example: dec eax
4 call rel32 Call procedure:

  rel32: a 32-bit signed relative displacement

  Example: call WriteString
5 idiv r/m32 Signed divide:

  EDX:EAX ÷ r/m32, with result stored in
  EAX := Quotient,
  EDX := Remainder.

  Example: idiv const3
6 imul r32, r/m32, imm32 Signed multiply:

  doubleword register := r/m32 × immediate doubleword

  Example: imul eax, eax, 2
7 je rel8 Jump short if equal (ZF=1):

  rel8: an 8-bit relative offset

  Example: je L1
8 jmp rel16 Jump

  rel16: a 16-bit relative offset

  Example: jmp L1
9 jne rel8 Jump short if not equal (ZF=0)

  rel8: an 8-bit relative offset

  Example: jne L1
10 loop rel8 Loop according to ECX counter:

  Decrement count; jump short if count ≠ 0

  Example: loop L1
11 mov r32, imm32 Move:

  Example: mov edx, OFFSET board
12 movzx r32, r/m16 Move with zero-extend:

  Example: movzx eax, r
13 not r/m32 One’s complement negation:

  Example: not eax
14 popad Pop all general-purpose registers:

  Example: popad
15 pushad Push all general-purpose registers:

  Example: pushad
16 ret Return from procedure:

  Example: ret
17 sub r/m32, imm32 Subtract:

  Example: sub eax, 10

The following table lists some procedures provided by Irvine:

Procedure Call args Return args Description Example
Crlf None None Writes a carriage return/linefeed sequence (,) to standard output. call Crlf
Randomize None None Re-seeds the random number generator with the current time in hundredths of seconds. call Randomize
RandomRange EAX = n, the range EAX = random (0 to n-1) Generates an unsigned pseudo-random 32-bit integer in the range of 0 through (n-1). Get a random number from 1 to 100:

ranNum DWORD ?

mov eax,100
call RandomRange
inc eax
mov ranNum,eax
ReadChar None AL = ASCII code Reads a single character from standard input and returns the character in the AL register. The character is not echoed on the screen. Waits for the character if none is currently in the input buffer. charIn BYTE ?

call ReadChar
mov charIn, al
WriteChar AL = the character to write None Writes a single character to standard output. mov al, '$'
call WriteChar
WriteString EDX = points to string None Writes a null-terminated string to standard output. prompt BYTE "Enter your name: ", 0

mov edx, OFFSET prompt
call WriteString

Evaluations
The following features will be considered when grading: