From 73838118922a8b247b97ac1acc83631ec4a00ea4 Mon Sep 17 00:00:00 2001 From: "(Tim) Efthimis Kritikos" Date: Wed, 14 Feb 2024 14:22:49 +0000 Subject: [PATCH] ASM: Added support for empty lines... ...and comments on those empty lines --- assembly.c | 14 +++++++++++++- main.c | 2 +- test.asm | 8 ++++++++ 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/assembly.c b/assembly.c index f6aead6..872cb06 100644 --- a/assembly.c +++ b/assembly.c @@ -261,8 +261,11 @@ int64_t parse_immediate(char* str,struct assembler_context_t *assembler_context) int64_t assemble_line(char *line, struct assembler_context_t *assembler_context){ uint16_t opcode; - int x; + int x=0; int call; + while(line[x]==' ')x++; + if(line[x]==0||line[x]=='#') + return -1;//empty line or comment if( ((call=strncmp(line,"JMP ",4))==0) || (strncmp(line,"CALL ",5)==0) ){ if(call){ x=4; @@ -560,6 +563,7 @@ int64_t assemble_line(char *line, struct assembler_context_t *assembler_context) } int assembler_context_process(char* line,struct assembler_context_t *assembler_context){ + int x=0; switch(line[0]){ case ':': if(line[1]==0) @@ -579,6 +583,14 @@ int assembler_context_process(char* line,struct assembler_context_t *assembler_c break; case 0: return 0; + case ' ': + while(line[x]==' ')x++; + if(line[x]==0) + return 0; + else + return 1; + case '#': + return 0; default: assembler_context->current_location+=4; diff --git a/main.c b/main.c index ae6bcda..4819bcb 100644 --- a/main.c +++ b/main.c @@ -130,7 +130,7 @@ int main(int argc, char* argd[] ){ if(opcode==-3) printf("Error label not found %s:%d\n", infile,linec+1); else - printf("Error assembling (0x%lx)%s:%d\n",(uint64_t)opcode, infile,linec+1); + printf("Error assembling %s:%d\n", infile,linec+1); fclose(rom); free_assembler_context(assembler_context); free_simdata(simdata); diff --git a/test.asm b/test.asm index 9ecbe6c..bbf80dd 100644 --- a/test.asm +++ b/test.asm @@ -1,4 +1,6 @@ MOV $FF0000,%SP + +#Test verious instructions MOV $0x0001,%R0l MOV $0x0000,%R0h MOV $0xBEEF,%R1l @@ -17,6 +19,8 @@ RET ADD %R0,%R1 RET :END + +#Test text terminal MOV $0xFFFC,%R0l MOV $0x00FF,%R0h MOV $0x0068,%R1l @@ -30,6 +34,8 @@ MOV $0x006c,%R1l MOV %R1,(%R0) MOV $0x006f,%R1l MOV %R1,(%R0) + +# Test Vector Display MOV $0xFFFF,%R1l MOV $0xFFFF,%R1h MOV %R1,(%R0) @@ -45,6 +51,8 @@ MOV %R1,(%R0) MOV $0xcccd,%R1l MOV $0x3f4c,%R1h MOV %R1,(%R0) + +#Test Indirect read/writes MOV $0xcccd,%R1l MOV $0x3f4c,%R1h MOV %R1,(%R0)