-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMAIN.c
More file actions
executable file
·68 lines (54 loc) · 1.8 KB
/
MAIN.c
File metadata and controls
executable file
·68 lines (54 loc) · 1.8 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/******************************************************************************
File : main.c
Description : testing the vm module
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <errno.h>
#include <malloc.h>
#include "mem_sim.h"
#define ACCESS 2000
#define MISS -1
#define HIT 0
/******************************************************************************
Function main :
******************************************************************************/
int main ()
{
char file[ 30 ] = "program_file" ;
int seed = 0 , text = 0 , data = 0 , bss = 0 , fd = 0 ;
unsigned char value = 4 ;
unsigned counter = 0 ;
unsigned short addr = 0 ;
int miss = 0, hit = 0 ;
sim_database_t* vir_mem ;
/* random number generator */
scanf ( "%d %d %d %d" , &seed, &text, &data, &bss ) ;
srand ( seed ) ;
/* initiating the virtual memory */
vir_mem = vm_constructor( file, text, data, bss ) ;
vm_print(vir_mem);
for ( counter = 0 ; counter < ACCESS ; counter++ )
{
int s ;
addr = rand () ;
if ( ( s = vm_load( vir_mem, addr, &value ) ) == MISS )
miss++ ;
else if ( s == HIT )
hit++ ;
addr = rand () ;
if ( ( s = vm_store( vir_mem, addr, value ) ) == MISS )
miss++ ;
else if ( s == HIT )
hit++ ;
}
vm_print(vir_mem);
vm_destructor ( vir_mem ) ;
return ( 0 ) ;
}
/******************************************************************************
******************************************************************************/