aboutsummaryrefslogtreecommitdiff
path: root/semestre 3/architecture des ordinateurs/tme/tme4
diff options
context:
space:
mode:
authorAnhgelus Morhtuuzh <william@herges.fr>2025-10-10 23:15:18 +0200
committerAnhgelus Morhtuuzh <william@herges.fr>2025-10-10 23:15:18 +0200
commit4ed8060318b1807638c12b8b43660bb98fc99fba (patch)
tree976f9b6be6cfbb72c3c908e2e1e60069f5a4296a /semestre 3/architecture des ordinateurs/tme/tme4
parent85fbaa4d9381e435be129aa7bc4ea6a472acb2b2 (diff)
Cours du 6 au 10 octobre
Diffstat (limited to 'semestre 3/architecture des ordinateurs/tme/tme4')
-rw-r--r--semestre 3/architecture des ordinateurs/tme/tme4/exo1.asm6
-rw-r--r--semestre 3/architecture des ordinateurs/tme/tme4/exo2.asm32
-rw-r--r--semestre 3/architecture des ordinateurs/tme/tme4/exo3.asm19
-rw-r--r--semestre 3/architecture des ordinateurs/tme/tme4/exo4.asm31
-rw-r--r--semestre 3/architecture des ordinateurs/tme/tme4/exo5.asm30
5 files changed, 118 insertions, 0 deletions
diff --git a/semestre 3/architecture des ordinateurs/tme/tme4/exo1.asm b/semestre 3/architecture des ordinateurs/tme/tme4/exo1.asm
new file mode 100644
index 0000000..da99bd9
--- /dev/null
+++ b/semestre 3/architecture des ordinateurs/tme/tme4/exo1.asm
@@ -0,0 +1,6 @@
+.data
+o1: .byte 1
+o2: .byte 2
+o3: .byte 3
+o4: .byte 4
+m1: .word 0xAABBCCDD \ No newline at end of file
diff --git a/semestre 3/architecture des ordinateurs/tme/tme4/exo2.asm b/semestre 3/architecture des ordinateurs/tme/tme4/exo2.asm
new file mode 100644
index 0000000..9c66651
--- /dev/null
+++ b/semestre 3/architecture des ordinateurs/tme/tme4/exo2.asm
@@ -0,0 +1,32 @@
+.data
+v1: .word -1
+v2: .word 0xFF
+
+o: .byte 0xFF
+.text
+ lui $8, 0x1001
+ lw $9, 0($8)
+ or $4, $0, $9
+ ori $2,$0,1
+ syscall
+
+ lw $10, 4($8)
+ or $4, $10, $10
+ syscall
+
+ addi $9, $9, 1
+ sw $9, 0($8)
+ addi $10, $10, 1
+ sw $10, 4($8)
+
+ addi $8, $8, 8 # on récupère l'adresse de o
+ lb $9, 0($8)
+ or $4, $0, $9
+ syscall # affiche -1 car il l'étend
+ lbu $10, 0($8)
+ or $4, $0, $10
+ syscall # affiche 255 car il n'est pas signé
+
+ ori $2, $0, 10
+ syscall
+ \ No newline at end of file
diff --git a/semestre 3/architecture des ordinateurs/tme/tme4/exo3.asm b/semestre 3/architecture des ordinateurs/tme/tme4/exo3.asm
new file mode 100644
index 0000000..4ccd63a
--- /dev/null
+++ b/semestre 3/architecture des ordinateurs/tme/tme4/exo3.asm
@@ -0,0 +1,19 @@
+.data
+ch: .asciiz "coucou"
+.text
+ lui $8, 0x1001
+ ori $2, $0, 4
+ or $4, $0, $8
+ syscall
+
+ # on garde en mémoire les deux caractères
+ lb $9, 0($8)
+ lb $10, 1($8)
+ # on les échanges
+ sb $9, 1($8)
+ sb $10, 0($8)
+ # et on affiche
+ syscall
+
+ ori $2, $0, 10
+ syscall \ No newline at end of file
diff --git a/semestre 3/architecture des ordinateurs/tme/tme4/exo4.asm b/semestre 3/architecture des ordinateurs/tme/tme4/exo4.asm
new file mode 100644
index 0000000..28a4c30
--- /dev/null
+++ b/semestre 3/architecture des ordinateurs/tme/tme4/exo4.asm
@@ -0,0 +1,31 @@
+# "123456" = 0x31 32 33 34 35 36 00
+.data
+cod: .byte 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x00
+.text
+ lui $8, 0x1001
+ ori $2, $0, 4
+ or $4, $0, $8
+ syscall
+
+ lb $16, 2($8)
+ or $4, $0, $16
+ ori $2, $0, 1
+ syscall
+
+ # "0" est représenté par 0x30
+ # les autres chiffres sont à la suite de 0x30 jusqu'à 0x39 ("9")
+ # pour transformer le code ASCII d'un chiffre en chiffre, il suffit donc de lui soustraire 0x30 pour obtenir le chiffre
+
+ # on a besoin de mettre 0x30 dans un registre car l'opcode subi n'existe pas
+ ori $9, $0, 0x30
+ sub $17, $16, $9
+ or $4, $0, $17
+ syscall
+
+ ori $18, $0, 0x34 # est l'ascii de "4"
+ sub $18, $18, $9
+ or $4, $0, $18
+ syscall
+
+ ori $2, $0, 10
+ syscall \ No newline at end of file
diff --git a/semestre 3/architecture des ordinateurs/tme/tme4/exo5.asm b/semestre 3/architecture des ordinateurs/tme/tme4/exo5.asm
new file mode 100644
index 0000000..c63dc69
--- /dev/null
+++ b/semestre 3/architecture des ordinateurs/tme/tme4/exo5.asm
@@ -0,0 +1,30 @@
+.data
+tab: .word 4, 23, 12, 3, 8, 1
+ .align 2
+s: .space 4
+ .align 2
+p: .space 4
+.text
+ lui $8, 0x1001 # @tab
+ addiu $9, $8, 24 # @s
+ addiu $10, $9, 4 # @p
+ # s = tab[3]
+ lw $11, 12($8)
+ sw $11, 0($9)
+ # p = tab[4]
+ lw $12, 16($8)
+ sw $12, 0($10)
+
+ # tab[0] = s + 1
+ addi $13, $11, 1
+ sw $13, 0($8)
+ # tab[1] = s + p
+ add $13, $11, $12
+ sw $13, 4($8)
+ # tab[2] = tab[5]
+ lw $13, 20($8)
+ sw $13, 8($8)
+
+ # exit()
+ ori $2, $0, 10
+ syscall \ No newline at end of file