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


(Industry-Level, Second-to-None Comprehensive Specifications)


Absolutely no copying others’ works

(Unlike other languages, using others’ assembly code is obvious. Assembly-language programming is not easy, but the instructor has made the specifications as simple as possible and provides much code. You should be able to get the exercises done based on the given code.)

Development Requirements
When start developing the exercise, follow the two requirements below:


Soft Due Date and Submission Method
On or before Thursday, February 15, 2024 and upload the source code (no documentation needed) to the section of “COVID-19 Exams, Homeworks, & Programming Exercises” of Blackboard.

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 a MIPS assembly program, which displays a tic-tac-toe game of one player. The final program is about 100 lines, most of which are for I/O. 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, for-display-only 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, where the italic, white text with a navy background color is entered by users:

Examples of Exercise I Execution
Start Showing a One-Player Tic-Tac-Toe Game.

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

Enter the next move (1-9):   4 

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

Continue? (y/n)   y 
Enter the next move (1-9):   3 

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

Continue? (y/n)   y 
Enter the next move (1-9):   8 

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

Continue? (y/n)   n 
New game? (y/n)   y 

Start Showing a One-Player Tic-Tac-Toe Game.

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

Enter the next move (1-9):   6 

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

Continue? (y/n)   y 
Enter the next move (1-9):   1 

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

Continue? (y/n)   n 
New game? (y/n)   n 
-- program is finished running --


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
MIPS Instruction Reference.

No. Directive Description
1 .ascii "string" Allocating space for string
2 .asciiz "string" Allocating space for string, NULL terminated
3 .byte Allocating space for a byte
4 .data Beginning of data section
5 .globl name Making the following name be a global symbol
6 .space n Allocating n bytes of space
7 .text Beginning of text section
No. Instruction Operation Description
1 add rd, rs, rt rd = rs + rt Add;
rd: destination register, rs: first source register, and rt: second source register or immediate value.
Check MIPS Registers and Usage Convention.
2 addu rd, rs, rt rd = rs + rt (no overflow) Add unsigned
3 beq rs, rt, label if rs==rt then goto label Branch if equal to
4 blt rs, rt, label if rs<rt then goto label Branch if less than
5 div rd, rs, rt rd = rs ÷ rt Divide
6 j label jump to label Jump
7 la rd, mem rd = address( mem ) Load address
8 lb rd, mem rd = mem Load byte
9 li rd, imm rd = imm Load immediate
10 lw rd, mem rd = mem Load word
11 mul rd, rs, rt rd = rs × rt Multiply
12 sb rs, mem mem = rs Store byte
13 sub rd, rs, rt rd = rs - rt Subtract
14 subu rd, rs, rt rd = rs - rt (no overflow) Subtract unsigned
15 sw rs, mem mem = rs Store word
16 syscall   System call; check System Services.

The following table lists some System Services provided by the MARS:

Service Code in $v0 Arguments Result
print_int 1 $a0 = integer to be printed  
print_float 2 $f12 = float to be printed  
print_double 3 $f12 = double to be printed  
print_string 4 $a0 = address of string in memory  
read_int 5   integer returned in $v0
read_float 6   float returned in $v0
read_double 7   double returned in $v0
read_string 8 $a0 = address of string input buffer
$a1 = length of string buffer (n)
 
malloc 9 $a0 = amount address in $v0
exit 10    
print character 11 $a0 = character to be printed  
read character 12   character returned in $v0

Evaluations
The following features will be considered when grading: