From 62480cd55b67e10128b9a49821d94c3c5117830f Mon Sep 17 00:00:00 2001 From: biouman <> Date: Sun, 15 Apr 2001 02:12:11 +0000 Subject: mergeage de la branche simulateur avec la branche asm --- lib/interne.c | 94 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 lib/interne.c (limited to 'lib/interne.c') 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 +#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 */ -- cgit v1.2.3