#include instruction

This commit is contained in:
KikooDX 2021-08-20 11:48:56 +02:00
parent 9be38429ff
commit 1af6ffc015
4 changed files with 41 additions and 15 deletions

View File

@ -1,3 +1,4 @@
#include
NOP
MOV
ADD

38
bcasm.c
View File

@ -3,22 +3,31 @@
#include <string.h>
#include <assert.h>
static void parse(char *path);
static char* get_op(int id);
static char* get_long_op(int id);
static char* get_value(int id);
static int counter = 0; /* line number */
int
main(int argc, char **argv)
{
assert(argc == 2);
parse(argv[1]);
return EXIT_SUCCESS;
}
static void
parse(char *path)
{
FILE *fp;
char line[256];
char *token = NULL;
char *op1, *op2;
assert(argc == 2);
fp = fopen(argv[1], "r");
fp = fopen(path, "r");
assert(fp != NULL);
while (fgets(line, sizeof(line), fp) != NULL)
@ -113,16 +122,19 @@ main(int argc, char **argv)
{
printf("Locate X,Y,Ans\n");
}
else if (strcmp(token, "#include") == 0)
{
op1 = get_long_op(1);
parse(op1);
}
else
{
fprintf(stderr, "line %d: unknown token '%s'\n", counter, token);
return EXIT_FAILURE;
exit(EXIT_FAILURE);
}
}
fclose(fp);
return EXIT_SUCCESS;
}
static char*
@ -131,7 +143,19 @@ get_op(int id)
char *op = strtok(NULL, "\n\t\r, ");
if (op == NULL)
{
fprintf(stderr, "line %d: missing operand %d\n", counter, id);
fprintf(stderr, "line %d: missing op %d\n", counter, id);
exit(EXIT_FAILURE);
}
return op;
}
static char*
get_long_op(int id)
{
char *op = strtok(NULL, "\"");
if (op == NULL)
{
fprintf(stderr, "line %d: missing long op %d\n", counter, id);
exit(EXIT_FAILURE);
}
return op;

View File

@ -8,14 +8,7 @@ MOV 0 ANS
LBL A
; display score
LOC
; wait for release
LBL R
MOV GTK ANS
JEZ R
; wait for press
LBL P
MOV GTK ANS
JNZ P
#include "waitkey.asm"
; increase score
MOV S ANS
ADD 1

8
examples/waitkey.asm Normal file
View File

@ -0,0 +1,8 @@
;wait for release
LBL R
MOV GTK ANS
JEZ R
;wait for press
LBL P
MOV GTK ANS
JNZ P