Programming Exercise II: Playing an SOS Game


Absolutely no copying others’ works
(Unlike other languages, using others’ assembly code is obvious.)

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

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



Objective
Design and implement a MIPS assembly program, which has the user play a 6×6 SOS game against the computer. The final program is less than 300 lines without counting the declarations of data structures. The purpose of this exercise is to make students practice assembly language programming including various control instructions, functions, and the runtime stack.


An incomplete game of SOS in an 8×8 board



Rules of an SOS Game
It is a board game for two players who take turns in putting the pieces S and O on empty cells of a board. Before play begins, a square grid of at least 3×3 squares in size is drawn. Players take turns to add either an ‘S’ or an ‘O’ to any square, with no requirement to use the same letter each turn.

The object of the game is for each player to attempt to create the straight sequence S-O-S among connected squares (either diagonally, horizontally, or vertically), and to create as many such sequences as they can. If a player succeeds in creating an SOS, that player immediately takes another turn, and continues to do so until no SOS can be created on their turn. Otherwise turns alternate between players after each move. Keeping track of who made which SOSs can be done by, e.g., one player circling their SOSs and the other player drawing a line through theirs. Once the grid has been filled up, the winner is the player who made the most SOSs. If the grid is filled up and the number of SOSs for each player is the same, then the game is a draw.



Requirements
The 6×6 SOS 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:
Examples
The following list shows some execution examples, where the white, italic text with a black background color is entered by users:

Examples of Exercise II Execution
Start Playing an SOS Game:

    . . . . . .      0 1 2 3 4 5
    . . . . . .      6 7 8 9 a b
    . . . . . .      c d e f g h
    . . . . . .      i j k l m n
    . . . . . .      o p q r s t
    . . . . . .      u v w x y z

I (System) am first and I pick the piece S
The move from me is m
Number of total SOSs created so far: 0
Number of SOSs created by me so far: 0

    . . . . . .      0 1 2 3 4 5
    . . . . . .      6 7 8 9 a b
    . . . . . .      c d e f g h
    . . . . S .      i j k l m n
    . . . . . .      o p q r s t
    . . . . . .      u v w x y z

Continue? (y/n)  y  
Your turn.  You (User) pick a piece: (S|O)  O 
Enter your next move: [0..z]  a 
Number of total SOSs created so far: 0
Number of SOSs created by you so far: 0

    . . . . . .      0 1 2 3 4 5
    . . . . O .      6 7 8 9 a b
    . . . . . .      c d e f g h
    . . . . S .      i j k l m n
    . . . . . .      o p q r s t
    . . . . . .      u v w x y z

Hit the spacebar to start the System’s next move.
 
My turn.  I (System) pick the piece O
The move from me is 8
Number of total SOSs created so far: 0
Number of SOSs created by me so far: 0

    . . . . . .      0 1 2 3 4 5
    . . O . O .      6 7 8 9 a b
    . . . . . .      c d e f g h
    . . . . S .      i j k l m n
    . . . . . .      o p q r s t
    . . . . . .      u v w x y z

Continue? (y/n)  y 
Your turn.  You (User) pick a piece: (S|O)  O 
Enter your next move: [0..z]  1 
Number of total SOSs created so far: 0
Number of SOSs created by you so far: 0

    . O . . . .      0 1 2 3 4 5
    . . O . O .      6 7 8 9 a b
    . . . . . .      c d e f g h
    . . . . S .      i j k l m n
    . . . . . .      o p q r s t
    . . . . . .      u v w x y z

Hit the spacebar to start the System’s next move.
  
My turn.  I (System) pick the piece S
The move from me is t
Number of total SOSs created so far: 0
Number of SOSs created by me so far: 0

    . O . . . .      0 1 2 3 4 5
    . . O . O .      6 7 8 9 a b
    . . . . . .      c d e f g h
    . . . . S .      i j k l m n
    . . . . . S      o p q r s t
    . . . . . .      u v w x y z

Continue? (y/n)  y 
Your turn.  You (User) pick a piece: (S|O)  O 
Enter your next move: [0..z]  o 
Number of total SOSs created so far: 0
Number of SOSs created by you so far: 0

    . O . . . .      0 1 2 3 4 5
    . . O . O .      6 7 8 9 a b
    . . . . . .      c d e f g h
    . . . . S .      i j k l m n
    O . . . . S      o p q r s t
    . . . . . .      u v w x y z

Hit the spacebar to start the System’s next move.
  
My turn.  I (System) pick the piece S
The move from me is x
Number of total SOSs created so far: 0
Number of SOSs created by me so far: 0

    . O . . . .      0 1 2 3 4 5
    . . O . O .      6 7 8 9 a b
    . . . . . .      c d e f g h
    . . . . S .      i j k l m n
    O . . . . S      o p q r s t
    . . . S . .      u v w x y z

Continue? (y/n)  y 
Your turn.  You (User) pick a piece: (S|O)  O 
Enter your next move: [0..z]  h 
Number of total SOSs created so far: 0
Number of SOSs created by you so far: 0

    . O . . . .      0 1 2 3 4 5
    . . O . O .      6 7 8 9 a b
    . . . . . O      c d e f g h
    . . . . S .      i j k l m n
    O . . . . S      o p q r s t
    . . . S . .      u v w x y z

Hit the spacebar to start the System’s next move.
  
My turn.  I (System) pick the piece S
The move from me is 3
Number of total SOSs created so far: 0
Number of SOSs created by me so far: 0

    . O . S . .      0 1 2 3 4 5
    . . O . O .      6 7 8 9 a b
    . . . . . O      c d e f g h
    . . . . S .      i j k l m n
    O . . . . S      o p q r s t
    . . . S . .      u v w x y z

Continue? (y/n)  y 
Your turn.  You (User) pick a piece: (S|O)  S 
Enter your next move: [0..z]  d 
Number of total SOSs created so far: 1
Number of SOSs created by you so far: 1

    . O . S . .      0 1 2 3 4 5
    . . O . O .      6 7 8 9 a b
    . S . . . O      c d e f g h
    . . . . S .      i j k l m n
    O . . . . S      o p q r s t
    . . . S . .      u v w x y z

Continue? (y/n)  y 
Your turn.  You (User) pick a piece: (S|O)  S 
Enter your next move: [0..z]  k 
Number of total SOSs created so far: 1
Number of SOSs created by you so far: 1

    . O . S . .      0 1 2 3 4 5
    . . O . O .      6 7 8 9 a b
    . S . . . O      c d e f g h
    . . S . S .      i j k l m n
    O . . . . S      o p q r s t
    . . . S . .      u v w x y z

Hit the spacebar to start the System’s next move.
  
My turn.  I (System) pick the piece O
The move from me is l
Number of total SOSs created so far: 2
Number of SOSs created by me so far: 1

    . O . S . .      0 1 2 3 4 5
    . . O . O .      6 7 8 9 a b
    . S . . . O      c d e f g h
    . . S O S .      i j k l m n
    O . . . . S      o p q r s t
    . . . S . .      u v w x y z

Hit the spacebar to start the System’s next move.
 
My turn.  I (System) pick the piece O
The move from me is v
Number of total SOSs created so far: 2
Number of SOSs created by me so far: 1

    . O . S . .      0 1 2 3 4 5
    . . O . O .      6 7 8 9 a b
    . S . . . O      c d e f g h
    . . S O S .      i j k l m n
    O . . . . S      o p q r s t
    . O . S . .      u v w x y z

Continue? (y/n)  n 

A tied game!  I (System) have 1 SOSs and you (User) have 1 SOSs.
New game? (y/n)  y 

Start Playing an SOS Game:

    . . . . . .      0 1 2 3 4 5
    . . . . . .      6 7 8 9 a b
    . . . . . .      c d e f g h
    . . . . . .      i j k l m n
    . . . . . .      o p q r s t
    . . . . . .      u v w x y z

I (System) am first and I pick the piece O
The move from me is 5
Number of total SOSs created so far: 0
Number of SOSs created by me so far: 0

    . . . . . O      0 1 2 3 4 5
    . . . . . .      6 7 8 9 a b
    . . . . . .      c d e f g h
    . . . . . .      i j k l m n
    . . . . . .      o p q r s t
    . . . . . .      u v w x y z

Continue? (y/n)  y 
Your turn.  You (User) pick a piece: (S|O)  S 
Enter your next move: [0..z]  h 
Number of total SOSs created so far: 0
Number of created SOSs by me so far: 0

    . . . . . O      0 1 2 3 4 5
    . . . . . .      6 7 8 9 a b
    . . . . . S      c d e f g h
    . . . . . .      i j k l m n
    . . . . . .      o p q r s t
    . . . . . .      u v w x y z

Hit the spacebar to start the System’s next move.
  
My turn.  I (System) pick the piece O
The move from me is 6
Number of total SOSs created so far: 0
Number of created SOSs by me so far: 0

    . . . . . O      0 1 2 3 4 5
    O . . . . .      6 7 8 9 a b
    . . . . . S      c d e f g h
    . . . . . .      i j k l m n
    . . . . . .      o p q r s t
    . . . . . .      u v w x y z

Continue? (y/n)  y 
Your turn.  You (User) pick a piece: (S|O)  S 
Enter your next move: [0..z]  o 
Number of total SOSs created so far: 0
Number of SOSs created by you so far: 0

    . . . . . O      0 1 2 3 4 5
    O . . . . .      6 7 8 9 a b
    . . . . . S      c d e f g h
    . . . . . .      i j k l m n
    S . . . . .      o p q r s t
    . . . . . .      u v w x y z

Hit the spacebar to start the System’s next move.
  
My turn.  I (System) pick the piece O
The move from me is a
Number of total SOSs created so far: 0
Number of SOSs created by me so far: 0

    . . . . . O      0 1 2 3 4 5
    O . . . O .      6 7 8 9 a b
    . . . . . S      c d e f g h
    . . . . . .      i j k l m n
    S . . . . .      o p q r s t
    . . . . . .      u v w x y z

Continue? (y/n)  y 
Your turn.  You (User) pick a piece: (S|O)  S 
Enter your next move: [0..z]  3 
Number of total SOSs created so far: 1
Number of SOSs created by you so far: 1

    . . . S . O      0 1 2 3 4 5
    O . . . O .      6 7 8 9 a b
    . . . . . S      c d e f g h
    . . . . . .      i j k l m n
    S . . . . .      o p q r s t
    . . . . . .      u v w x y z

Continue? (y/n)  y 
Your turn.  You (User) pick a piece: (S|O)  S 
Enter your next move: [0..z]  y 
Number of total SOSs created so far: 1
Number of SOSs created by you so far: 1

    . . . S . O      0 1 2 3 4 5
    O . . . O .      6 7 8 9 a b
    . . . . . S      c d e f g h
    . . . . . .      i j k l m n
    S . . . . .      o p q r s t
    . . . . S .      u v w x y z

Hit the spacebar to start the System’s next move.
  
My turn.  I (System) pick the piece S
The move from me is x
Number of total SOSs created so far: 1
Number of SOSs created by me so far: 0

    . . . S . O      0 1 2 3 4 5
    O . . . O .      6 7 8 9 a b
    . . . . . S      c d e f g h
    . . . . . .      i j k l m n
    S . . . . .      o p q r s t
    . . . S S .      u v w x y z

Continue? (y/n)  y 
Your turn.  You (User) pick a piece: (S|O)  S 
Enter your next move: [0..z]  8 
Number of total SOSs created so far: 1
Number of SOSs created by you so far: 1

    . . . S . O      0 1 2 3 4 5
    O . S . O .      6 7 8 9 a b
    . . . . . S      c d e f g h
    . . . . . .      i j k l m n
    S . . . . .      o p q r s t
    . . . S S .      u v w x y z

Hit the spacebar to start the System’s next move.
  
My turn.  I (System) pick the piece O
The move from me is q
Number of total SOSs created so far: 1
Number of SOSs created by me so far: 0

    . . . S . O      0 1 2 3 4 5
    O . S . O .      6 7 8 9 a b
    . . . . . S      c d e f g h
    . . . . . .      i j k l m n
    S . O . . .      o p q r s t
    . . . S S .      u v w x y z

Continue? (y/n)  y 
Your turn.  You (User) pick a piece: (S|O)  S 
Enter your next move: [0..z]  j 
Number of total SOSs created so far: 2
Number of SOSs created by you so far: 2

    . . . S . O      0 1 2 3 4 5
    O . S . O .      6 7 8 9 a b
    . . . . . S      c d e f g h
    . S . . . .      i j k l m n
    S . O . . .      o p q r s t
    . . . S S .      u v w x y z

Continue? (y/n)  y 
Your turn.  You (User) pick a piece: (S|O)  O 
Enter your next move: [0..z]  f 
Number of total SOSs created so far: 2
Number of SOSs created by you so far: 2

    . . . S . O      0 1 2 3 4 5
    O . S . O .      6 7 8 9 a b
    . . . O . S      c d e f g h
    . S . . . .      i j k l m n
    S . O . . .      o p q r s t
    . . . S S .      u v w x y z

Hit the spacebar to start the System’s next move.
  
My turn.  I (System) pick the piece S
The move from me is m
Number of total SOSs created so far: 3
Number of SOSs created by me so far: 1

    . . . S . O      0 1 2 3 4 5
    O . S . O .      6 7 8 9 a b
    . . . O . S      c d e f g h
    . S . . S .      i j k l m n
    S . O . . .      o p q r s t
    . . . S S .      u v w x y z

Hit the spacebar to start the System’s next move.
 
My turn.  I (System) pick the piece O
The move from me is s
Number of total SOSs created so far: 4
Number of SOSs created by me so far: 2

    . . . S . O      0 1 2 3 4 5
    O . S . O .      6 7 8 9 a b
    . . . O . S      c d e f g h
    . S . . S .      i j k l m n
    S . O . O .      o p q r s t
    . . . S S .      u v w x y z

Hit the spacebar to start the System’s next move.
  
My turn.  I (System) pick the piece S
The move from me is n
Number of total SOSs created so far: 5
Number of SOSs created by me so far: 3

    . . . S . O      0 1 2 3 4 5
    O . S . O .      6 7 8 9 a b
    . . . O . S      c d e f g h
    . S . . S S      i j k l m n
    S . O . O .      o p q r s t
    . . . S S .      u v w x y z

Hit the spacebar to start the System’s next move.
  
My turn.  I (System) pick the piece  S 
The move from me is  l 
Number of total SOSs created so far: 5
Number of SOSs created by me so far: 3

    . . . S . O      0 1 2 3 4 5
    O . S . O .      6 7 8 9 a b
    . . . O . S      c d e f g h
    . S . S S S      i j k l m n
    S . O . O .      o p q r s t
    . . . S S .      u v w x y z

Continue? (y/n)  y 
Your turn.  You (User) pick a piece: (S|O)  O 
Enter your next move: (0..z)  r 
Number of total SOSs created so far: 6
Number of SOSs created by you so far: 3

    . . . S . O      0 1 2 3 4 5
    O . S . O .      6 7 8 9 a b
    . . . O . S      c d e f g h
    . S . S S S      i j k l m n
    S . O O O .      o p q r s t
    . . . S S .      u v w x y z

Continue? (y/n)  y 
Your turn.  You (User) pick a piece: (S|O)  S 
Enter your next move: (0..z)  z 
Number of total SOSs created so far: 7
Number of SOSs created by you so far: 4

    . . . S . O      0 1 2 3 4 5
    O . S . O .      6 7 8 9 a b
    . . . O . S      c d e f g h
    . S . S S S      i j k l m n
    S . O O O .      o p q r s t
    . . . S S S      u v w x y z

Continue? (y/n)  y 
Your turn.  You (User) pick a piece: (S|O)  O 
Enter your next move: (0..z)  v 
Number of total SOSs created so far: 7
Number of SOSs created by you so far: 4

    . . . S . O      0 1 2 3 4 5
    O . S . O .      6 7 8 9 a b
    . . . O . S      c d e f g h
    . S . S S S      i j k l m n
    S . O O O .      o p q r s t
    . O . S S S      u v w x y z

Hit the spacebar to start the System’s next move.
 
My turn.  I (System) pick the piece S
The move from me is w
Number of total SOSs created so far: 8
Number of SOSs created by me so far: 4

    . . . S . O      0 1 2 3 4 5
    O . S . O .      6 7 8 9 a b
    . . . O . S      c d e f g h
    . S . S S S      i j k l m n
    S . O O O .      o p q r s t
    . O S S S S      u v w x y z

Hit the spacebar to start the System’s next move.

My turn.  I (System) pick the piece S
The move from me is k
Number of total SOSs created so far: 10
Number of SOSs created by me so far: 6

    . . . S . O      0 1 2 3 4 5
    O . S . O .      6 7 8 9 a b
    . . . O . S      c d e f g h
    . S S S S S      i j k l m n
    S . O O O .      o p q r s t
    . O S S S S      u v w x y z

Hit the spacebar to start the System’s next move.
 
My turn.  I (System) pick the piece S
The move from me is u
Number of total SOSs created so far: 11
Number of SOSs created by me so far: 7

    . . . S . O      0 1 2 3 4 5
    O . S . O .      6 7 8 9 a b
    . . . O . S      c d e f g h
    . S S S S S      i j k l m n
    S . O O O .      o p q r s t
    S O S S S S      u v w x y z

Hit the spacebar to start the System’s next move.
 
My turn.  I (System) pick the piece S
The move from me is 9
Number of total SOSs created so far: 12
Number of SOSs created by me so far: 8

    . . . S . O      0 1 2 3 4 5
    O . S S O .      6 7 8 9 a b
    . . . O . S      c d e f g h
    . S S S S S      i j k l m n
    S . O O O .      o p q r s t
    S O S S S S      u v w x y z

Hit the spacebar to start the System’s next move.
 
My turn.  I (System) pick the piece O
The move from me is e
Number of total SOSs created so far: 14
Number of SOSs created by me so far: 10

    . . . S . O      0 1 2 3 4 5
    O . S S O .      6 7 8 9 a b
    . . O O . S      c d e f g h
    . S S S S S      i j k l m n
    S . O O O .      o p q r s t
    S O S S S S      u v w x y z

Hit the spacebar to start the System’s next move.
 
My turn.  I (System) pick the piece S
The move from me is b
Number of total SOSs created so far: 15
Number of SOSs created by me so far: 11

    . . . S . O      0 1 2 3 4 5
    O . S S O S      6 7 8 9 a b
    . . O O . S      c d e f g h
    . S S S S S      i j k l m n
    S . O O O .      o p q r s t
    S O S S S S      u v w x y z

Hit the spacebar to start the System’s next move.
 
My turn.  I (System) pick the piece O
The move from me is g
Number of total SOSs created so far: 17
Number of SOSs created by me so far: 13

    . . . S . O      0 1 2 3 4 5
    O . S S O S      6 7 8 9 a b
    . . O O O S      c d e f g h
    . S S S S S      i j k l m n
    S . O O O .      o p q r s t
    S O S S S S      u v w x y z

Hit the spacebar to start the System’s next move.
 
My turn.  I (System) pick the piece S
The move from me is 7
Number of total SOSs created so far: 18
Number of SOSs created by me so far: 14

    . . . S . O      0 1 2 3 4 5
    O S S S O S      6 7 8 9 a b
    . . O O O S      c d e f g h
    . S S S S S      i j k l m n
    S . O O O .      o p q r s t
    S O S S S S      u v w x y z

Hit the spacebar to start the System’s next move.
 
My turn.  I (System) pick the piece O
The move from me is t
Number of total SOSs created so far: 19
Number of SOSs created by me so far: 15

    . . . S . O      0 1 2 3 4 5
    O S S S O S      6 7 8 9 a b
    . . O O O S      c d e f g h
    . S S S S S      i j k l m n
    S . O O O O      o p q r s t
    S O S S S S      u v w x y z

Hit the spacebar to start the System’s next move.
 
My turn.  I (System) pick the piece O
The move from me is p
Number of total SOSs created so far: 20
Number of SOSs created by me so far: 16

    . . . S . O      0 1 2 3 4 5
    O S S S O S      6 7 8 9 a b
    . . O O O S      c d e f g h
    . S S S S S      i j k l m n
    S O O O O O      o p q r s t
    S O S S S S      u v w x y z

Hit the spacebar to start the System’s next move.
 
My turn.  I (System) pick the piece S
The move from me is i
Number of total SOSs created so far: 21
Number of SOSs created by me so far: 17

    . . . S . O      0 1 2 3 4 5
    O S S S O S      6 7 8 9 a b
    . . O O O S      c d e f g h
    S S S S S S      i j k l m n
    S O O O O O      o p q r s t
    S O S S S S      u v w x y z

Hit the spacebar to start the System’s next move.
  
My turn.  I (System) pick the piece O
The move from me is d
Number of total SOSs created so far: 23
Number of SOSs created by me so far: 19

    . . . S . O      0 1 2 3 4 5
    O S S S O S      6 7 8 9 a b
    . O O O O S      c d e f g h
    S S S S S S      i j k l m n
    S O O O O O      o p q r s t
    S O S S S S      u v w x y z

Hit the spacebar to start the System’s next move.
  
My turn.  I (System) pick the piece S
The move from me is 0
Number of total SOSs created so far: 23
Number of SOSs created by me so far: 19

    S . . S . O      0 1 2 3 4 5
    O S S S O S      6 7 8 9 a b
    . O O O O S      c d e f g h
    S S S S S S      i j k l m n
    S O O O O O      o p q r s t
    S O S S S S      u v w x y z

Continue? (y/n)  y 
Your turn.  You (User) pick a piece: (S|O)  S 
Enter your next move: (0..z)  c 
Number of total SOSs created so far: 24
Number of SOSs created by you so far: 5

    S . . S . O      0 1 2 3 4 5
    O S S S O S      6 7 8 9 a b
    S O O O O S      c d e f g h
    S S S S S S      i j k l m n
    S O O O O O      o p q r s t
    S O S S S S      u v w x y z

Continue? (y/n)  y 
Your turn.  You (User) pick a piece: (S|O)  O 
Enter your next move: [0..z]  4 
Number of total SOSs created so far: 24
Number of SOSs created by you so far: 5

    S . . S O O      0 1 2 3 4 5
    O S S S O S      6 7 8 9 a b
    S O O O O S      c d e f g h
    S S S S S S      i j k l m n
    S O O O O O      o p q r s t
    S O S S S S      u v w x y z

Hit the spacebar to start the System’s next move.
  
My turn.  I (System) pick the piece S
The move from me is 2
Number of total SOSs created so far: 24
Number of SOSs created by me so far: 19

    S . S S O O      0 1 2 3 4 5
    O S S S O S      6 7 8 9 a b
    S O O O O S      c d e f g h
    S S S S S S      i j k l m n
    S O O O O O      o p q r s t
    S O S S S S      u v w x y z

Continue? (y/n)  y 
Your turn.  You (User) pick a piece: (S|O)  O 
Enter your next move: (0..z)  1 
Number of total SOSs created so far: 25
Number of SOSs created by you so far: 6

    S O S S O O      0 1 2 3 4 5
    O S S S O S      6 7 8 9 a b
    S O O O O S      c d e f g h
    S S S S S S      i j k l m n
    S O O O O O      o p q r s t
    S O S S S S      u v w x y z

I (System) won!  I have 19 SOSs and you have 6 SOSs.
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 .half Allocating space for a half word (two bytes)
7 .space n Allocating n bytes of space
8 .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 beqz rs, label if rs==0 then goto label Branch if equal to zero
5 bgez rs label if rs≥0 then goto label Branch if greater than or equal to zero
6 bgt rs, rt, label if rs>rt then goto label Branch if greater than
7 ble rs, rt, label if rs≤rt then goto label Branch if less than or equal to
8 blt rs, rt, label if rs<rt then goto label Branch if less than
9 bne rs, rt, label if rs≠rt then goto label Branch if not equal to
10 bnez rs, label if rs≠0 then goto label Branch if not equal to zero
11 j label jump to label Jump
12 jal label jump to label and save the return address in $31 or $ra Jump and link
13 jr rs jump to [rs]; [ ]: contents of Jump and link
14 la rd, mem rd = address( mem ) Load address
15 lb rd, mem rd = mem Load byte
16 lh rd, mem rd = mem Load half word
17 li rd, imm rd = imm Load immediate
18 lw rd, mem rd = mem Load word
19 move rd, rs rd = rs Move register
20 mul rd, rs, rt rd = rs × rt Multiply
21 sb rs, mem mem = rs Store byte
22 sub rd, rs, rt rd = rs - rt Subtract
23 subu rd, rs, rt rd = rs - rt (no overflow) Subtract unsigned
24 sw rs, mem mem = rs Store word
25 syscall   System call; check System Services.
26 xor rd, rs, rt rd = rs xor rt Bitwise exclusive or

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
random int range 42 $a0 = i.d. of pseudorandom number generator (any int).
$a1 = upper bound of range of returned values.
$a0 contains pseudorandom, uniformly distributed int value in the range 0 ≤ [int] < [upper bound], drawn from this random number generator’s sequence.

Evaluations
The following features will be considered when grading: