-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathnewmain.c
105 lines (83 loc) · 2.46 KB
/
newmain.c
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/******************************************************************************
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 text = 0 , data = 0 , bss = 0 , fd = 0 ;
unsigned char value = '4' ; // 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" , &text, &data, &bss ) ;
//srand ( seed ) ;
text = 20;
data = 22;
bss = 22;
//total 64 pages -> 2048 bytes.
/* initiating the virtual memory */
vir_mem = vm_constructor( file, text, data, bss ) ;
vm_print(vir_mem);
//int address[] = {204, 3000, 2500, 4000, 150, 1000, 550, 3159, 2941, 5021};
for ( counter = 0 ; counter < ACCESS ; counter++ )
{
int s ;
//addr = address[counter] ; //rand();
printf("Choose address to LOAD:\n");
scanf("%hd", &addr);
/*** DEBUG ***/
if(addr == 5000)
break;
else if(addr == 5001) {
printRAM();
continue;
}
else if(addr == 5002)
continue;
/************/
if ( ( s = vm_load( vir_mem, addr, &value ) ) == MISS )
miss++ ;
else if ( s == HIT )
hit++ ;
//addr = rand () ;
printf("Choose address to STORE:\n");
scanf("%hd", &addr);
/*** DEBUG ***/
if(addr == 5000)
break;
else if(addr == 5001) {
printRAM();
continue;
}
else if(addr == 5002)
continue;
/************/
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 ) ;
}
/******************************************************************************
******************************************************************************/