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
8e00a9e5
Commit
8e00a9e5
authored
Jun 10, 2020
by
sea19
Browse files
Started on input values for assembler
parent
097de796
Changes
5
Hide whitespace changes
Inline
Side-by-side
src/Makefile
View file @
8e00a9e5
CC
=
gcc
CFLAGS
=
-Wall
-g
-std
=
c99
-Werror
-pedantic
FILES
=
emulate.c fetch.c decode.c execute.c instrType.c
EMULATE
FILES
=
emulate.c fetch.c decode.c execute.c instrType.c
ASSEMBLEFILES
=
assemble.c readFile.c
#.PHONY: all clean
all
:
emulate.o fetch.o execute.o decode.o instrType.o
$(CC)
$(CFLAGS)
$(FILES)
-o
emulate
all
:
emulate assemble
emulate
:
emulate.o fetch.o decode.o execute.o instrType.o
$(CC)
$(CFLAGS)
$(EMULATEFILES)
-o
emulate
assemble
:
assemble.o readFile.o
$(CC)
$(CFLAGS)
$(ASSEMBLEFILES)
-o
assemble
clean
:
rm
-f
$(
wildcard
*
.o
)
...
...
src/assemble.c
View file @
8e00a9e5
#include <stdlib.h>
#include <stdio.h>
#include <assert.h>
#include "readFile.h"
#define MAX_SIZE_OF_STRING 50
int
main
(
int
argc
,
char
**
argv
)
{
assert
(
argc
==
3
);
int
length
=
getLengthOfFile
(
argv
[
1
]);
char
**
instruction
=
calloc
(
length
,
sizeof
(
char
*
));
if
(
!
instruction
)
{
perror
(
"Node allocation failed!"
);
exit
(
EXIT_FAILURE
);
}
for
(
int
i
=
0
;
i
<
length
;
i
++
)
{
instruction
[
i
]
=
calloc
(
MAX_SIZE_OF_STRING
,
sizeof
(
char
));
if
(
!
instruction
[
i
])
{
perror
(
"Node allocation failed!"
);
exit
(
EXIT_FAILURE
);
}
}
readSourceFile
(
argv
[
1
],
instruction
);
for
(
int
i
=
0
;
i
<
length
;
i
++
)
{
printf
(
"%s
\n
"
,
instruction
[
i
]);
}
free
(
instruction
);
for
(
int
i
=
0
;
i
<
length
;
i
++
)
{
free
(
instruction
[
i
]);
}
return
EXIT_SUCCESS
;
}
src/assemble.h
0 → 100644
View file @
8e00a9e5
src/readFile.c
0 → 100644
View file @
8e00a9e5
#include <stdio.h>
int
getLengthOfFile
(
char
*
fileName
)
{
FILE
*
ptr
=
fopen
(
fileName
,
"r"
);
int
size
=
0
;
char
c
=
getc
(
ptr
);
while
(
c
!=
EOF
)
{
if
(
c
==
'\n'
||
c
==
' '
)
{
size
++
;
}
c
=
getc
(
ptr
);
}
fclose
(
ptr
);
return
size
;
}
void
readSourceFile
(
char
*
fileName
,
char
**
instruction
)
{
int
i
=
0
;
FILE
*
ptr
=
fopen
(
fileName
,
"r"
);
while
(
!
feof
(
ptr
))
{
fscanf
(
ptr
,
"%s"
,
instruction
[
i
]);
i
++
;
}
fclose
(
ptr
);
//Closes file "filename"
}
src/readFile.h
0 → 100644
View file @
8e00a9e5
int
getLengthOfFile
(
char
*
fileName
);
void
readSourceFile
(
char
*
fileName
,
char
**
instruction
);
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