added example && changed flags

This commit is contained in:
Igor Malovitsa 2024-03-04 22:30:03 +02:00
parent 376117ace5
commit 4fa350a094
3 changed files with 22 additions and 7 deletions

View file

@ -8,7 +8,7 @@ hbas: hbas.c
${CC} ${CFLAGS} ${CFLAGS_EXTRA} hbas.c -o hbas ${CC} ${CFLAGS} ${CFLAGS_EXTRA} hbas.c -o hbas
example: hbas example.S example: hbas example.S
./hbas --bin < example.S > example ./hbas < example.S > example
xxd example xxd example
clean: clean:

15
README.md Normal file
View file

@ -0,0 +1,15 @@
# Holey-bytes VM playground
This is my take on holey bytes toolchain, currently only an assembler written in C.
## Building
Run `make`, or `make CC=<your preferred C compiler> CFLAGS_EXTRA=<more flags>`
## Usage
To run the assembler, feed the input file to stdin, and the output will be in stdout.
```
./hbas --hex < input.S > output.hex
./hbas < input.S > output.bin
```

12
hbas.c
View file

@ -821,9 +821,9 @@ AsmError assemble(InstHt ht, char *input, size_t len, ByteVec *out, EInfo *einfo
} }
int main(int argc, char **argv) { int main(int argc, char **argv) {
int binout = 0; int hex_out = 0;
if (argc >= 2 && strcmp(argv[1], "--bin") == 0) { if (argc >= 2 && strcmp(argv[1], "--hex") == 0) {
binout = 1; hex_out = 1;
} }
int err = 0; int err = 0;
@ -854,10 +854,10 @@ int main(int argc, char **argv) {
fprintf(stderr, "\n"); fprintf(stderr, "\n");
goto done; goto done;
} }
if (binout) { if (hex_out) {
fwrite(out.buf, 1, out.len, stdout);
} else {
hd(out.buf, out.len); hd(out.buf, out.len);
} else {
fwrite(out.buf, 1, out.len, stdout);
} }
done: done: