cours_progra/bac1/q2/fonctio/tp2/switch-table.s
Debucquoy 4fd7542f03
.
2023-09-20 15:18:20 +02:00

64 lines
652 B
ArmAsm

.data
tab: .word case5, case6, case7, case8
q1: .asciiz "Entrez un nombre entre 5 et 8:"
r5: .asciiz "case 5"
r6: .asciiz "case 6"
r7: .asciiz "case 7"
r8: .asciiz "case 8"
.text
main:
# ask a number
li $v0, 4
la $a0, q1
syscall
# read the number
li $v0, 5
syscall
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
case5:
li $v0, 4
la $a0, r5
syscall
j end_case
case6:
li $v0, 4
la $a0, r6
syscall
j end_case
case7:
li $v0, 4
la $a0, r7
syscall
j end_case
case8:
li $v0, 4
la $a0, r8
syscall
j end_case
end_case:
jr $ra