diff options
| author | Anhgelus Morhtuuzh <william@herges.fr> | 2025-11-01 13:27:41 +0100 |
|---|---|---|
| committer | Anhgelus Morhtuuzh <william@herges.fr> | 2025-11-01 13:27:41 +0100 |
| commit | 341fc63ff791e08c7d0a00346080067c9bd1d5dd (patch) | |
| tree | 817638957893aa4899da4386483a29baa6e99151 /semestre 3/architecture des ordinateurs/tme | |
| parent | b47e5b1518d7089a2f6fdba439cf35dcf29e6089 (diff) | |
Cours du 17 au 21 octobre
Diffstat (limited to 'semestre 3/architecture des ordinateurs/tme')
9 files changed, 398 insertions, 0 deletions
diff --git a/semestre 3/architecture des ordinateurs/tme/tme5/exo1.asm b/semestre 3/architecture des ordinateurs/tme/tme5/exo1.asm new file mode 100644 index 0000000..4337468 --- /dev/null +++ b/semestre 3/architecture des ordinateurs/tme/tme5/exo1.asm @@ -0,0 +1,33 @@ +.data +p: .word 0 # 0x1001 0000 +q: .word 0 # 0x1001 0004 +.text + lui $8, 0x1001 # $8 <- 0x1001 0000 + ori $2, $0, 5 + syscall + lui $8, 0x1001 # $8 <- 0x1001 0000 + sw $2, 0($8) + ori $2, $0, 5 + syscall + lui $8, 0x1001 # $8 <- 0x1001 0000 + sw $2, 4($8) + + lw $12, 0($8) # p + lw $13, 4($8) # q + or $10, $0, $12 # i + ori $11, $0, 0 # somme +for: + # i+1 > q + addiu $14, $10, 1 + slt $15, $13, $14 + bne $15, $0, end_for + addu $11, $11, $10 # somme += i + addiu $10, $10, 1 + j for +end_for: + ori $2, $0, 1 + or $4, $0, $11 + syscall + + ori $2, $0, 10 + syscall
\ No newline at end of file diff --git a/semestre 3/architecture des ordinateurs/tme/tme5/exo2.asm b/semestre 3/architecture des ordinateurs/tme/tme5/exo2.asm new file mode 100644 index 0000000..00354a7 --- /dev/null +++ b/semestre 3/architecture des ordinateurs/tme/tme5/exo2.asm @@ -0,0 +1,33 @@ +.data +a: .word 0 # 0x1001 0000 +b: .word 0 # 0x1001 0004 +.text + lui $8, 0x1001 # $8 <- 0x1001 0000 + ori $2, $0, 5 + syscall + lui $8, 0x1001 # $8 <- 0x1001 0000 + sw $2, 0($8) + ori $2, $0, 5 + syscall + lui $8, 0x1001 # $8 <- 0x1001 0000 + sw $2, 4($8) + + lw $9, 0($8) # tmpa + lw $10, 4($8) # tmpb +while: + beq $9, $10, end_while + # tmpb < tmpa -> else + slt $11, $10, $9 + beq $11, $0, else + subu $9, $9, $10 + j end_if +else: + subu $10, $10, $9 +end_if: + j while +end_while: + ori $2, $0, 1 + or $4, $0, $9 + syscall + ori $2, $0, 10 + syscall
\ No newline at end of file diff --git a/semestre 3/architecture des ordinateurs/tme/tme5/exo3.asm b/semestre 3/architecture des ordinateurs/tme/tme5/exo3.asm new file mode 100644 index 0000000..715303b --- /dev/null +++ b/semestre 3/architecture des ordinateurs/tme/tme5/exo3.asm @@ -0,0 +1,17 @@ +.data +ch: .asciiz "Bonjour, je suis une licorne avec des pouvoirs magiques :D" # len(ch) 58 +.text + lui $8, 0x1001 + ori $9, $0, 0 # n +while: + lb $10, 0($8) + beq $10, $0, end_while + addiu $9, $9, 1 + addiu $8, $8, 1 + j while +end_while: + ori $2, $0, 1 + or $4, $0, $9 + syscall + ori $2, $0, 10 + syscall
\ No newline at end of file diff --git a/semestre 3/architecture des ordinateurs/tme/tme5/exo4.asm b/semestre 3/architecture des ordinateurs/tme/tme5/exo4.asm new file mode 100644 index 0000000..bac6a30 --- /dev/null +++ b/semestre 3/architecture des ordinateurs/tme/tme5/exo4.asm @@ -0,0 +1,29 @@ +.data +val: .word 70 +tab: .word 42, 69, 420, 666, 1, 2, 0, -1 +.text + lui $8, 0x1001 + ori $9, $0, 0 # n + lw $12, 0($8) + addiu $8, $8, 4 + # cond d'arrêt + or $13, $0, $0 + ori $14, $0, 1 + subu $13, $13, $14 +while: + # while tab[i] != '\0' + lw $10, 0($8) + beq $10, $13, end_while + slt $11, $10, $12 + # if tab[i] < val + beq $11, $0, end_if + addiu $9, $9, 1 +end_if: + addiu $8, $8, 4 + j while +end_while: + ori $2, $0, 1 + or $4, $0, $9 + syscall + ori $2, $0, 10 + syscall
\ No newline at end of file diff --git a/semestre 3/architecture des ordinateurs/tme/tme5/exo5.asm b/semestre 3/architecture des ordinateurs/tme/tme5/exo5.asm new file mode 100644 index 0000000..1ca188b --- /dev/null +++ b/semestre 3/architecture des ordinateurs/tme/tme5/exo5.asm @@ -0,0 +1,24 @@ +.data +n: .word 123 +.text + lui $8, 0x1001 + lw $9, 0($8) + + ori $11, $0, 1 + ori $10, $0, 31 + ori $13, $0, 0 +while: + bltz $10, end_while + srlv $12, $9, $10 + andi $12, $12, 1 + beq $12, $0, end_if + addiu $13, $13, 1 +end_if: + subu $10, $10, $11 + j while +end_while: + ori $2, $0, 1 + or $4, $0, $13 + syscall + ori $2, $0, 10 + syscall
\ No newline at end of file diff --git a/semestre 3/architecture des ordinateurs/tme/tme6/exo1-q1A.asm b/semestre 3/architecture des ordinateurs/tme/tme6/exo1-q1A.asm new file mode 100644 index 0000000..322654a --- /dev/null +++ b/semestre 3/architecture des ordinateurs/tme/tme6/exo1-q1A.asm @@ -0,0 +1,54 @@ +.data +ch: .space 11 +.text +#main + # prologue + addiu $29, $29, -16 + # scanf + ori $2, $0, 5 + syscall + sw $2, 4($29) + # chaine[10] = 0 + lui $8, 0x1001 + sb $0, 10($8) + + # i = 9 + lw $9, 0($29) # i + ori $9, $0, 9 + sw $9, 0($29) + +while: + # i >= 0 + lw $9, 0($29) + bltz $9, end_while + # corps + # r = nb % 10 + lw $10, 4($29) # nb + ori $11, $0, 10 + div $10, $11 + mfhi $12 + sw $12, 8($29) + # nb /= 10 + mflo $12 + sw $12, 4($29) + # chaine[i] = r + 0x30 + # *(chaine + i) = r + 0x30 + lw $9, 0($29) + addu $13, $8, $9 + lw $10, 8($29) # r + addiu $14, $10, 0x30 + sb $14, 0($13) + + # i -= 1 + lw $9, 0($29) # i + addiu $9, $9, -1 + sw $9, 0($29) + j while +end_while: + ori $2, $0, 4 + or $4, $0, $8 + syscall + # épilogue + addiu $29, $29, 16 + ori $2, $0, 10 + syscall
\ No newline at end of file diff --git a/semestre 3/architecture des ordinateurs/tme/tme6/exo1-q1B.asm b/semestre 3/architecture des ordinateurs/tme/tme6/exo1-q1B.asm new file mode 100644 index 0000000..47035aa --- /dev/null +++ b/semestre 3/architecture des ordinateurs/tme/tme6/exo1-q1B.asm @@ -0,0 +1,50 @@ +.data +ch: .space 11 +.text +#main + # prologue + addiu $29, $29, -16 + # scanf + ori $2, $0, 5 + syscall + sw $2, 4($29) + # chaine[10] = 0 + lui $8, 0x1001 + sb $0, 10($8) + + # i = 9 + lw $9, 0($29) # i + ori $9, $0, 9 + sw $9, 0($29) + +while: + # i >= 0 + lw $9, 0($29) + bltz $9, end_while + # corps + # r = nb % 10 + lw $10, 4($29) # nb + ori $11, $0, 10 + div $10, $11 + mfhi $12 # r + # nb /= 10 + mflo $10 + sw $10, 4($29) + # chaine[i] = r + 0x30 + # *(chaine + i) = r + 0x30 + addu $13, $8, $9 + addiu $12, $12, 0x30 + sb $12, 0($13) + + # i -= 1 + addiu $9, $9, -1 + sw $9, 0($29) + j while +end_while: + ori $2, $0, 4 + or $4, $0, $8 + syscall + # épilogue + addiu $29, $29, 16 + ori $2, $0, 10 + syscall
\ No newline at end of file diff --git a/semestre 3/architecture des ordinateurs/tme/tme6/exo1-q2.asm b/semestre 3/architecture des ordinateurs/tme/tme6/exo1-q2.asm new file mode 100644 index 0000000..408f19a --- /dev/null +++ b/semestre 3/architecture des ordinateurs/tme/tme6/exo1-q2.asm @@ -0,0 +1,70 @@ +.data +ch: .space 11 +.text +#main + # prologue + addiu $29, $29, -16 + # scanf + ori $2, $0, 5 + syscall + sw $2, 4($29) + # chaine[10] = 0 + lui $8, 0x1001 + sb $0, 10($8) + + # i = 9 + lw $9, 0($29) # i + ori $9, $0, 9 + sw $9, 0($29) + +for: + # i >= 0 + lw $9, 0($29) + bltz $9, end_for + # corps + # r = nb % 10 + lw $10, 4($29) # nb + ori $11, $0, 10 + div $10, $11 + mfhi $12 # r + # nb /= 10 + mflo $10 + sw $10, 4($29) + # chaine[i] = r + 0x30 + # *(chaine + i) = r + 0x30 + addu $13, $8, $9 + addiu $12, $12, 0x30 + sb $12, 0($13) + + # i -= 1 + addiu $9, $9, -1 + sw $9, 0($29) + j for +end_for: + ori $2, $0, 4 + or $4, $0, $8 + syscall + + # nbzero = 0 + ori $12, $0, 0 + # i = 0 + ori $9, $0, 0 + +while: + sltiu $10, $9, 9 + beq $10, $0, end_while + addu $11, $8, $9 + lb $11, 0($11) + addiu $11, $11, -0x30 + bne $11, $0, end_while + addiu $12, $12, 1 + addiu $9, $9, 1 + j while +end_while: + ori $2, $0, 1 + or $4, $0, $12 + syscall + # épilogue + addiu $29, $29, 16 + ori $2, $0, 10 + syscall
\ No newline at end of file diff --git a/semestre 3/architecture des ordinateurs/tme/tme6/exo1-q3.asm b/semestre 3/architecture des ordinateurs/tme/tme6/exo1-q3.asm new file mode 100644 index 0000000..eebc5ed --- /dev/null +++ b/semestre 3/architecture des ordinateurs/tme/tme6/exo1-q3.asm @@ -0,0 +1,88 @@ +.data +ch: .space 11 +.text +#main + # prologue + addiu $29, $29, -16 + # scanf + ori $2, $0, 5 + syscall + sw $2, 4($29) + # chaine[10] = 0 + lui $8, 0x1001 + sb $0, 10($8) + + # i = 9 + lw $9, 0($29) # i + ori $9, $0, 9 + sw $9, 0($29) + +for: + # i >= 0 + lw $9, 0($29) + bltz $9, end_for + # corps + # r = nb % 10 + lw $10, 4($29) # nb + ori $11, $0, 10 + div $10, $11 + mfhi $12 # r + # nb /= 10 + mflo $10 + sw $10, 4($29) + # chaine[i] = r + 0x30 + # *(chaine + i) = r + 0x30 + addu $13, $8, $9 + addiu $12, $12, 0x30 + sb $12, 0($13) + + # i -= 1 + addiu $9, $9, -1 + sw $9, 0($29) + j for +end_for: + ori $2, $0, 4 + or $4, $0, $8 + #syscall + + # nbzero = 0 + ori $12, $0, 0 + # i = 0 + ori $9, $0, 0 + +while: + sltiu $10, $9, 9 + beq $10, $0, end_while + addu $11, $8, $9 + lb $11, 0($11) + addiu $11, $11, -0x30 + bne $11, $0, end_while + addiu $12, $12, 1 + addiu $9, $9, 1 + j while +end_while: + ori $2, $0, 1 + or $4, $0, $12 + #syscall + + ori $9, $0, 0 + ori $10, $0, 10 + subu $10, $10, $12 +for2: + sltu $11, $9, $10 + beq $11, $0, end_for2 + addu $13, $8, $9 + addu $14, $13, $12 + lb $15, 0($14) + sb $15, 0($13) + addiu $9, $9, 1 + j for2 +end_for2: + ori $2, $0, 4 + or $4, $0, $8 + syscall + + # épilogue + addiu $29, $29, 16 + ori $2, $0, 10 + syscall
\ No newline at end of file |
