t1 tp2
This commit is contained in:
parent
8ea2c9f239
commit
04639ccfb6
7 changed files with 145 additions and 0 deletions
26
T1/TP/TP3/T1-TP3-code/TP3-dist/parity_deroule.s
Normal file
26
T1/TP/TP3/T1-TP3-code/TP3-dist/parity_deroule.s
Normal file
|
@ -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
|
27
T1/TP/TP3/T1-TP3-code/TP3-dist/parity_jump.s
Normal file
27
T1/TP/TP3/T1-TP3-code/TP3-dist/parity_jump.s
Normal file
|
@ -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
|
17
T1/TP/TP3/T1-TP3-code/TP3-dist/power.s
Normal file
17
T1/TP/TP3/T1-TP3-code/TP3-dist/power.s
Normal file
|
@ -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
|
19
T1/TP/TP3/T1-TP3-code/TP3-dist/power_succ.s
Normal file
19
T1/TP/TP3/T1-TP3-code/TP3-dist/power_succ.s
Normal file
|
@ -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
|
17
T1/TP/TP3/T1-TP3-code/TP3-dist/somme.s
Normal file
17
T1/TP/TP3/T1-TP3-code/TP3-dist/somme.s
Normal file
|
@ -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
|
20
T1/TP/TP3/T1-TP3-code/TP3-dist/somme_deroule.s
Normal file
20
T1/TP/TP3/T1-TP3-code/TP3-dist/somme_deroule.s
Normal file
|
@ -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
|
19
T1/TP/TP3/T1-TP3-code/TP3-dist/somme_deroule_opti.s
Normal file
19
T1/TP/TP3/T1-TP3-code/TP3-dist/somme_deroule_opti.s
Normal file
|
@ -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
|
Loading…
Reference in a new issue