diff options
author | Wojciech Kosior <kwojtus@protonmail.com> | 2020-12-29 19:52:00 +0100 |
---|---|---|
committer | Wojciech Kosior <kwojtus@protonmail.com> | 2020-12-29 19:52:00 +0100 |
commit | 5b6a3f3b216939a11ed1978d7da4dd6bbe4edc2a (patch) | |
tree | 597198cd0bf0df05df9b34ffef8a8681835cb825 | |
parent | 30a97274bde7a1988d80861ab9b381148f3d19a7 (diff) | |
download | AGH-engineering-thesis-5b6a3f3b216939a11ed1978d7da4dd6bbe4edc2a.tar.gz AGH-engineering-thesis-5b6a3f3b216939a11ed1978d7da4dd6bbe4edc2a.zip |
add a C program for translating binary files to format understood by Verilog
-rw-r--r-- | tools/Makefile | 2 | ||||
-rw-r--r-- | tools/Makefile.tools | 2 | ||||
-rw-r--r-- | tools/bin2hex.c | 26 |
3 files changed, 29 insertions, 1 deletions
diff --git a/tools/Makefile b/tools/Makefile index 8634a5c..a166da1 100644 --- a/tools/Makefile +++ b/tools/Makefile @@ -11,6 +11,8 @@ wasm_compile : wasm_compile.o assemble.o parse_module.o translate.o VGAdump2ppm : VGAdump2ppm.o +bin2hex : bin2hex.o + clean : rm *.o 2>/dev/null || true find . -executable -type f -delete diff --git a/tools/Makefile.tools b/tools/Makefile.tools index 5fc2b6c..19b265c 100644 --- a/tools/Makefile.tools +++ b/tools/Makefile.tools @@ -1,4 +1,4 @@ # This variable definition has been put here, because it is used by # toplevel Makefile as well as Makefile in tools/ -TOOLS = wasm_compile VGAdump2ppm +TOOLS = wasm_compile VGAdump2ppm bin2hex diff --git a/tools/bin2hex.c b/tools/bin2hex.c new file mode 100644 index 0000000..f4f2745 --- /dev/null +++ b/tools/bin2hex.c @@ -0,0 +1,26 @@ +#include <stdio.h> +#include <stdint.h> + +int main(int argc, char **argv) +{ + int input; + + while (1) { + input = getchar(); + + if (input == EOF) + break; + + printf("%02x", input); + + input = getchar(); + + /* If we have odd number of bytes, pad with a NULL-byte. */ + if (input == EOF) + input = 0; + + printf(" %02x\n", input); + } + + return 0; +} |