summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/assembler.c4
-rw-r--r--lib/instructions.txt20
-rw-r--r--lib/linker.c8
-rw-r--r--lib/memoire.c1
-rw-r--r--lib/simulator.c39
-rw-r--r--po/ProjetArchi.pot94
-rw-r--r--samples/rechcara.s35
-rw-r--r--samples/recherche.s38
-rw-r--r--samples/sommeentiers.s31
9 files changed, 133 insertions, 137 deletions
diff --git a/lib/assembler.c b/lib/assembler.c
index 64eafb9..8e9452e 100644
--- a/lib/assembler.c
+++ b/lib/assembler.c
@@ -1650,6 +1650,7 @@ void asm_eol(void)
t->pattern = NULL;
t->symbol = NULL;
InsererVarDansTab(&it, CreerElement(instr->names[i], t));
+ fprintf(stderr, "On a %s qui vaut %i\n", instr->names[i], e_current->index);
evaluate_pattern(&it, e_current);
break;
default:
@@ -1675,6 +1676,7 @@ void asm_eol(void)
t->pattern = NULL;
t->symbol = NULL;
}
+ fprintf(stderr, "On a %s qui vaut %i\n", instr->implicits[i], t->avalue);
InsererVarDansTab(&it, CreerElement(instr->implicits[i], t));
break;
case 1: /* type prédéfinit */
@@ -1687,6 +1689,7 @@ void asm_eol(void)
t->child = t->next = NULL;
t->pattern = NULL;
t->symbol = NULL;
+ fprintf(stderr, "On a %s qui vaut %i\n", instr->implicits[i], t->avalue);
InsererVarDansTab(&it, CreerElement(instr->implicits[i], t));
break;
case 2: /* type valeur */
@@ -1696,6 +1699,7 @@ void asm_eol(void)
t->child = t->next = NULL;
t->pattern = NULL;
t->symbol = NULL;
+ fprintf(stderr, "On a %s qui vaut %i\n", instr->implicits[i], t->avalue);
InsererVarDansTab(&it, CreerElement(instr->implicits[i], t));
break;
}
diff --git a/lib/instructions.txt b/lib/instructions.txt
index c9717cf..8548887 100644
--- a/lib/instructions.txt
+++ b/lib/instructions.txt
@@ -33,6 +33,10 @@ I:ADD c1=.Pr,c2=.Pr,c3=.Pr;op=0x0;e=0x0
I:ADD c1=.Pr,c2=.Pr,.I=.C;op=0x0;e=0x1
I:ADU c1=.Pr,c2=.Pr,c3=.Pr;op=0x0;e=0x2
I:ADU c1=.Pr,c2=.Pr,.I=.C;op=0x0;e=0x3
+I:ADD c2=.Pr,c3=.Pr;op=0x0;e=0x0;c1=c2
+I:ADD c2=.Pr,.I=.C;op=0x0;e=0x1;c1=c2
+I:ADU c2=.Pr,c3=.Pr;op=0x0;c1=c2;e=0x2
+I:ADU c2=.Pr,.I=.C;op=0x0;c1=c2;e=0x3
p:ADS=ADD
@@ -40,6 +44,10 @@ I:SUB c1=.Pr,c2=.Pr,c3=.Pr;op=0x1;e=0x0
I:SUB c1=.Pr,c2=.Pr,.I=.C;op=0x1;e=0x1
I:SBU c1=.Pr,c2=.Pr,c3=.Pr;op=0x1;e=0x2
I:SBU c1=.Pr,c2=.Pr,.I=.C;op=0x1;e=0x3
+I:SUB c2=.Pr,c3=.Pr;op=0x1;e=0x0;c1=c2
+I:SUB c2=.Pr,.I=.C;op=0x1;e=0x1;c1=c2
+I:SBU c2=.Pr,c3=.Pr;op=0x1;e=0x2;c1=c2
+I:SBU c2=.Pr,.I=.C;op=0x1;e=0x3;c1=c2
p:SBS=SUB
@@ -64,11 +72,11 @@ I:SHR c1=.Pr,c2=.Pr,.I=.C;op=0x7;e=0x1
# Transferts
-I:MOV c1=.Pr,rm=.Pm;op=8;e=0;c2=.Fa;c3=regop
-I:MOV c1=.Pr,c3=.Pr;op=8;e=0;c2=0
-I:MOV c1=.Pr,.I=.C;op=8;e=1
-I:MOV rm=.Pm,c2=.Pr;op=8;e=2;c1=.Fa;c3=regop
-I:MOV rm=.Pm,.I=.C;op=8;e=3;c1=.Fa;c3=regop
+I:MOV c2=.Pr,rm=.Pm;op=8;e=2;c1=.Fa;c3=regop
+I:MOV c2=.Pr,c3=.Pr;op=8;e=2
+I:MOV c3=.Pr,.I=.C;op=8;e=1
+I:MOV rm=.Pm,c2=.Pr;op=8;e=0;c1=.Fa;c3=regop
+I:MOV rm=.Pm,.I=.C;op=8;e=1;c1=.Fa;c3=regop
p:MV=MOV
@@ -111,7 +119,7 @@ I:JNZ .I=.O;op=0xa;e=0x34
I:JNS .I=.O;op=0xa;e=0x38
I:JNP .I=.O;op=0xa;e=0x3c
-I:JMP .I=.O;op=0x0c;e=0x2
+I:JMP .I=.O;op=0xa;e=0x0
I:HALT;op=0x7f
I:RESET;op=0x7f;e=1
diff --git a/lib/linker.c b/lib/linker.c
index 0be4cfc..81fc507 100644
--- a/lib/linker.c
+++ b/lib/linker.c
@@ -238,27 +238,29 @@ static void dumprelog(FILE * f)
exception(1, _("Internal error"));
break;
}
+ fprintf(stderr, "Relogement effectué sur %i, de %i octets pour le symbole %s\n", s->offset, decal, s->name);
objects[s->objindex]->text[s->offset] += decal;
writeword(objects[s->objindex]->textstart + s->offset, f);
break;
case 3: /* data */
switch (t->type) {
case 0:
- objects[s->objindex]->data[s->offset] +=
+ decal =
objects[t->objindex]->textstart + t->offset;
break;
case 2:
- objects[s->objindex]->data[s->offset] +=
+ decal =
textsize + objects[t->objindex]->datastart + t->offset;
break;
case 4:
- objects[s->objindex]->data[s->offset] +=
+ decal =
textsize + datasize + objects[t->objindex]->bssstart + t->offset;
break;
default:
exception(1, _("Internal error"));
break;
}
+ objects[s->objindex]->data[s->offset] += decal;
writeword(textsize + objects[s->objindex]->datastart + s->offset, f);
break;
default:
diff --git a/lib/memoire.c b/lib/memoire.c
index eb6dadc..264009c 100644
--- a/lib/memoire.c
+++ b/lib/memoire.c
@@ -126,4 +126,5 @@ void ST(Uint32 offset, Uint32 valeur)
memoire_principale[offset] = valeur;
break;
}
+ fflush(stdout);
}
diff --git a/lib/simulator.c b/lib/simulator.c
index 802587b..16cc2ef 100644
--- a/lib/simulator.c
+++ b/lib/simulator.c
@@ -57,8 +57,8 @@ static Uint32 readword(FILE * f)
Uint32 Adresse(Uint32 u, Uint32 instruction)
{
Uint32 tmp;
-
- switch (champ(u, 2)) {
+
+ switch (champ(u, 4)) {
case 0:
exception(1, _("Adresse: Call With Invalid r/m Field State ( r/m=00 )"));
return (0);
@@ -101,7 +101,6 @@ void DecodeExec(Uint32 instruction)
if (Opcode(instruction) & 0x80) {
- fprintf(stderr, "Opcode FPU\n");
fpu(Opcode(instruction));
} else {
switch (Opcode(instruction)) {
@@ -113,7 +112,6 @@ void DecodeExec(Uint32 instruction)
case 5:
case 6:
case 7:
- fprintf(stderr, "Opcode ALU\n");
/* ALU */
champ_registre_resultat = Champ1(instruction); /* Champ du registre dans lequel va etre stocké le résultat */
val1 = LireRegistre(Champ2(instruction)); /* Premier entier qui va etre utilisé dans l'opération */
@@ -188,7 +186,6 @@ void DecodeExec(Uint32 instruction)
}
break;
case 8: /* MOV */
- fprintf(stderr, "Opcode MOV\n");
if (ValeurBit(Extension(instruction), 4) == 1) { /* MOV conditionnel */
if (ValeurBit(Extension(instruction), 5) == 0) { /* Test normal */
switch (champ(Extension(instruction) >> 2, 4)) { /* teste les bits 2 et 3 */
@@ -224,38 +221,28 @@ void DecodeExec(Uint32 instruction)
}
/* Pas de MOV conditionnel */
if (ValeurBit(Extension(instruction), 1) == 0) { /* Mov arg1 arg2 */
- fprintf(stderr, "MOV arg1, arg2\n");
if (ValeurBit(Extension(instruction), 0) == 0) { /* arg2 = reg */
- fprintf(stderr, "arg2 = reg (%i)\n", Champ2(instruction));
if (champ(Champ1(instruction), 2) == 0) { /* r/m de arg1 = 0 */
- fprintf(stderr, "arg1 = reg (%i)\n", Champ3(instruction));
EcrireRegistre(Champ3(instruction), LireRegistre(Champ2(instruction)));
} else {
- fprintf(stderr, "arg1 = adresse\n");
ST(Adresse(Champ1(instruction), instruction),
LireRegistre(Champ2(instruction)));
}
} else { /* arg2 = imm32 */
- fprintf(stderr, "arg2 = imm (%i)\n", LireInstruction());
if (champ(Champ1(instruction), 2) == 0) { /* r/m de arg1 = 0 */
- fprintf(stderr, "arg1 = reg (%i)\n", Champ3(instruction));
EcrireRegistre(Champ3(instruction), LireInstruction());
IncrementeCompteurOrdinal();
} else {
- fprintf(stderr, "arg1 = adresse\n");
- ST(Adresse(Champ1(instruction), instruction), LireInstruction());
+ val = Adresse(Champ1(instruction), instruction);
+ ST(val, LireInstruction());
IncrementeCompteurOrdinal();
}
}
- } else {
- fprintf(stderr, "MOV arg2, arg1\n");
+ } else { /* mov arg2, arg1 */
if (ValeurBit(Extension(instruction), 0) == 0) { /* arg2 = reg */
- fprintf(stderr, "arg2 = reg (%i)\n", Champ2(instruction));
if (champ(Champ1(instruction), 2) == 0) { /* r/m de arg1 = 0 */
- fprintf(stderr, "arg1 = reg (%i)\n", Champ3(instruction));
EcrireRegistre(Champ2(instruction), LireRegistre(Champ3(instruction)));
} else {
- fprintf(stderr, "arg1 = addresse\n");
EcrireRegistre(Champ2(instruction),
LD(Adresse(Champ1(instruction), instruction)));
}
@@ -328,6 +315,8 @@ void DecodeExec(Uint32 instruction)
tmp += LireRegistrePC();
}
EcrireRegistrePC(tmp);
+ } else {
+ IncrementeCompteurOrdinal();
}
break;
@@ -372,7 +361,7 @@ void DecodeExec(Uint32 instruction)
break;
case 127: /* HALT-RESET */
- if (ValeurBit(Extension(instruction), 0)) {
+ if (ValeurBit(Extension(instruction), 0) == 0) {
HasToRun = 0; /* Halt */
} else {
HasToReset = 1; /* Reset */
@@ -390,16 +379,16 @@ void AfficheReg(void) // affiche reg
int i, j;
for (i = 0; i <= 3; i++) {
- for (j = 1; j <= 8; j++) {
+ for (j = 0; j < 8; j++) {
fprintf(stderr, " R%02d ", (i * 8 + j));
}
fprintf(stderr, "\n");
- for (j = 1; j <= 8; j++) {
- fprintf(stderr, "%08lX ", (registre[i * 8 + j - 1]));
+ for (j = 0; j < 8; j++) {
+ fprintf(stderr, "%08lX ", (registre[i * 8 + j]));
}
fprintf(stderr, "\n");
}
- fprintf(stderr, "Rg: %08lX | Rd: %08lX | Flag: %08lX | PC: %08lX\n\n", LireRegistreRG(), LireRegistreRD(),
+ fprintf(stderr, "Rg: %08lX | Rd: %08lX | Flag: %08lX | PC: %08lX\n", LireRegistreRG(), LireRegistreRD(),
LireRegistreFLAG(), LireRegistrePC());
}
@@ -417,13 +406,13 @@ void Debogueur(void)
switch (fgetc(input)) {
case 'G':
case 'g':
- fprintf(stderr, "Go\n");
+ fprintf(stderr, "Go\n\n");
debug = 0;
out = 1;
break;
case 'p':
case 'P':
- fprintf(stderr, "Proceed\n");
+ fprintf(stderr, "Proceed\n\n");
out = 1;
break;
case 'R':
diff --git a/po/ProjetArchi.pot b/po/ProjetArchi.pot
index a0d0ef0..2d6ef39 100644
--- a/po/ProjetArchi.pot
+++ b/po/ProjetArchi.pot
@@ -6,7 +6,7 @@
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
-"POT-Creation-Date: 2001-04-17 00:44+0200\n"
+"POT-Creation-Date: 2001-04-17 02:32+0200\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
@@ -132,7 +132,7 @@ msgid "Pattern not matching..."
msgstr ""
#: lib/assembler.c:1345 lib/assembler.c:1375 lib/assembler.c:1626
-#: lib/assembler.c:1642 lib/assembler.c:1656
+#: lib/assembler.c:1642 lib/assembler.c:1657
msgid "Unknow constant type in the meta language"
msgstr ""
@@ -142,7 +142,7 @@ msgid ""
msgstr ""
#: lib/assembler.c:1387 lib/assembler.c:1412 lib/assembler.c:1420
-#: lib/assembler.c:1684
+#: lib/assembler.c:1686
msgid "Logical error in meta language"
msgstr ""
@@ -158,7 +158,7 @@ msgstr ""
msgid "Value too large for field"
msgstr ""
-#: lib/assembler.c:1522 lib/assembler.c:1708
+#: lib/assembler.c:1522 lib/assembler.c:1712
msgid "Unknow instruction"
msgstr ""
@@ -186,121 +186,121 @@ msgstr ""
msgid "Unmatched instruction"
msgstr ""
-#: lib/assembler.c:1732 lib/assembler.c:1774 lib/linker.c:45 lib/linker.c:67
+#: lib/assembler.c:1736 lib/assembler.c:1778 lib/linker.c:45 lib/linker.c:67
msgid "Error writing file"
msgstr ""
-#: lib/assembler.c:1783 lib/assembler.c:2151 lib/linker.c:56
+#: lib/assembler.c:1787 lib/assembler.c:2155 lib/linker.c:56
#: lib/simulator.c:42
msgid "Error reading file"
msgstr ""
-#: lib/assembler.c:1800
+#: lib/assembler.c:1804
msgid "Creating temporary files"
msgstr ""
-#: lib/assembler.c:1803
+#: lib/assembler.c:1807
msgid "Error writing file __text__"
msgstr ""
-#: lib/assembler.c:1807
+#: lib/assembler.c:1811
msgid "Error writing file __symbols__"
msgstr ""
-#: lib/assembler.c:1811
+#: lib/assembler.c:1815
msgid "Dumping memory into object file"
msgstr ""
#. Segment de texte
-#: lib/assembler.c:1816
+#: lib/assembler.c:1820
msgid "Dumping text segment"
msgstr ""
-#: lib/assembler.c:1818 lib/assembler.c:1948 lib/assembler.c:2028
+#: lib/assembler.c:1822 lib/assembler.c:1952 lib/assembler.c:2032
#, c-format
msgid "Processing word number %i coming from line %i of the file %s."
msgstr ""
-#: lib/assembler.c:1891 lib/assembler.c:1894 lib/assembler.c:1972
-#: lib/assembler.c:1975
+#: lib/assembler.c:1895 lib/assembler.c:1898 lib/assembler.c:1976
+#: lib/assembler.c:1979
msgid "Can't evaluate expression for a direct value"
msgstr ""
-#: lib/assembler.c:1898 lib/assembler.c:1979
+#: lib/assembler.c:1902 lib/assembler.c:1983
msgid "Can only use the diff() function onto labels"
msgstr ""
-#: lib/assembler.c:1903 lib/assembler.c:1907 lib/assembler.c:1984
-#: lib/assembler.c:1988
+#: lib/assembler.c:1907 lib/assembler.c:1911 lib/assembler.c:1988
+#: lib/assembler.c:1992
msgid "Can only evaluate a diff on local symbols"
msgstr ""
-#: lib/assembler.c:1911 lib/assembler.c:1992
+#: lib/assembler.c:1915 lib/assembler.c:1996
msgid "Can only evaluate a diff on symbols from the same segment"
msgstr ""
-#: lib/assembler.c:1917 lib/assembler.c:1998
+#: lib/assembler.c:1921 lib/assembler.c:2002
msgid "Can't evaluate expression"
msgstr ""
#. Segment de data
-#: lib/assembler.c:1946
+#: lib/assembler.c:1950
msgid "Dumping data segment"
msgstr ""
#. Segment bss
-#: lib/assembler.c:2026
+#: lib/assembler.c:2030
msgid "Dumping bss segment"
msgstr ""
-#: lib/assembler.c:2073
+#: lib/assembler.c:2077
#, c-format
msgid ""
"Statistics: %i words of text, %i words of data, and %i words reserved.\n"
"%i symbols generated with %i internal and %i external.\n"
msgstr ""
-#: lib/assembler.c:2102
+#: lib/assembler.c:2106
msgid "Loading file"
msgstr ""
-#: lib/assembler.c:2103 lib/meta.c:516
+#: lib/assembler.c:2107 lib/meta.c:516
#, c-format
msgid "Opening file '%s'"
msgstr ""
-#: lib/assembler.c:2112 lib/meta.c:524
+#: lib/assembler.c:2116 lib/meta.c:524
msgid "Reading file"
msgstr ""
-#: lib/assembler.c:2114 lib/meta.c:526
+#: lib/assembler.c:2118 lib/meta.c:526
#, c-format
msgid "Reading line %i"
msgstr ""
-#: lib/assembler.c:2123
+#: lib/assembler.c:2127
#, c-format
msgid "Summering line %s"
msgstr ""
-#: lib/assembler.c:2142
+#: lib/assembler.c:2146
#, c-format
msgid "Assembling file %s...\n"
msgstr ""
-#: lib/assembler.c:2143
+#: lib/assembler.c:2147
msgid "Opening output file"
msgstr ""
-#: lib/assembler.c:2146
+#: lib/assembler.c:2150
msgid "Error writing output file"
msgstr ""
-#: lib/assembler.c:2153 lib/linker.c:279
+#: lib/assembler.c:2157 lib/linker.c:281
msgid "Writing output file"
msgstr ""
-#: lib/assembler.c:2154
+#: lib/assembler.c:2158
#, c-format
msgid "Generating output file %s...\n"
msgstr ""
@@ -488,36 +488,36 @@ msgstr ""
msgid "Symbol %s not found"
msgstr ""
-#: lib/linker.c:238 lib/linker.c:259 lib/linker.c:265
+#: lib/linker.c:238 lib/linker.c:260 lib/linker.c:267
msgid "Internal error"
msgstr ""
-#: lib/linker.c:283
+#: lib/linker.c:285
msgid "No startpoint defined."
msgstr ""
-#: lib/linker.c:286
+#: lib/linker.c:288
msgid "Writing headers"
msgstr ""
-#: lib/linker.c:295
+#: lib/linker.c:297
msgid "Writing relocating informations"
msgstr ""
-#: lib/linker.c:298
+#: lib/linker.c:300
msgid "Writing text segments"
msgstr ""
-#: lib/linker.c:303
+#: lib/linker.c:305
msgid "Writing data segments"
msgstr ""
-#: lib/linker.c:310
+#: lib/linker.c:312
#, c-format
msgid "Statistics: %i words of text, %i words of data and reserving %i words\n"
msgstr ""
-#: lib/linker.c:312
+#: lib/linker.c:314
#, c-format
msgid "Output file size: %i words containing %i relocating offsets.\n"
msgstr ""
@@ -531,19 +531,19 @@ msgid "Adresse: Unmatched Addr Field"
msgstr ""
#. arg2 = imm32
-#: lib/simulator.c:263
+#: lib/simulator.c:250
msgid "MOV: Memory to Memory Forbidden On This Type Of Processor"
msgstr ""
-#: lib/simulator.c:383
+#: lib/simulator.c:372
msgid "DecodeExec: Invalid Opcode"
msgstr ""
-#: lib/simulator.c:435
+#: lib/simulator.c:424
msgid "Shutdown requested"
msgstr ""
-#: lib/simulator.c:437
+#: lib/simulator.c:426
msgid ""
"Help:\n"
"G: go\n"
@@ -553,16 +553,16 @@ msgid ""
msgstr ""
#. verification de la signature
-#: lib/simulator.c:474
+#: lib/simulator.c:465
msgid "Invalid Signature"
msgstr ""
-#: lib/simulator.c:477
+#: lib/simulator.c:468
#, c-format
msgid "Loading file %s"
msgstr ""
-#: lib/simulator.c:512
+#: lib/simulator.c:503
#, c-format
msgid "Executing file %s"
msgstr ""
diff --git a/samples/rechcara.s b/samples/rechcara.s
index c4747c3..4eeeef8 100644
--- a/samples/rechcara.s
+++ b/samples/rechcara.s
@@ -1,26 +1,25 @@
-;Recherche du caractere 0DH dans une chaine de caracteres
+;Recherche du caractere 0x0D dans une chaine de caracteres
.DATA
-CHAINE DS "ceci est un test de chaine de caractere de quatre vingt caracteres akdijhgffddss"
-MSGPASTROUVE DS "Le caractere 0DH n'a pas été trouvé dans la chaine"
-MSGTROUVE DS "Le caractere 0DH a été trouvé dans la chaine"
-ZERO DB 0
+CHAINE DS "ceci est un test de chaine\r de caractere quelconque..."
+MSGPASTROUVE DS "Le caractere 0x0D n'a pas été trouvé dans la chaine\n"
+MSGTROUVE DS "Le caractere 0x0D a été trouvé dans la chaine à l'index "
+MSGENDL DS "\n"
.TEXT
.START
- MOV R1,ZERO;
- MOV R3,80;
- MOV R2,0x0D;
- MOV R5,ZERO;
-BOUCLE: MOV R4,CHAINE[R1];
- JE R4,R2,TROUVE;
- ADD R1,R1,1;
- SUB R3,R3,1;
- JNE R3 R5 BOUCLE;
- MOV, [0xffffff04],MSGPASTROUVE;
- JMP FIN;
-TROUVE: MOV, [0xffffff04],MSGTROUVE;
+ MOV R1, R0 ; R1 est le compteur
+ MOV R2, 0x0D ; R2 est l'élement recherché
+
+BOUCLE: MOV R4,CHAINE[R1] ; On lit un caractère.
+ JE R4, R2, TROUVE
+ ADD R1, 1 ; On incrément le pointeur
+ JNE R4, R0, BOUCLE ; C'était le caractère 0? On sort
+ MOV, [0xffffff04], MSGPASTROUVE;
+ JMP FIN
+TROUVE: MOV, [0xffffff04], MSGTROUVE;
+ MOV, [0xffffff06], R1
+ MOV, [0xffffff04], MSGENDL
FIN: HALT
- \ No newline at end of file
diff --git a/samples/recherche.s b/samples/recherche.s
index 46b979e..78db501 100644
--- a/samples/recherche.s
+++ b/samples/recherche.s
@@ -1,26 +1,24 @@
.DATA
-TAB1 DS "efghijklynoparstuvzxywqbcdefghijklynoparstuvzxywqbcdefghijklynoparstuvzxywqbcdefghijklynoparstuvzxywNNEX"
-TAB2 DS "aafghijklynoparstuvzxywqbcdefghijklynoparstuvzxywqbcdefghijklynoparstuvzxywqbcdefghijklynoparstuvzxy"
-MSGTROUVE DS "TAB1 et TAB2 ont un élément en commun"
-MSGPASTROUVE DS "TAB1 et TAB2 n'ont pas d'élément en commun"
-ZERO DB 0
+TAB1 DS "efghijklynoparstuvzxywqbcdefghijklynoparstuvzxywqbcdefghijklynoparstuvzxywqbcdefghXjklynoparstuvzxyw"
+TAB2 DS "aafghijklynoparstuvzxywqbcdefghijklynoparstuvzxywqbcdefghijklynoparstuvzxywqbcdefgXijklynoparstuvzxy"
+MSGTROUVE DS "TAB1 et TAB2 ont un élément en commun à l'index "
+MSGPASTROUVE DS "TAB1 et TAB2 n'ont pas d'élément en commun\n"
+ENDLINE DS "\n"
.TEXT
.START
- MOV R5, 101 ;R5 est le compteur
- MOV R1, TAB1 ;TAB1 est un tableau de 100 octets de type char
- MOV R2, TAB2 ;TAB2 est un tableau de 100 octets de type char
-BOUCLE: SUB R5 R5 1
- MOV R6, [R1]
- MOV R7, [R2] ;decrementation du compteur
- JE R6 R7 TROUVE ;test si TAB1[i]=TAB2[i] =>jmp trouvé
- ADD R1 R1 1 ;incrementation de R1 (element suivant du tableau TAB1)
- ADD R2 R1 1
- MOV R8, ZERO ;incrementation de R2 (element suivant du tableau TAB2)
- JNE R5 R8 BOUCLE ;si compteur !=0 on refait la boucle
- MOV, [0xffffff04], MSGPASTROUVE ;il n'y a pas de d'éléments identiques a une position i => on place dans R3 le msg a afficher
- JMP FIN ;jmp a l'affichage
-TROUVE: MOV, [0xffffff04], MSGTROUVE ;il y a une paire d'éléments identiques => on place dans R3 le msg a afficher
+ MOV R4, TAB2 ; R4 est la taille max
+ SUB R4, TAB1
+ MOV R5, R0 ; R5 est le compteur
+BOUCLE: MOV R6, TAB1[R5] ; on charge les lettres
+ MOV R7, TAB2[R5] ;
+ JE R6 R7 TROUVE ; test si TAB1[i]=TAB2[i] =>jmp trouvé
+ ADD R5, 1 ; incrémentation du compteur
+ JNE R5 R4 BOUCLE ; si compteur !=taille max on refait la boucle
+ MOV, [0xffffff04], MSGPASTROUVE ; il n'y a pas de d'éléments identiques a une position i => on place dans R3 le msg a afficher
+ JMP FIN ; jmp a l'affichage
+TROUVE: MOV, [0xffffff04], MSGTROUVE ; il y a une paire d'éléments identiques => on place dans R3 le msg a afficher
+ MOV, [0xffffff06], R5
+ MOV, [0xffffff04], ENDLINE
FIN: HALT
- RET 4
\ No newline at end of file
diff --git a/samples/sommeentiers.s b/samples/sommeentiers.s
index e8b6926..0580e77 100644
--- a/samples/sommeentiers.s
+++ b/samples/sommeentiers.s
@@ -1,28 +1,23 @@
;Ce programme va calculer la somme des 97 premiers entiers
.DATA
MSG DS "La somme des "
-MSG2 DS " premiers entiers est égale à"
-N DB 97
-ZERO DB 0
-SOMME DB 4
+MSG2 DS " premiers entiers est égale à "
+N DD 97
+MSG3 DS "\n"
.TEXT
.START
- MOV R5,[N] ;init du compteur
- MOV R1,0 ;init de R1
- MOV R2,0 ;init de R2
-
+ MOV R6,[N] ;init du compteur, R6 sera la taille totale
+ MOV R5,R0 ; R5 sera notre compteur
+ MOV R1,R0 ;init de R1, qui sera la somme totale
+
BOUCLE: ADD R1,R1,R5 ; R1=R1+R5
- AND R3,Fl,0x00000001 ;
- ADD R2,R2,R3 ; R2=R2+CF
- SUB R5,R5,1 ; DEC R5
- MOV R6,ZERO ;
- JNE R5,R6,BOUCLE ; si R5!=0 on refait la boucle
- MOV, [SOMME], R1 ; ;
- MOV, [SOMME+2], R2 ;on place la valeur de la somme
- MOV, [0xffffff04], MSG ;on affiche le msg et la somme
- MOV, [0xffffff06], SOMME ;
- MOV, [0xffffff06], SOMME+2 ;
+ ADD R5,R5,1 ; DEC R5
+ JNE R5,R6,BOUCLE ; si R5!=R6 (=N) on refait la boucle
+ MOV, [0xffffff04], MSG ; on affiche le msg et la somme
+ MOV, [0xffffff06], R6 ;
MOV, [0xffffff04], MSG2 ;
+ MOV, [0xffffff06], R1 ;
+ MOV, [0xffffff04], MSG3 ;
HALT ;