#include #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 */ /* 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 */ Uint32 ZERO(void) { return (0); } Uint32 ONE(void) { return (1); } /* Met le bit 'position' à zéro */ void ResetBit(Uint32 * i, int position) { int k; Uint32 maxi = ZERO(); if (position < 0 || position > 31) exception(1, _("ResetBit: Incorrect Value")); else { for (k = 0; k < 32; k++) SetBit(&maxi, k); * i &= maxi - (ONE() << position); } } /* Met le bit 'position' à un */ void SetBit(Uint32 * i, int position) { Uint32 aux = ONE() << position; if (position < 0 || position > 31) exception(1, _("SetBit: Incorrect Value")); else { * 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)); } /* 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); }