summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/alu.c91
-rw-r--r--lib/meta.c12
-rw-r--r--lib/simulator.c7
3 files changed, 51 insertions, 59 deletions
diff --git a/lib/alu.c b/lib/alu.c
index 0adac7d..a23494e 100644
--- a/lib/alu.c
+++ b/lib/alu.c
@@ -15,34 +15,36 @@ Uint32 SecondResult = 0;
/* ALU rapide */
-Uint32 RNot(Uint32 a) {
+Uint32 RNot(Uint32 a)
+{
return (~a) + 1;
}
Uint32 RAdditionNonSigne(Uint32 a, Uint32 b)
{
unsigned long long tr = a, masq = 1;
+
tr += b;
-
+
masq <<= 32;
if (masq & tr) {
SetOverflow();
} else {
ResetOverflow();
}
-
+
if (tr) {
ResetZero();
} else {
SetZero();
}
-
+
if (tr & 1) {
SetParity();
} else {
ResetParity();
}
-
+
ResetSign();
return tr;
}
@@ -50,6 +52,7 @@ Uint32 RAdditionNonSigne(Uint32 a, Uint32 b)
Uint32 RAdditionSigne(long int a, long int b)
{
long int tr = a;
+
tr += b;
if (((a & 0x80000000) && (b & 0x80000000) && !(tr & 0x80000000)) ||
@@ -58,19 +61,19 @@ Uint32 RAdditionSigne(long int a, long int b)
} else {
ResetOverflow();
}
-
+
if (tr) {
ResetZero();
} else {
SetZero();
}
-
+
if (tr & 1) {
SetParity();
} else {
ResetParity();
}
-
+
if (tr & 0x80000000) {
SetSign();
} else {
@@ -159,7 +162,7 @@ Uint32 RDivisionNonSigne(Uint32 a, Uint32 b)
Uint32 RDivisionSigne(long int a, long int b)
{
long long temp = a;
-
+
temp /= b;
if (temp & 1) {
SetParity();
@@ -819,63 +822,50 @@ couple MultipliSig(Uint32 x, Uint32 y)
Uint32 NDivisionNonSigne(Uint32 a, Uint32 b)
{
Uint32 quot, rest;
- if (b>a)
- {
- quot=0;
- rest=a;
- }
- else
- {
- if (b==a)
- {
- quot=1;
- rest=0;
- }
- else
- {
- quot=0;
- rest=a;
- while (rest>=b)
- {
- rest=NSoustractionNonSigne(rest,b);
+
+ if (b > a) {
+ quot = 0;
+ rest = a;
+ } else {
+ if (b == a) {
+ quot = 1;
+ rest = 0;
+ } else {
+ quot = 0;
+ rest = a;
+ while (rest >= b) {
+ rest = NSoustractionNonSigne(rest, b);
quot++;
}
}
}
SecondResult = rest;
return quot;
-}
+}
Uint32 NDivisionSigne(long int a, long int b)
{
long int quot, rest;
-
- if (b>a)
- {
- quot=0;
- rest=a;
- }
- else
- {
- if (b==a)
- {
- quot=1;
- rest=0;
- }
- else
- {
- quot=0;
- rest=a;
- while (rest>=b)
- {
- rest=NSoustractionNonSigne(rest,b);
+
+ if (b > a) {
+ quot = 0;
+ rest = a;
+ } else {
+ if (b == a) {
+ quot = 1;
+ rest = 0;
+ } else {
+ quot = 0;
+ rest = a;
+ while (rest >= b) {
+ rest = NSoustractionNonSigne(rest, b);
quot++;
}
}
}
SecondResult = rest;
return quot;
-}
+}
Uint32 NMultiplicationNonSigne(Uint32 a, Uint32 b)
{
@@ -1004,4 +994,3 @@ Uint32 SHR(Uint32 a)
return NSHR(a);
}
}
-
diff --git a/lib/meta.c b/lib/meta.c
index 6a50ecf..be13434 100644
--- a/lib/meta.c
+++ b/lib/meta.c
@@ -579,20 +579,20 @@ void main(void)
fprintf(stderr, " + %s (%s) type: %s\n",
pattern->expr[i]->name ? pattern->expr[i]->name : "Opérateur [",
pattern->expr[i]->string ? pattern->expr[i]->string : "Aucune chaîne associée",
- pattern->expr[i]->type ? "Constante prédéfinie" : pattern->
- expr[i]->left ? "Binaire" : pattern->expr[i]->right ? "Unaire" : "Feuille");
+ pattern->expr[i]->type ? "Constante prédéfinie" : pattern->expr[i]->
+ left ? "Binaire" : pattern->expr[i]->right ? "Unaire" : "Feuille");
if (pattern->expr[i]->left) {
fprintf(stderr, " - gauche: %s (%s) type: %s\n",
pattern->expr[i]->left->name ? pattern->expr[i]->left->name : "Opérateur [",
- pattern->expr[i]->left->string ? pattern->expr[i]->
- left->string : "Aucune chaîne associée",
+ pattern->expr[i]->left->string ? pattern->expr[i]->left->
+ string : "Aucune chaîne associée",
pattern->expr[i]->left->type ? "Constante prédéfinie" : "Feuille");
}
if (pattern->expr[i]->right) {
fprintf(stderr, " - droite: %s (%s) type: %s\n",
pattern->expr[i]->right->name ? pattern->expr[i]->right->name : "Opérateur [",
- pattern->expr[i]->right->string ? pattern->expr[i]->
- right->string : "Aucune chaîne associée",
+ pattern->expr[i]->right->string ? pattern->expr[i]->right->
+ string : "Aucune chaîne associée",
pattern->expr[i]->right->type ? "Constante prédéfinie" : "Feuille");
}
}
diff --git a/lib/simulator.c b/lib/simulator.c
index 729e379..380c705 100644
--- a/lib/simulator.c
+++ b/lib/simulator.c
@@ -26,6 +26,7 @@ Uint32 LireInstruction(void)
void IncrementeCompteurOrdinal(void)
{
Uint32 of = LireRegistreFLAG();
+
EcrireRegistrePC(AdditionNonSigne(LireRegistrePC(), 1));
EcrireRegistreFLAG(of);
}
@@ -90,7 +91,8 @@ void Initialisation(void)
EcrireRegistreSP(ADD_SP); /* initialisation du stack pointer */
}
-void Flush(void) {
+void Flush(void)
+{
FlushMemoire();
}
@@ -415,7 +417,8 @@ void Debogueur(void)
fprintf(stderr, "Opcode: %02X, extension: %02X, champ1: %02X, champ2: %02X, champ3: %02X\n",
Opcode(instruction), Extension(instruction), Champ1(instruction), Champ2(instruction),
Champ3(instruction));
- fprintf(stderr, "%08lX:%08lX - %08lX - %08lX > ", LireRegistrePC(), instruction, LD(LireRegistrePC() + 1), LD(LireRegistrePC() + 2));
+ fprintf(stderr, "%08lX:%08lX - %08lX - %08lX > ", LireRegistrePC(), instruction,
+ LD(LireRegistrePC() + 1), LD(LireRegistrePC() + 2));
switch (fgetc(input)) {
case 'G':