#include #include "interne.h" #include "simulator.h" #include "exceptions.h" #ifdef HAVE_CONFIG_H #include "config.h" #else #define _(x) x #endif 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) { 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) { 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 */