-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprintboard.asm
126 lines (104 loc) · 2.19 KB
/
printboard.asm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
.data
space:
.asciiz " "
player_1_string:
.asciiz "A"
player_2_string:
.asciiz "B"
board_corner:
.asciiz "+"
board_top_bottom:
.asciiz "-"
board_side:
.asciiz "|"
.globl newline
newline:
.asciiz "\n"
.text
.align 2
# a0 is location of board
# a1 is width
.globl print_string
.globl print_board
print_board:
addi $sp, $sp, -12
sw $s1, 8($sp)
sw $s0, 4($sp)
sw $ra, 0($sp)
move $s1, $a1
move $s0, $a0
move $t0, $s1
print_board_top_start:
la $a0, board_corner
jal print_string
print_board_top:
beq $t0, $zero, print_board_top_done
la $a0, board_top_bottom
jal print_string
addi $t0, $t0, -1
j print_board_top
print_board_top_done:
la $a0, board_corner
jal print_string
la $a0, newline
jal print_string
move $t1, $zero
print_board_middle:
beq $t1, $s1, print_board_bottom_start
addi $t1, $t1, 1
print_board_row_start:
la $a0, board_side
jal print_string
move $t0, $zero
print_board_row:
beq $t0, $s1, print_board_row_end
lw $a0, 0($s0)
beq $a0, $zero, print_board_row_empty
li $t2, 1
beq $a0, $t2, print_board_row_player_1
li $t2, 2
beq $a0, $t2, print_board_row_player_2
j print_board_done
print_board_row_empty:
la $a0, space
jal print_string
j print_board_row_cont
print_board_row_player_1:
la $a0, player_1_string
jal print_string
j print_board_row_cont
print_board_row_player_2:
la $a0, player_2_string
jal print_string
j print_board_row_cont
print_board_row_cont:
addi $s0, $s0, 4
addi $t0, $t0, 1
j print_board_row
print_board_row_end:
la $a0, board_side
jal print_string
la $a0, newline
jal print_string
j print_board_middle
print_board_bottom_start:
la $a0, board_corner
jal print_string
print_board_bottom:
beq $t0, $zero, print_board_bottom_done
la $a0, board_top_bottom
jal print_string
addi $t0, $t0, -1
j print_board_bottom
print_board_bottom_done:
la $a0, board_corner
jal print_string
# la $a0, newline
# jal print_string
move $t1, $zero
print_board_done:
lw $s1, 8($sp)
lw $s0, 4($sp)
lw $ra, 0($sp)
addi $sp, $sp, 12
jr $ra