summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbiouman <>2001-05-19 23:54:39 +0000
committerbiouman <>2001-05-19 23:54:39 +0000
commit9d6740c3b6c83b3493ce2254ddb48a0995bd28b4 (patch)
treeab5ff90ebcc3d89a54f53d83492f798605bc8ab1
parent2d3e05c791bf5ee7443d64c5550915ce554e36cf (diff)
*** empty log message ***
-rw-r--r--include/interne.h17
-rw-r--r--lib/interne.c164
2 files changed, 136 insertions, 45 deletions
diff --git a/include/interne.h b/include/interne.h
index 801365b..337ec2d 100644
--- a/include/interne.h
+++ b/include/interne.h
@@ -14,4 +14,19 @@ Uint32 Extension(Uint32 ins);
Uint32 Champ1(Uint32 ins);
Uint32 Champ2(Uint32 ins);
Uint32 Champ3(Uint32 ins);
-#endif
+Uint32 ZERO(void);
+Uint32 ONE(void);
+void AffecteBit(Uint32 * a, char v, int position);
+int Neg(Uint32 a);
+char Not(char a);
+char And(char a, char b);
+char Or(char a, char b);
+char Xor(char a, char b);
+char Nand(char a, char b);
+char Nor(char a, char b);
+void SetOverflow(int * o);
+void ResetOverflow(int * o);
+int Overflow(int o);
+char OrWord(Uint32 a);
+char AndWord(Uint32 a);
+#endif \ No newline at end of file
diff --git a/lib/interne.c b/lib/interne.c
index 9e59944..642ce16 100644
--- a/lib/interne.c
+++ b/lib/interne.c
@@ -1,4 +1,5 @@
#include <stdio.h>
+#include <stdlib.h>
#include "interne.h"
#include "simulator.h"
#include "exceptions.h"
@@ -18,50 +19,6 @@ void Set(Uint32 * i)
*i &= 1;
} /* Ok */
-/* Met le bit 'position' à zéro */
-void ResetBit(Uint32 * i, int position)
-{
- if (position < 0 || position > 31) {
- exception(1, _("ResetBit: Incorrect Value"));
- } else {
- Uint32 aux = VAL_MAX - (1 << position);
-
- *i &= aux;
- }
-} /* Ok */
-
-/* Met le bit 'position' à un */
-void SetBit(Uint32 * i, int position)
-{
- if (position < 0 || position > 31) {
- exception(1, _("SetBit: Incorrect Value"));
- } else {
- Uint32 aux = 1 << position;
-
- *i |= aux;
- }
-} /* Ok */
-
-/* Donne la valeur du bit 'position' */
-int ValeurBit(Uint32 nombre, int position)
-{
- if (position < 0 || position > 31) {
- exception(1, _("ValeurBit: Incorrect Value"));
- return (-1);
- }
- return ((nombre >> position) & 1);
-} /* Ok */
-
-/* Affiche tous les bits d'un mot */
-void Uint32toBin(Uint32 i)
-{
- int k;
-
- for (k = 31; k >= 0; k--)
- printf("%d", ValeurBit(i, k));
- printf("\n");
-} /* Ok */
-
/* Extrait un champ dans un mot */
Uint32 champ(Uint32 nombre, int taille)
{
@@ -92,3 +49,122 @@ Uint32 Champ3(Uint32 ins)
{
return (champ(ins >> 26, 64));
} /* Ok */
+Uint32 ZERO(void) { return (0); }
+Uint32 ONE(void) { return (1); }
+
+/* Met le bit 'position' à zéro */
+void ResetBit(Uint32 * i, int position) {
+ if (position < 0 || position > 31)
+ exception(1, _("ResetBit: Incorrect Value"));
+ else {
+ int k;
+ Uint32 VAL_MAX = ZERO();
+ for (k = 0; k < 32; k++)
+ SetBit(&VAL_MAX, k);
+ * i &= VAL_MAX - (ONE() << position);
+ }
+}
+
+/* Met le bit 'position' à un */
+void SetBit(Uint32 * i, int position) {
+ if (position < 0 || position > 31)
+ exception(1, _("SetBit: Incorrect Value"));
+ else {
+ Uint32 aux = ONE() << position;
+ * i |= aux;
+ }
+}
+
+/* Met le bit 'position' à la meme valeur que 'v' */
+void AffecteBit(Uint32 * a, char v, int position) { (v == 0) ? ResetBit(&(* a), position) : SetBit(&(* a), position); }
+
+/* Donne la valeur du bit 'position' */
+int ValeurBit(Uint32 nombre, int position) {
+ if (position < 0 || position > 31) {
+ exception(1, _("ValeurBit: Incorrect Value"));
+ return (-1);
+ }
+ return ((nombre >> position) & ONE());
+}
+
+int Neg(Uint32 a) {
+ return (ValeurBit(a, 31));
+}
+
+/* Met le flag d'overflow à zéro */
+void SetOverflow(int * o) { * o = ONE(); }
+
+/* Met le flag d'overflow à un */
+void ResetOverflow(int * o) { * o = ZERO(); }
+
+/* Donne la valeur du flag d'overflow */
+int Overflow(int o) { return (o); }
+
+/* Affiche tous les bits d'un mot */
+void Uint32toBin(Uint32 i) {
+ int k;
+ for (k = 31; k >= 0; k--)
+ printf("%d", ValeurBit(i, k));
+ printf("\n");
+}
+
+/* Effectue le Not d'un bit */
+char Not(char a) { return ((char) ((a == 0) ? 1 : 0)); }
+
+/* Effectue le And de deux bits */
+char And(char a, char b) {
+ if (a == 0 && b == 0) return (0);
+ if (a == 0 && b == 1) return (0);
+ if (a == 1 && b == 0) return (0);
+ return (1);
+}
+
+/* Effectue le Or de deux bits */
+char Or(char a, char b) {
+ if (a == 0 && b == 0) return (0);
+ if (a == 0 && b == 1) return (1);
+ if (a == 1 && b == 0) return (1);
+ return (1);
+}
+
+/* Effectue le Xor de deux bits */
+char Xor(char a, char b) {
+ if (a == 0 && b == 0) return (0);
+ if (a == 0 && b == 1) return (1);
+ if (a == 1 && b == 0) return (1);
+ return (0);
+}
+
+/* Effectue le Nand de deux bits */
+char Nand(char a, char b) {
+ if (a == 0 && b == 0) return (1);
+ if (a == 0 && b == 1) return (1);
+ if (a == 1 && b == 0) return (1);
+ return (0);
+}
+
+/* Effectue le Nor de deux bits */
+char Nor(char a, char b) {
+ if (a == 0 && b == 0) return (1);
+ if (a == 0 && b == 1) return (0);
+ if (a == 1 && b == 0) return (0);
+ return (0);
+}
+
+char OrWord(Uint32 a) {
+ int i;
+ char resultat = (char) ValeurBit(a, 0);
+ for (i = 1; i < 32; i++)
+ resultat = Or((char) ValeurBit(a, i), resultat);
+ return (resultat);
+}
+
+char AndWord(Uint32 a) {
+ int i;
+ char resultat = (char) ValeurBit(a, 0);
+ for (i = 1; i < 32; i++)
+ resultat = And((char) ValeurBit(a, i), resultat);
+ return (resultat);
+}
+
+