Created
April 10, 2018 02:06
-
-
Save harveyslash/5cfab97f6898a1e5e1c2c6d1073d4aad to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This function takes in | |
# | |
# $a0 as max_size | |
# $a1 as row | |
# $a2 as col | |
# $a3 as 1 or -1 | |
# 1 is = A | |
# -1 is =B | |
# it returns v0 = 0 if validation failed , else it returns 1 | |
validate_and_set_point: | |
slt $t0, $a1 , $a0 | |
beq $t0, $zero, validate_point_fail | |
slt $t0, $a2 , $a0 | |
beq $t0, $zero, validate_point_fail | |
slti $t0, $a1, 0 | |
bne $t0, $zero, validate_point_fail | |
slti $t0, $a2, 0 | |
bne $t0, $zero, validate_point_fail | |
# check if point in table is not already non 0 | |
mul $t0, $a0, $a1 | |
add $t0, $t0, $a2 # t0 now has index of the element | |
mul $t1, $t0, 4 # t1 = index * 4 | |
la $t2, table | |
add $t2, $t2, $t1 # t2 = Table + index*4 | |
lw $t3, 0($t2) # t3 has the value of the index | |
bne $t3, $zero, validate_point_fail | |
sw $a3, 0($t2) | |
li $v0, 1 | |
j validate_point_done | |
validate_point_fail: | |
li $v0, 0 | |
validate_point_done: | |
jr $ra |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment