Você está na página 1de 4

#Jake E.

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

jal check_input #check if valid input


bne $22, $10, reset #if invalid flag is 4, then end
add $2, $0, $25 #ibalik sa nakaraan
eret

reset:
addi $6, $0, 1 #constant 1

addi $15, $0, 0 #reset corr counter


addi $17, $0, 0 #reset nips counter
addi $9, $0, 0 #reset inner counter
addi $14, $0, 0 #reset outer counter
addi $16, $0, 0 #reset corr/nips flag
addi $13, $0, 0

#sll $4, $4, 16 #remove MSB and epals


#srl $4, $4, 16 #remove MSB

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

sll $28, $4, 20 #rotation alogorithm


srl $28, $28, 16
srl $29, $4, 12
or $4, $28, $29

addi $14, $14, 1 #outer counter


beq $14, $10, done #if outer counter is equal to 4, done
addi $7, $0, 0xf #reinitialize Oxf
addi $9, $0, 0 #reinitialize inner counter
addi $13, $0, 0
j check #else, check
done:
addi $14, $0, 0 #reset outer counter for next guesses
beq $17, $10, smiley #if corr is 4, smiley
addi $19, $0, 2 #smiley is sad
j score #else zero
smiley:
addi $19, $0, 1 #smiley is happy
score:
addi $18, $15, 0 #DELETE
sll $15, $15, 2 #shift left nips 2 times
sll $17, $17, 5 #shift left corr 5 times
or $20, $17, $15 #add everything to get matrix display
or $20, $20, $19 #enabled at main memory

addi $6, $0, 1 #constant 1


beq $21, $6, oof

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)

andi $28, $28, 0x10 #delete or not


srl $28, $28, 4
beq $28, $6, enable_CRB #delete or not

lw $11, 0($3) #load row enables


sll $12, $11, 1 #shift the row enable, button enable only not matrix
enables
andi $12, $12, 0x3f #and 0x3f to obtain last 6 bits
srl $11, $11, 6 #remove last 6 bits
sll $11, $11, 6 #remove last bits
or $11, $11, $12 #or; button enable has been shifted
sw $11, 0($3) #store enable row
j end_talaga
enable_CRB:
lw $11, 0($3)
srl $11, $11, 8
sll $11, $11, 8
lui $12, 0x8000 #enable CRB
ori $11, $11, 0x2000
or $11, $11, $12

#lw $12, 0($3) #load row enables


#or $12, $11, $12 #enable CRT
sw $11, 0($3) #enable CRB only, take no inputs
end_talaga:
lw $12, 0($3) #load row enables
#addi $30, $0, 0x1f00 #constant 0x1f00
#nor $30, $30, $0 #invert 0x1f
andi $30, $12, 0x3f #remove matrix bits
#sll $29, $12, 1 #shift the row enable, matrix enables ~ button
enables
#andi $29, $12, 0x3f #and 0x3f to obtain the shifted 6 last bits which
will become the new matrix bits
sll $29, $30, 8 #shift lefft 8 times to reposition to matrix bits
or $30, $29, $30 #or; matrix enable has been shifted

add $2, $0, $25 #ibalik sa nakaraan


addi $21, $0, 1 #matrix enable flag
eret

#### Check if input is valid. ####

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

Você também pode gostar