From 04639ccfb6c94fb3f6fd32adeb8ee3c45b7e2f22 Mon Sep 17 00:00:00 2001 From: hiGepi Date: Sat, 26 Nov 2022 23:34:46 +0100 Subject: [PATCH] t1 tp2 --- .../TP3/T1-TP3-code/TP3-dist/parity_deroule.s | 26 ++++++++++++++++++ T1/TP/TP3/T1-TP3-code/TP3-dist/parity_jump.s | 27 +++++++++++++++++++ T1/TP/TP3/T1-TP3-code/TP3-dist/power.s | 17 ++++++++++++ T1/TP/TP3/T1-TP3-code/TP3-dist/power_succ.s | 19 +++++++++++++ T1/TP/TP3/T1-TP3-code/TP3-dist/somme.s | 17 ++++++++++++ .../TP3/T1-TP3-code/TP3-dist/somme_deroule.s | 20 ++++++++++++++ .../T1-TP3-code/TP3-dist/somme_deroule_opti.s | 19 +++++++++++++ 7 files changed, 145 insertions(+) create mode 100644 T1/TP/TP3/T1-TP3-code/TP3-dist/parity_deroule.s create mode 100644 T1/TP/TP3/T1-TP3-code/TP3-dist/parity_jump.s create mode 100644 T1/TP/TP3/T1-TP3-code/TP3-dist/power.s create mode 100644 T1/TP/TP3/T1-TP3-code/TP3-dist/power_succ.s create mode 100644 T1/TP/TP3/T1-TP3-code/TP3-dist/somme.s create mode 100644 T1/TP/TP3/T1-TP3-code/TP3-dist/somme_deroule.s create mode 100644 T1/TP/TP3/T1-TP3-code/TP3-dist/somme_deroule_opti.s diff --git a/T1/TP/TP3/T1-TP3-code/TP3-dist/parity_deroule.s b/T1/TP/TP3/T1-TP3-code/TP3-dist/parity_deroule.s new file mode 100644 index 0000000..90b7ae1 --- /dev/null +++ b/T1/TP/TP3/T1-TP3-code/TP3-dist/parity_deroule.s @@ -0,0 +1,26 @@ +;; MIPS program parity check + .data +N: .word 12 +A: .double 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 +B: .double 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 + + .text +main: + dadd r1,r0,r0 ; r1=i=0 + lw r2, N(r0) ; r2=N +loop: + l.d f1, A(r1) ; f1=A[i] + l.d f2, B(r1) ; f2=B[i] + daddi r1,r1,8 ; i++ + sub.d f2, f2, f1 ; f2=B[i]+A[i] + l.d f3, A(r1) ; f3=A[i+1] + l.d f4, B(r1) ; f4=B[i+1] + add.d f4, f4, f3 ; f4=B[i+1]-A[i+1] + daddi r2,r2,-2 ; N--; + s.d f4, B(r1) ; B[i+1] = f4 + daddi r1,r1,-8 ; i-- + s.d f2, B(r1) ; B[i] = f2 + daddi r1,r1,16 ; i+=2 + bne r2, r0, loop + nop + halt \ No newline at end of file diff --git a/T1/TP/TP3/T1-TP3-code/TP3-dist/parity_jump.s b/T1/TP/TP3/T1-TP3-code/TP3-dist/parity_jump.s new file mode 100644 index 0000000..a0bb11f --- /dev/null +++ b/T1/TP/TP3/T1-TP3-code/TP3-dist/parity_jump.s @@ -0,0 +1,27 @@ +;; MIPS program parity check + .data +N: .word 12 +A: .double 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 +B: .double 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 + + .text +main: + dadd r1,r0,r0 ; r1=i=0 + lw r2, N(r0) ; r2=N +loop: + l.d f1, A(r1) ; f1=A[i] + l.d f2, B(r1) ; f2=B[i] + andi $t0, r1, 1 ; i&1 + bnez $t0, impair ; if i impair + sub.d f2, f2, f1 ; f2=B[i]-A[i] + beq r0,r0,end + nop +impair: + add.d f2, f2, f1 ; f2=B[i]+A[i] +end: + s.d f2, B(r1) ; B = f2 + daddi r1,r1,8 ; i++ + daddi r2,r2,-1 ; N--; + bne r2, r0, loop + nop + halt \ No newline at end of file diff --git a/T1/TP/TP3/T1-TP3-code/TP3-dist/power.s b/T1/TP/TP3/T1-TP3-code/TP3-dist/power.s new file mode 100644 index 0000000..6db9a1e --- /dev/null +++ b/T1/TP/TP3/T1-TP3-code/TP3-dist/power.s @@ -0,0 +1,17 @@ +;; MIPS program pow(x,n) + .data +N: .word 5 +X: .double 2 +W: .double 1 + + .text + dadd r1,r0,r0 ; r1=i=0 + lw r2, N(r0) ; r2=n + l.d f1, W(r0) ; f1=w + l.d f2, X(r0) ; f2=x +loop: + mul.d f1, f1, f2 ; w*=x + addi r1, r1, 1 ; i++ + bne r1, r2, loop + s.d f1, W(r0) + halt \ No newline at end of file diff --git a/T1/TP/TP3/T1-TP3-code/TP3-dist/power_succ.s b/T1/TP/TP3/T1-TP3-code/TP3-dist/power_succ.s new file mode 100644 index 0000000..a4f5200 --- /dev/null +++ b/T1/TP/TP3/T1-TP3-code/TP3-dist/power_succ.s @@ -0,0 +1,19 @@ + .data +N: .word 5 +X: .double 2 +W: .double 1 + + .text + lw r2, N(r0) ; r2=n + l.d f1, W(r0) ; f1=w + l.d f2, X(r0) ; f2=x +loop: + andi $t0, r2, 1 ; n&1 + beqz $t0, pair ; if n pair + mul.d f1, f1, f2 ; w*=x sinon +pair: + mul.d f2, f2, f2 + dsrl r2, r2, 1 ; n>>1 + bnez r2, loop ; while(n) + s.d f1, W(r0) + halt \ No newline at end of file diff --git a/T1/TP/TP3/T1-TP3-code/TP3-dist/somme.s b/T1/TP/TP3/T1-TP3-code/TP3-dist/somme.s new file mode 100644 index 0000000..dc90dc0 --- /dev/null +++ b/T1/TP/TP3/T1-TP3-code/TP3-dist/somme.s @@ -0,0 +1,17 @@ + .data +N: .word 96 +A: .double 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 +S: .double 0 + + .text +main: + dadd r1,r0,r0 ; r1=i=0 + lw r2, N(r0) ; r2=N + l.d f1, S(r0) ; f1=S +loop: + l.d f2, A(r1) ; f2=A[i] + add.d f1, f1, f2 ; f1=f1+A[i] + addi r1, r1, 8 ; i++ + bne r1, r2, loop + s.d f1, S(r0) ; S=somme(A) + halt \ No newline at end of file diff --git a/T1/TP/TP3/T1-TP3-code/TP3-dist/somme_deroule.s b/T1/TP/TP3/T1-TP3-code/TP3-dist/somme_deroule.s new file mode 100644 index 0000000..de03d11 --- /dev/null +++ b/T1/TP/TP3/T1-TP3-code/TP3-dist/somme_deroule.s @@ -0,0 +1,20 @@ + .data +N: .word 96 +A: .double 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 +S: .double 0 + + .text +main: + dadd r1,r0,r0 ; r1=i=0 + lw r2, N(r0) ; r2=N + l.d f1, S(r0) ; f1=S +loop: + l.d f2, A(r1) ; f2=A[i] + add.d f1, f1, f2 ; f1=f1+A[i] + addi r1, r1, 8 ; i++ + l.d f3, A(r1) ; f2=A[i+1] + add.d f1, f1, f3 ; f1=f1+A[i+1] + addi r1, r1, 8 ; i++ + bne r1, r2, loop + s.d f1, S(r0) ; S=somme(A) + halt \ No newline at end of file diff --git a/T1/TP/TP3/T1-TP3-code/TP3-dist/somme_deroule_opti.s b/T1/TP/TP3/T1-TP3-code/TP3-dist/somme_deroule_opti.s new file mode 100644 index 0000000..378d9cb --- /dev/null +++ b/T1/TP/TP3/T1-TP3-code/TP3-dist/somme_deroule_opti.s @@ -0,0 +1,19 @@ + .data +N: .word 96 +A: .double 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 +S: .double 0 + + .text +main: + dadd r1,r0,r0 ; r1=i=0 + lw r2, N(r0) ; r2=N + l.d f1, S(r0) ; f1=S + l.d f2, A(r1) ; f2=A[i] +loop: + addi r1, r1, 8 ; i++ + add.d f1, f1, f2 ; f1=f1+A[i] + l.d f2, A(r1) ; f2=A[i+1] + bne r1, r2, loop + nop + s.d f1, S(r0) ; S=somme(A) + halt \ No newline at end of file