-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathRISCVfileReader.c
45 lines (36 loc) · 1.11 KB
/
RISCVfileReader.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
/* RISC-V binary file reader code file: */
#include "./include/RISCVfileReader.h"
void ReadText(char FileName[]){
/* Open text file: */
FILE *fp = fopen(FileName, "rb");
/* Verify if file was correctly open: */
if(fp == NULL){
printf("ERROR: Provided 'text' file does not exist.\n");
exit(0);
}
int32_t instr, i = 0;
/* Store content of binary file on memory until end of file or maximum memory for text is reached. */
while((!feof(fp)) && (i < 1024)){
fread(&instr, sizeof(int32_t), 1, fp);
mem[i] = instr;
i++;
}
fclose(fp);
}
void ReadData(char FileName[]){
/* Open data file: */
FILE *fp = fopen(FileName, "rb");
/* Verify if file was correctly open: */
if(fp == NULL){
printf("ERROR: Provided 'data' file does not exist.\n");
exit(0);
}
int32_t data, i = 2048;
/* Store content of binary file on memory until end of file or maximum memory is reached. */
while((!feof(fp)) && (i < 4096)){
fread(&data, sizeof(int32_t), 1, fp);
mem[i] = data;
i++;
}
fclose(fp);
}