Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Shen, Siran
arm11_
Commits
de38530f
Commit
de38530f
authored
May 29, 2020
by
sea19
Browse files
Fetch completed, decode started
parent
4394b373
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/emulate.c
View file @
de38530f
...
...
@@ -20,25 +20,90 @@ int *readFile(char *filename) {
}
int
fetch
(
int
*
objectcode
,
int
programCounter
)
{
return
objectcode
[
programCounter
];
return
objectcode
[
programCounter
];
//Returns an instruction at the value of programCounter
}
void
initialiseRegisters
(
int
*
registers
)
{
for
(
int
i
=
0
;
i
<
17
;
i
++
)
{
registers
[
i
]
=
0
;
registers
[
i
]
=
0
;
//Sets all the registers to 0
}
}
/*void decode(int instruction, int programcounter) { //Decode started but not working yet
enum instrSet{dataProcess, mul, singleData, branch};
enum instrSet instrType;
if ((2^27 + 2^26) & instruction == 0) {
instrType = dataProcess;
}
switch (instrType) {
case dataProcess:
decodeDataProcess(instruction, programcounter);
break;
}
}/*
/*void decodeDataProcess(int instruction, int pc, char* decodedData) {
int opcode = ((2^24 + 2^23 + 2^22 + 2^21) & instruction) / (2^21)
switch (opcode) {
case 0:
break;
case 1:
break;
case 2:
break;
case 3:
break;
case 4:
break;
case 8:
break;
case 9:
break;
case 10:
break;
case 12:
break;
case 13:
break;
}
}*/
void
startCycle
(
int
*
objectcode
,
int
*
registers
)
{
int
pc
=
registers
[
15
];
//pc takes the value of the program counter
if
(
pc
==
0
)
{
fetch
(
objectcode
,
pc
);
pc
=
pc
+
4
;
}
else
if
(
pc
==
4
)
{
fetch
(
objectcode
,
pc
/
4
);
decode
(
objectcode
,
(
pc
/
4
-
1
));
pc
=
pc
+
4
;
}
else
{
fetch
(
objectcode
,
pc
/
4
);
decode
(
objectcode
,
(
pc
/
4
-
1
));
execute
(
objectcode
,
(
pc
/
4
-
2
));
pc
=
pc
+
4
;
}
}
int
main
(
int
argc
,
char
**
argv
)
{
int
registers
[
17
];
int
*
objectcode
;
char
*
decodedData
;
bool
halt
;
assert
(
argc
==
2
);
initialiseRegisters
(
&
registers
[
0
]);
objectcode
=
readFile
(
argv
[
1
]);
while
(
!
halt
)
{
startCycle
(
objectCode
,
&
registers
[
0
]);
}
printf
(
"%d
\n
"
,
fetch
(
objectcode
,
0
));
free
(
objectcode
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment