summaryrefslogtreecommitdiff
path: root/lib/interne.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/interne.c')
-rw-r--r--lib/interne.c94
1 files changed, 94 insertions, 0 deletions
diff --git a/lib/interne.c b/lib/interne.c
new file mode 100644
index 0000000..bdab97e
--- /dev/null
+++ b/lib/interne.c
@@ -0,0 +1,94 @@
+#include <stdio.h>
+#include "interne.h"
+#include "archi.h"
+
+// mettre des exceptions dans les fcns ci dessous a la place de GestionErreurs
+
+void GestionErreurs(void)
+{
+}
+
+void Reset(Uint32 * i)
+{ /* met tous les bits d'un mot à zéro */
+ *i &= 0;
+} /* Ok */
+
+void Set(Uint32 * i)
+{ /* met le bit de poids faible à 1 */
+ *i &= 1;
+} /* Ok */
+
+/* Met le bit 'position' à zéro */
+void ResetBit(Uint32 * i, int position)
+{
+ if (position < 0 || position > 31) {
+ GestionErreurs();
+ } 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) {
+ GestionErreurs();
+ } 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) {
+ GestionErreurs();
+ 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)
+{
+ return (nombre & (taille - 1));
+} /* Ok */
+
+Uint32 Opcode(Uint32 ins)
+{
+ return (champ(ins >> 0, 256));
+} /* Ok */
+
+Uint32 Extension(Uint32 ins)
+{
+ return (champ(ins >> 8, 64));
+} /* Ok */
+
+Uint32 Champ1(Uint32 ins)
+{
+ return (champ(ins >> 14, 64));
+} /* Ok */
+
+Uint32 Champ2(Uint32 ins)
+{
+ return (champ(ins >> 20, 64));
+} /* Ok */
+
+Uint32 Champ3(Uint32 ins)
+{
+ return (champ(ins >> 26, 64));
+} /* Ok */