Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
Computer_architecture_project2
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
lang0909
Computer_architecture_project2
Commits
7685850a
Commit
7685850a
authored
5 years ago
by
lang0909
Browse files
Options
Downloads
Patches
Plain Diff
Add sce212sim.c
parent
07082b9d
Branches
Branches containing commit
No related tags found
No related merge requests found
Pipeline
#2191
canceled
5 years ago
Stage: build
Stage: test
Changes
1
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
sce212sim.c
+186
-0
186 additions, 0 deletions
sce212sim.c
with
186 additions
and
0 deletions
sce212sim.c
0 → 100644
+
186
−
0
View file @
7685850a
/***************************************************************/
/* */
/* MIPS-32 Instruction Level Simulator */
/* */
/* SCE212 Ajou University */
/* sce212.c */
/* Adapted from CS311@KAIST */
/* */
/***************************************************************/
/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
/* DO NOT MODIFY THIS FILE! */
/* You should only the parse.c and run.c files! */
/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
#include
<assert.h>
#include
<stdio.h>
#include
<stdlib.h>
#include
<string.h>
#include
<stdint.h>
#include
"util.h"
#include
"parse.h"
#include
"run.h"
/**************************************************************/
/* */
/* Procedure : load_program */
/* */
/* Purpose : Load program and service routines into mem. */
/* */
/**************************************************************/
void
load_program
(
char
*
program_filename
)
{
FILE
*
prog
;
int
ii
,
word
;
char
buffer
[
33
];
//to notifying data & text segment size
int
flag
=
0
;
int
text_index
=
0
;
int
data_index
=
0
;
/* Open program file. */
prog
=
fopen
(
program_filename
,
"r"
);
if
(
prog
==
NULL
)
{
printf
(
"Error: Can't open program file %s
\n
"
,
program_filename
);
exit
(
-
1
);
}
/* Read in the program. */
ii
=
0
;
//read 32bits + '\0' = 33
while
(
fgets
(
buffer
,
33
,
prog
)
!=
NULL
)
{
if
(
flag
==
0
)
{
//check text segment size
text_size
=
fromBinary
(
buffer
);
NUM_INST
=
text_size
/
4
;
//initial memory allocation of text segment
INST_INFO
=
malloc
(
sizeof
(
instruction
)
*
(
text_size
/
4
));
init_inst_info
(
text_size
/
4
);
}
else
if
(
flag
==
1
)
{
//check data segment size
data_size
=
fromBinary
(
buffer
);
//initial memory allocation of data segment
//if you would like to add data, you can re-allocate memory.
/* data_seg = malloc(sizeof(uint32_t)*(data_size/4)); */
}
else
{
if
(
ii
<
text_size
)
{
INST_INFO
[
text_index
++
]
=
parsing_instr
(
buffer
,
ii
);
}
else
if
(
ii
<
text_size
+
data_size
)
{
parsing_data
(
buffer
,
ii
-
text_size
);
}
else
{
//Do not enter this case
//assert(0);
//However, there is a newline in the input file
}
ii
+=
4
;
}
flag
++
;
}
CURRENT_STATE
.
PC
=
MEM_TEXT_START
;
//printf("Read %d words from program into memory.\n\n", ii/4);
}
/************************************************************/
/* */
/* Procedure : initialize */
/* */
/* Purpose : Load machine language program */
/* and set up initial state of the machine. */
/* */
/************************************************************/
void
initialize
(
char
*
program_filename
)
{
int
i
;
init_memory
();
load_program
(
program_filename
);
RUN_BIT
=
TRUE
;
}
/***************************************************************/
/* */
/* Procedure : main */
/* */
/***************************************************************/
int
main
(
int
argc
,
char
*
argv
[])
{
char
**
tokens
;
int
count
=
1
;
int
addr1
=
0
;
int
addr2
=
0
;
int
num_inst
=
0
;
int
i
=
100
;
//for loop
int
mem_dump_set
=
0
;
int
debug_set
=
0
;
int
num_inst_set
=
0
;
/* Error Checking */
if
(
argc
<
2
)
{
printf
(
"Error: usage: %s [-m addr1:addr2] [-d] [-n num_instr] inputBinary
\n
"
,
argv
[
0
]);
exit
(
1
);
}
initialize
(
argv
[
argc
-
1
]);
//for checking parse result
//print_parse_result();
while
(
count
!=
argc
-
1
)
{
if
(
strcmp
(
argv
[
count
],
"-m"
)
==
0
)
{
tokens
=
str_split
(
argv
[
++
count
],
':'
);
addr1
=
(
int
)
strtol
(
*
(
tokens
),
NULL
,
16
);
addr2
=
(
int
)
strtol
(
*
(
tokens
+
1
),
NULL
,
16
);
mem_dump_set
=
1
;
}
else
if
(
strcmp
(
argv
[
count
],
"-d"
)
==
0
)
{
debug_set
=
1
;
}
else
if
(
strcmp
(
argv
[
count
],
"-n"
)
==
0
)
{
num_inst
=
(
int
)
strtol
(
argv
[
++
count
],
NULL
,
10
);
num_inst_set
=
1
;
}
else
{
printf
(
"Error: usage: %s [-m addr1:addr2] [-d] [-n num_instr] inputBinary
\n
"
,
argv
[
0
]);
exit
(
1
);
}
count
++
;
}
if
(
num_inst_set
)
{
i
=
num_inst
;
}
if
(
debug_set
)
{
printf
(
"Simulating for %d cycles...
\n\n
"
,
i
);
for
(;
i
>
0
;
i
--
){
cycle
();
rdump
();
if
(
mem_dump_set
)
{
mdump
(
addr1
,
addr2
);
}
}
}
else
{
run
(
i
);
rdump
();
if
(
mem_dump_set
)
{
mdump
(
addr1
,
addr2
);
}
}
return
0
;
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment