diff --git a/q2/algo/tp8/AdditiveArrayList.java b/q2/algo/tp8/AdditiveArrayList.java new file mode 100644 index 0000000..0ebad5e --- /dev/null +++ b/q2/algo/tp8/AdditiveArrayList.java @@ -0,0 +1,9 @@ +import java.util.Arrays; + +public class AdditiveArrayList extends MyArrayList{ + public void makeSpaceIfNeeded(){ + if(T1.length == size){ + T[] temp = Arrays.newInstance(size-1); + } + } +} diff --git a/q2/algo/tp8/ArrayListTest.java b/q2/algo/tp8/ArrayListTest.java new file mode 100644 index 0000000..dc11479 --- /dev/null +++ b/q2/algo/tp8/ArrayListTest.java @@ -0,0 +1,54 @@ +import java.util.ArrayList; +import java.util.Random; + +public class ArrayListTest { + + public static ArrayList create(int n){ + ArrayList ret = new ArrayList(); + for (;n > 0 ; n--) { + String random_Word = ""; + Random rand = new Random(); + int str_size = rand.nextInt(1, 50); + for(int i =0; i < str_size; i++){ + random_Word += (char) rand.nextInt(32, 126); + } + ret.add(random_Word); + } + return ret; + } + + public static void add(ArrayList l, String s){ + l.add(s); + } + + public static void empty(ArrayList l){ + l.clear(); + + } + + public static void display(ArrayList l){ + System.out.print("["); + for (String e : l) { + System.out.print(e); + System.out.print(", "); + } + System.out.println("]"); + } + + public static void main(String[] args) { + ArrayList a; + + a = create(5); + display(a); + + add(a, "The lazy brown fox jump over the lazy fence"); + display(a); + + empty(a); + display(a); + + add(a, "The lazy brown fox jump over the lazy fence"); + display(a); + + } +} diff --git a/q2/algo/tp8/MyArrayList.java b/q2/algo/tp8/MyArrayList.java new file mode 100644 index 0000000..108a68e --- /dev/null +++ b/q2/algo/tp8/MyArrayList.java @@ -0,0 +1,35 @@ +import java.util.Arrays; + +public abstract class MyArrayList { + protected T T1[], temp[]; + protected int size; + + public int size(){ + return size; + } + + public int physicalSize(){ + return T1.length + temp.length + size * Integer.SIZE; + } + + public T get(int i){ + return T1[i]; + } + + public void add(T o){ + makeSpaceIfNeeded(); + T1[size++] = o; + } + + public void add(int i, T o){ + makeSpaceIfNeeded(); + temp = Arrays.copyOfRange(T1, i, size-1); + T1[i] = o; + for(int j = 1; j <= temp.length; j++){ + T1[j + i] = temp[i]; + } + size++; + } + + abstract void makeSpaceIfNeeded(); +} diff --git a/q2/algo/tp8/TP7.pdf b/q2/algo/tp8/TP8.pdf similarity index 100% rename from q2/algo/tp8/TP7.pdf rename to q2/algo/tp8/TP8.pdf diff --git a/q2/fonctio/tp2/MIPS_Green_Sheet.pdf b/q2/fonctio/tp2/MIPS_Green_Sheet.pdf new file mode 100644 index 0000000..ff9b607 Binary files /dev/null and b/q2/fonctio/tp2/MIPS_Green_Sheet.pdf differ diff --git a/q2/fonctio/tp2/fonct-ordis-tp2-spim.pdf b/q2/fonctio/tp2/fonct-ordis-tp2-spim.pdf new file mode 100644 index 0000000..1cf375a Binary files /dev/null and b/q2/fonctio/tp2/fonct-ordis-tp2-spim.pdf differ diff --git a/q2/fonctio/tp2/spim-add-int.s b/q2/fonctio/tp2/spim-add-int.s new file mode 100644 index 0000000..dfc9a6e --- /dev/null +++ b/q2/fonctio/tp2/spim-add-int.s @@ -0,0 +1,32 @@ + .data +txt1: .asciiz "Entrez un premier nombre:" +txt2: .asciiz "Entrez un second nombre:" + + .text +main: + # print txt1 + la $a0, txt1 + li $v0, 4 + syscall + + #read t0 + li $v0, 5 + syscall + move $t0, $v0 + + # print txt2 + li $v0, 4 + la $a0, txt2 + syscall + + #read t1 + li $v0, 5 + syscall + move $t1, $v0 + + # a0 = t0 + t1 + add $a0, $t1, $t0 + + li $v0, 1 + syscall + jr $ra diff --git a/q2/fonctio/tp2/spim-loop-5-write.s b/q2/fonctio/tp2/spim-loop-5-write.s new file mode 100644 index 0000000..f40e5f9 --- /dev/null +++ b/q2/fonctio/tp2/spim-loop-5-write.s @@ -0,0 +1,12 @@ +main: + li $a0, 5 + li $a1, 0 + li $v0, 1 + j loop + +loop: + syscall + addiu $a0, -1 + bne $a0, $a1, loop + # bgtz $a0, loop + jr $ra diff --git a/q2/fonctio/tp2/spim-loop-5.s b/q2/fonctio/tp2/spim-loop-5.s new file mode 100644 index 0000000..726cd4b --- /dev/null +++ b/q2/fonctio/tp2/spim-loop-5.s @@ -0,0 +1,10 @@ +main: + li $a0, 5 + li $a1, 0 + j loop + +loop: + addiu $a0, -1 + bne $a0, $a1, loop + # bgtz $a0, loop + jr $ra diff --git a/q2/fonctio/tp2/spim-loop.s b/q2/fonctio/tp2/spim-loop.s new file mode 100644 index 0000000..832a472 --- /dev/null +++ b/q2/fonctio/tp2/spim-loop.s @@ -0,0 +1,3 @@ +main: + nop + j main diff --git a/q2/fonctio/tp2/spim-print-str.s b/q2/fonctio/tp2/spim-print-str.s new file mode 100644 index 0000000..5b82986 --- /dev/null +++ b/q2/fonctio/tp2/spim-print-str.s @@ -0,0 +1,9 @@ + .data +mystr: .asciiz "The answer to live, universe and everything else is.... 42" + + .text +main: + la $a0, mystr + li $v0, 4 + syscall + jr $ra diff --git a/q2/fonctio/tp2/spim-read-int.s b/q2/fonctio/tp2/spim-read-int.s new file mode 100644 index 0000000..5da882e --- /dev/null +++ b/q2/fonctio/tp2/spim-read-int.s @@ -0,0 +1,33 @@ + .data +question: .asciiz "Entrez un nombre: " +gr: .asciiz "Trop Grand!\n" +pe: .asciiz "Valeur acceptee\n" + + .text +main: + la $a0, question + li $v0, 4 + syscall + + li $v0, 5 + syscall + + bgt $v0, 10, grand + bgt $v0, 0, petit + jr $ra + +grand: + la $a0, gr + li $v0, 4 + syscall + j main + +petit: + la $a0, pe + li $v0, 4 + syscall + + lr $a0, + li $v0, 4 + syscall + j main diff --git a/q2/fonctio/tp2/spim-to-binary.s b/q2/fonctio/tp2/spim-to-binary.s new file mode 100644 index 0000000..736c6fb --- /dev/null +++ b/q2/fonctio/tp2/spim-to-binary.s @@ -0,0 +1,27 @@ + .data +ask: .ascii "Entrez un nombre:" + + .text +main: + +# Print(ask) +li $v0 4 +la $a0 ask +syscall + +# read() +li $v0 5 +syscall + +li $t0 2 #base + +divi: + +div $v0, $t0 +li $v0, 1 +mfhi $a0 +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 new file mode 100644 index 0000000..6096667 --- /dev/null +++ b/q2/fonctio/tp2/switch-table.s @@ -0,0 +1,29 @@ + .data +tab: .word case5, case6, case7, case8 +q1: .asciiz "Entrez un nombre entre 5 et 8:" + + .text +main: + li $v0, 5 + la $a0, q1 + syscall + + li $v0, 4 + syscall + + +case5: + + j end_case +case6: + + j end_case +case7: + + j end_case +case8: + + j end_case + +end_case: + jr $ra