Escolar Documentos
Profissional Documentos
Cultura Documentos
Zozobrado
#2015-01055
#MP2: Mini-Mastermind
check_gobit:
addi $26, $4, 0 #copy previous guess code
lw $4, 12($3) #load the input which is at 0x800c
addi $27, $4, 0 #copy the new guess code
sll $26, $26, 16 #remove unnecessary bits; 16 MSB bits for both guess and
answer
srl $26, $26, 16
sll $4, $4, 16
srl $4, $4, 16
beq $26, $4, start #if guess and answer is equal, interrupt is go bit!
end_invalid:
addi $4, $27, 0 #update previous code
eret
start:
addi $10, $0, 4 #constant 4
addi $7, $0, 0xf #constant 0xf
add $25, $0, $2 #copy the color code
reset:
addi $6, $0, 1 #constant 1
check:
addi $9, $9, 1 #inner counter
and $8, $4, $7 #isolate the color of interest (breaker)
and $18, $2, $7 #isolate the color of interest (master)
beq $8, $0, hop #if equal to zero, alis na
beq $8, $18, blue #if equal increment corr/nips
hop:
sll $7, $7, 4 #shift left 0xf
beq $9, $10, rotate #if inner counter is equal to 4, rotate
j check #else loop
blue:
beq $16, $0, corr #corr flag
add $15, $15, 1 #increment nips
j jump
corr:
add $17, $17, 1 #increment corr
jump:
or $13, $13, $7 #or 0xf; progressively shifting
sll $7, $7, 4 #shift left 0xf
beq $17, $10, done #if 4 correct colors, done
beq $9, $10, rotate #if inner counter equal to 4, rotate
j check #else loop
rotate:
addi $16, $0, 1 #nips flag
nor $13, $13, $0 #invert the f's
and $4, $4, $13 #snap out all the likeys
and $2, $2, $13
sw $20, 4($3)
j punyeta
oof:
sw $30, 0($3)
#addi $18, $0, 456789 #DELETE
sw $20, 4($3)
punyeta:
srl $17, $17, 5 #shift back to the right nips 2 times
beq $17, $10, enable_CRB#if corr is equal to 4, set CRB.
lw $28, 0($3)
check_input:
addi $5, $0, 0 #reset counter
addi $22, $0, 0 #reset invalid flag
add $23, $0, $4 #copy guess, nagamit kasi
yeah: #this code removes the LSB set bit until the operand
becomes zero; if counter is four -> valid
addi $24, $4, -1 #n-1
and $6, $24, $4 #(n)&(n-1)
addi $5, $5, 1 #counter
beq $6, $0, tapos #if zero, done
add $4, $0, $6
j yeah
tapos:
bne $5, $10, invalid #if counter equals 4, yey
j talon
invalid:
addi $20, $0, 3 #smiley is shookt
sw $20, 4($3)
addi $22, $0, 4 #if invalid, flag is set to 4 (bakit 'di 1, wala
lang...)
talon:
add $4, $0, $23 #balik sa operand, nagamit kasi ihhh
jr $ra