Created
May 20, 2011 14:19
-
-
Save razielgn/982983 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
# Esercizio 2 | |
# Autori: Luca Parsani, Federico Ravasio | |
# Licenza GPL | |
# | |
# Indirizzi memoria RAM | |
# Sensore Alto 0x10010020 | |
# Sensore Centro 0x10010030 | |
# Sensore Basso 0x10010040 | |
# Temp. Input 0x10010050 | |
# Output 0x10010060 | |
# | |
# $s0 => sforati_caldi | |
# $s1 => sforati_freddi | |
# $s2 => compresi_caldi | |
# $s3 => compresi_freddi | |
# | |
# $s4 => temperatura desiderata | |
# | |
# li $t0, 0x10010020 #assegno a $t0 l'indirizzo | |
# li $t1, 140 #assegno a $t1 il valore di sen. alto | |
# sb $t1, ($t0) #inserisco la temperatura del sensore alto | |
# li $t0, 0x10010030 #assegno a $t0 l'indirizzo | |
# li $t1, 102 #assegno a $t1 il valore di sen. medio | |
# sb $t1, ($t0) #inserisco la temperatura del sensore medio | |
# li $t0, 0x10010040 #assegno a $t0 l'indirizzo | |
# li $t1, 76 #assegno a $t1 il valore di sen. basso | |
# sb $t1, ($t0) #inserisco la temperatura del sensore basso | |
# li $t0, 0x10010050 #assegno a $t0 l'indirizzo | |
# li $t1, 64 #assegno a $t1 il valore che devo impostare | |
# sb $t1, ($t0) #inserisco la temperatura desiderata | |
main: | |
li $t0, 0x10010050 # $t0 = indirizzo temperatura desiderata | |
lbu $s4, ($t0) # Temperatura desiderata in $s7 | |
li $a0, 0x10010020 # Sensore alto | |
jal sub_proc # Processa sensore alto | |
li $a0, 0x10010030 # Sensore centro | |
jal sub_proc # Processa sensore centro | |
li $a0, 0x10010040 # Sensore basso | |
jal sub_proc # Processa sensore basso | |
if_1: # compresi_caldi == 2 ? | |
li $t0, 2 | |
bne $t0, $s2, if_2 # goto if_2 if $t0 =/= $s2 | |
li $a0, 5 | |
jal ventola | |
j end | |
if_2: # compresi_freddi == 2 ? | |
li $t0, 2 | |
bne $t0, $s3, if_3 # goto if_3 if $t0 =/= $s3 | |
li $a0, 6 | |
jal ventola | |
j end | |
if_3: # compresi_caldi == 3 OR sforati_caldi >= 2 ? | |
seq $t1, $s2, 3 | |
sge $t2, $s0, 2 | |
or $t1, $t1, $t2 | |
beqz $t1, if_4 # goto if_4 if $t1 == 0 (se la condizione sopra è falsa) | |
li $a0, 12 | |
jal ventola | |
j end | |
if_4: # compresi_freddi == 3 OR sforati_freddi >= 2 ? | |
seq $t1, $s3, 3 | |
sge $t2, $s1, 2 | |
or $t1, $t1, $t2 | |
beqz $t1, else # goto else if $t1 == 0 (se la condizione sopra è falsa) | |
li $a0, 15 | |
jal ventola | |
j end | |
else: # ventola bloccata | |
li $a0, 3 | |
jal ventola | |
j end | |
sub_proc: | |
# $t6 << segno | |
# $t7 << delta T | |
lbu $t1, ($a0) # Carica il byte del sensore all'indirizzo di $t0 in $t1 | |
sub $t7, $t1, $s4 # dT tra la temperatura letta e la temperatura desiderata | |
slt $t6, $zero, $t7 # $t7 > 0 ? Caldo (1) : Freddo (0) | |
bnez $t6, sub_proc_sfora # Se segno != 0 salta | |
neg $t7, $t7 # dT da negativo diventa positivo | |
sub_proc_sfora: | |
sgt $t0, $t7, 0x33 # \ | |
beqz $t0, sub_proc_compr # -- goto sub_proc_compr se (dT <= 0x33) | |
beqz $t6, sub_proc_s_f # goto sub_proc_s_f se segno == 0 | |
addi $s0, $s0, 1 # sforati_caldi++ | |
j sub_proc_end | |
sub_proc_s_f: | |
addi $s1, $s1, 1 # sforati_freddi++ | |
j sub_proc_end | |
sub_proc_compr: | |
sge $t0, $t7, 0x0C # $t0 = (dT >= 0x0C ? 1 : 0) | |
beqz $t0, sub_proc_end | |
beqz $t6, sub_proc_c_f | |
addi $s2, $s2, 1 # compresi_caldi++ | |
j sub_proc_end | |
sub_proc_c_f: | |
addi $s3, $s3, 1 # compresi_freddi++ | |
j sub_proc_end | |
sub_proc_end: | |
jr $ra | |
ventola: # Scrittura ventola | |
li $t0, 0x10010060 | |
sb $a0, ($t0) | |
jr $ra | |
# | |
# delay: | |
# addi $a0, $a0, -1 | |
# bne $a0, 0, delay | |
# jr $ra | |
end: | |
li $2, 10 | |
syscall |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment