ASM: Added support for empty lines... ...and comments on those empty lines

This commit is contained in:
(Tim) Efthimis Kritikos 2024-02-14 14:22:49 +00:00
parent 35588a07c8
commit 7383811892
3 changed files with 22 additions and 2 deletions

View File

@ -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;

2
main.c
View File

@ -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);

View File

@ -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)