cours_progra/q2/fonctio/tp2/switch-table.s

64 lines
652 B
ArmAsm
Raw Normal View History

2023-05-05 13:02:58 +02:00
.data
tab: .word case5, case6, case7, case8
q1: .asciiz "Entrez un nombre entre 5 et 8:"
2023-05-05 16:04:44 +02:00
r5: .asciiz "case 5"
r6: .asciiz "case 6"
r7: .asciiz "case 7"
r8: .asciiz "case 8"
2023-05-05 13:02:58 +02:00
.text
main:
2023-05-05 16:04:44 +02:00
# ask a number
li $v0, 4
2023-05-05 13:02:58 +02:00
la $a0, q1
syscall
2023-05-05 16:04:44 +02:00
# read the number
li $v0, 5
2023-05-05 13:02:58 +02:00
syscall
2023-05-05 16:04:44 +02:00
li $t5, 5
li $t4, 4
sub $t1, $v0, $t5
mult $t1, $t4
mflo $t2
# Load addr : tab
la $t1, tab
addu $t1, $t2, $t1
lw $t0,0($t1)
jr $t0
2023-05-05 13:02:58 +02:00
case5:
2023-05-05 16:04:44 +02:00
li $v0, 4
la $a0, r5
syscall
2023-05-05 13:02:58 +02:00
j end_case
2023-05-05 16:04:44 +02:00
2023-05-05 13:02:58 +02:00
case6:
2023-05-05 16:04:44 +02:00
li $v0, 4
la $a0, r6
syscall
2023-05-05 13:02:58 +02:00
j end_case
2023-05-05 16:04:44 +02:00
2023-05-05 13:02:58 +02:00
case7:
2023-05-05 16:04:44 +02:00
li $v0, 4
la $a0, r7
syscall
2023-05-05 13:02:58 +02:00
j end_case
2023-05-05 16:04:44 +02:00
2023-05-05 13:02:58 +02:00
case8:
2023-05-05 16:04:44 +02:00
li $v0, 4
la $a0, r8
syscall
2023-05-05 13:02:58 +02:00
j end_case
end_case:
jr $ra