Correctif merge
This commit is contained in:
parent
36996ae17f
commit
bc036e3c94
1 changed files with 42 additions and 8 deletions
|
@ -4,8 +4,11 @@
|
|||
|
||||
#define TAILLE_BUFFER_INSTRUCTIONS (1024)
|
||||
#define TAILLE_MEMOIRE (32)
|
||||
#define TAILLE_PILE_APPELS (16)
|
||||
#define TAILLE_BANC_REGISTRES (16)
|
||||
|
||||
#define SECURISED (1)
|
||||
|
||||
|
||||
/**************************************************/
|
||||
/**************************************************/
|
||||
|
@ -35,6 +38,12 @@ int mem[TAILLE_MEMOIRE];
|
|||
|
||||
// Pointeur de base dans la mémoire
|
||||
int ebp = 0;
|
||||
|
||||
// Memoire du programme
|
||||
int pile[TAILLE_PILE_APPELS];
|
||||
|
||||
// Pointeur de sommet dans la pile d'appel
|
||||
int esp = 0;
|
||||
|
||||
// Flag Z
|
||||
int Z = 0;
|
||||
|
@ -77,6 +86,15 @@ int check_registre(int registre) {
|
|||
return registre;
|
||||
}
|
||||
|
||||
// Verifie que les limites de la mémoire d'appels ne sont pas franchies
|
||||
int check_adresse_pile(int adresse) {
|
||||
if (adresse >= TAILLE_PILE_APPELS || adresse < 0) {
|
||||
printf("\033[31;01m ERROR : \033[00m Stack error\n");
|
||||
exit(2);
|
||||
}
|
||||
return adresse;
|
||||
}
|
||||
|
||||
// Verifie que eip ne depasse pas la taille du buffer
|
||||
int check_eip(int eip) {
|
||||
if (eip >= TAILLE_BUFFER_INSTRUCTIONS) {
|
||||
|
@ -208,16 +226,32 @@ void execute() {
|
|||
printf("%d@%d\n", registres[check_registre(programme[eip].param1)], programme[eip].param1);
|
||||
|
||||
} else if (programme[eip].instruction == CALL) {
|
||||
mem[check_adresse(ebp + programme[eip].param2)] = ebp;
|
||||
mem[check_adresse(ebp + programme[eip].param2 + 1)] = eip + 1;
|
||||
ebp = ebp + programme[eip].param2 + 2;
|
||||
eip = programme[eip].param1 - 1;
|
||||
if (SECURISED) {
|
||||
pile[check_adresse_pile(esp)] = ebp;
|
||||
esp++;
|
||||
pile[check_adresse_pile(esp)] = eip + 1;
|
||||
esp++;
|
||||
ebp = ebp + programme[eip].param2;
|
||||
eip = programme[eip].param1 - 1;
|
||||
} else {
|
||||
mem[check_adresse(ebp + programme[eip].param2)] = ebp;
|
||||
mem[check_adresse(ebp + programme[eip].param2 + 1)] = eip + 1;
|
||||
ebp = ebp + programme[eip].param2 + 2;
|
||||
eip = programme[eip].param1 - 1;
|
||||
}
|
||||
|
||||
} else if (programme[eip].instruction == RET) {
|
||||
int lastebp = ebp;
|
||||
eip = mem[check_adresse(ebp - 1)] - 1;
|
||||
ebp = mem[check_adresse(ebp - 2)];
|
||||
mem[check_adresse(lastebp - 2)] = mem[check_adresse(lastebp)];
|
||||
if (SECURISED) {
|
||||
esp--;
|
||||
eip = pile[check_adresse_pile(esp)] - 1;
|
||||
esp--;
|
||||
ebp = pile[check_adresse_pile(esp)];
|
||||
} else {
|
||||
int lastebp = ebp;
|
||||
eip = mem[check_adresse(ebp - 1)] - 1;
|
||||
ebp = mem[check_adresse(ebp - 2)];
|
||||
mem[check_adresse(lastebp - 2)] = mem[check_adresse(lastebp)];
|
||||
}
|
||||
|
||||
} else if (programme[eip].instruction == STOP) {
|
||||
if (programme[eip].param1 == 0) {
|
||||
|
|
Loading…
Reference in a new issue