From 690720e54dcf0be49b872304251bbff916d71e0f Mon Sep 17 00:00:00 2001 From: Anthony Debucquoy Date: Fri, 5 May 2023 16:04:44 +0200 Subject: [PATCH] hexa --- q2/fonctio/tp2/simp-to-hex.s | 27 +++++++++++++++++++++++++ q2/fonctio/tp2/switch-table.s | 38 +++++++++++++++++++++++++++++++++-- 2 files changed, 63 insertions(+), 2 deletions(-) create mode 100644 q2/fonctio/tp2/simp-to-hex.s diff --git a/q2/fonctio/tp2/simp-to-hex.s b/q2/fonctio/tp2/simp-to-hex.s new file mode 100644 index 0000000..7f5a8e9 --- /dev/null +++ b/q2/fonctio/tp2/simp-to-hex.s @@ -0,0 +1,27 @@ + .data +hex: .asciiz "0123456789ABCDEF" +q1: .asciiz "Entrez un nombre" + .text +main: + li $v0, 4 + la $a0, q1 + la $t9, hex + syscall + + li $v0, 5 + syscall + + li $t0 16 #base + +divi: + div $v0, $t0 + mfhi $t2 + addu $t9, $t9, $t2 + lb $a0 0($t9) + li $v0, 11 + syscall + + mflo $v0 + bne $v0, 0, divi + +jr $ra diff --git a/q2/fonctio/tp2/switch-table.s b/q2/fonctio/tp2/switch-table.s index 6096667..34ba0c5 100644 --- a/q2/fonctio/tp2/switch-table.s +++ b/q2/fonctio/tp2/switch-table.s @@ -1,27 +1,61 @@ .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: - li $v0, 5 + # ask a number + li $v0, 4 la $a0, q1 syscall - li $v0, 4 + # 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