Skip to content
This repository was archived by the owner on Jan 16, 2024. It is now read-only.

Commit 132d679

Browse files
committed
esame lab giugno luglio 2021
1 parent 66fac15 commit 132d679

File tree

9 files changed

+261
-0
lines changed

9 files changed

+261
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
.data
2+
space: .ascii " "
3+
fine: .asciiz ""
4+
.text
5+
.globl conta_parole
6+
7+
8+
conta_parole:
9+
move $t0 $a0 #salvo indirizzo dell'array
10+
11+
lb $t1 space #32
12+
lb $t3 fine #carattere fine stringa
13+
lb $t2 0($t0) #primo carattere, cursore
14+
15+
addi $v0 $0 1 #contatore
16+
17+
#beq $t2 $t3 end #se
18+
#addi $v0 $0 1
19+
20+
loop: beq $t2 $t3 end
21+
22+
addi $t0 $t0 1
23+
lb $t2 0($t0)
24+
25+
beq $t2 $t1 spazio
26+
j loop
27+
spazio: addi $v0 $v0 1
28+
j loop
29+
30+
end:
31+
jr $ra
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
.data
2+
str: .asciiz "Ciao 0 zero?"
3+
.text
4+
.globl main
5+
6+
main:
7+
la $a0 str
8+
9+
jal conta_parole
10+
11+
move $s0 $v0
12+
13+
li $v0 10
14+
syscall

esame_20210618/minmax/main.asm

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
.data
2+
arr: .word 1 -1 3 10 5 6
3+
size: .word 6
4+
.text
5+
.globl main
6+
7+
main:
8+
la $a0 arr #indirizzo dell'array
9+
lw $a1 size #dimensione dell'array
10+
11+
jal minmax
12+
13+
move $s0 $v0
14+
move $s1 $v1
15+
16+
li $v0 10
17+
syscall

esame_20210618/minmax/maxmain.asm

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
.text
2+
.globl minmax
3+
4+
5+
minmax: move $t0 $a0 #salvo array indirizzo
6+
move $t1 $a1 #salvo dim del array
7+
8+
lw $t2 0($a0) #min
9+
lw $t3 0($a0) #max
10+
11+
addi $t1 $t1 -1
12+
13+
loop: beq $t1 $0 end
14+
15+
lw $t4 4($t0)
16+
17+
bgt $t4 $t3 max
18+
blt $t4 $t2 min
19+
20+
addi $t0 $t0 4
21+
addi $t1 $t1 -1
22+
j loop
23+
24+
max: move $t3 $t4
25+
j loop
26+
min: move $t2 $t4
27+
j loop
28+
29+
end: move $v0 $t2
30+
move $v1 $t3
31+
32+
jr $ra
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
.text
2+
.globl conta_multipli
3+
4+
conta_multipli:
5+
move $t0 $fp
6+
addi $fp $sp -4
7+
sw $t0 0($fp)
8+
sw $sp -4($fp)
9+
sw $ra -8($fp)
10+
sw $s0 -12($fp)
11+
add $sp $fp -12
12+
13+
move $s1 $a0
14+
move $s2 $a1
15+
move $t2 $a2 # N
16+
li $s0 0
17+
#ultima pos del array
18+
addi $a2 $a2 -1
19+
mul $t3 $a2 4 #4x5
20+
add $s1 $s1 $t3
21+
add $s2 $s2 $t3
22+
23+
loop: blt $a2 $0 exit
24+
lw $a0 0($s1)
25+
lw $a1 0($s2)
26+
27+
addi $s1 $s1 -4
28+
addi $s2 $s2 -4
29+
30+
jal multiplo
31+
add $s0 $s0 $v0
32+
33+
addi $a2 $a2 -1
34+
j loop
35+
36+
exit:
37+
move $v0 $s0
38+
39+
lw $t0 0($fp)
40+
lw $sp -4($fp)
41+
lw $ra -8($fp)
42+
lw $s0 -12($fp)
43+
move $fp $t0
44+
45+
jr $ra

esame_20210702/multiplo/main.asm

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
.data
2+
arr_1: .word 1 9 5 9 5
3+
arr_2: .word 4 3 3 8 15
4+
.text
5+
.globl main
6+
7+
8+
main:
9+
la $a0 arr_1
10+
la $a1 arr_2
11+
li $a2 5
12+
13+
jal conta_multipli
14+
15+
move $s0 $v0
16+
17+
li $v0 10
18+
syscall
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
.text
2+
.globl multiplo
3+
4+
5+
multiplo:
6+
move $t0 $fp
7+
addi $fp $sp -4
8+
sw $t0 0($fp)
9+
sw $sp -4($fp)
10+
sw $ra -8($fp)
11+
sw $s0 -12($fp)
12+
add $sp $fp -12
13+
14+
li $v0 0
15+
16+
blt $a0 $a1 gt
17+
j job
18+
19+
gt: move $t7 $a0
20+
move $a0 $a1
21+
move $a1 $t7
22+
23+
job:
24+
div $a0 $a1
25+
mfhi $s0
26+
bne $s0 $0 exit
27+
li $v0 1
28+
29+
exit: lw $t0 0($fp)
30+
lw $sp -4($fp)
31+
lw $ra -8($fp)
32+
lw $s0 -12($fp)
33+
move $fp $t0
34+
35+
jr $ra

esame_20210702/palindroma/main.asm

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
.data
2+
str: .asciiz "5kayyak5"
3+
.text
4+
.globl main
5+
6+
7+
main: la $a0 str
8+
9+
jal palindroma
10+
11+
move $s0 $v0
12+
13+
li $v0 10
14+
syscall
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
.data
2+
fine: .asciiz ""
3+
.text
4+
.globl palindroma
5+
6+
7+
palindroma:
8+
move $t0 $a0 #salvo indirizzo della stringa
9+
10+
lb $t1 fine
11+
addi $t2 $0 0 #f posizione fine
12+
addi $t3 $0 0 #i posizione iniziale
13+
li $v0 0
14+
lb $t4 0($t0) #primo carattere
15+
16+
loop_size:
17+
beq $t4 $t1 end_size
18+
addi $a0 $a0 1
19+
lb $t4 0($a0)
20+
addi $t2 $t2 1
21+
22+
j loop_size
23+
end_size:
24+
li $t5 2
25+
div $t2 $t5
26+
mfhi $t5
27+
mflo $t6
28+
29+
addi $t6 $t6 1
30+
31+
32+
lb $t4 0($t0) #primo carattere
33+
34+
move $a0 $t0
35+
addi $t2 $t2 -1
36+
add $a0 $a0 $t2 #ultimo carattere
37+
38+
lb $t5 0($a0) #ultimo carattere
39+
40+
loop: bne $t4 $t5 exit
41+
bgt $t3 $t6 end
42+
addi $t3 $t3 1
43+
44+
addi $t0 $t0 1
45+
addi $a0 $a0 -1
46+
47+
lb $t4 0($t0)
48+
lb $t5 0($a0)
49+
50+
j loop
51+
52+
53+
end: li $v0 1
54+
55+
exit: jr $ra

0 commit comments

Comments
 (0)