-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmem.c
More file actions
53 lines (45 loc) · 1.03 KB
/
mem.c
File metadata and controls
53 lines (45 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include "mem.h"
#include <stdio.h>
#include <limits.h> // pour INT_MIN
#define CAPACITE_TAS 1000
int TAS[CAPACITE_TAS];
int ebp ; // bas du tas (relatif)
int nb_var_globales ;
int var_globales_init ;
void set_ebp(int value) {
ebp = value ;
}
int get_ebp() {
return ebp ;
}
void init_var_globales(int nb) {
if (var_globales_init == 0){
nb_var_globales = nb ;
var_globales_init = 1 ;
}
}
void mem_init() { int i;
for (i = 0; i < CAPACITE_TAS; i++) {
TAS[i] = INT_MIN;
}
set_ebp(0) ;
var_globales_init = 0 ;
}
int mem_set(int addr, int valeur)
{
if (addr >= nb_var_globales) { addr = addr + ebp ; }
if (addr < 0 || CAPACITE_TAS <= addr) {
printf("Segmentation fault : unable to access to address %d\n", addr);
return -1;
}
TAS[addr] = valeur;
return 0;
}
int mem_get(int addr) {
if (addr >= nb_var_globales) { addr = addr + ebp ; }
if (addr < 0 || CAPACITE_TAS <= addr) {
printf("Segmentation fault : unable to access to address %d\n", addr);
return -1;
}
return TAS[addr];
}