ASM: Added support for empty lines... ...and comments on those empty lines
This commit is contained in:
parent
35588a07c8
commit
7383811892
14
assembly.c
14
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){
|
int64_t assemble_line(char *line, struct assembler_context_t *assembler_context){
|
||||||
uint16_t opcode;
|
uint16_t opcode;
|
||||||
int x;
|
int x=0;
|
||||||
int call;
|
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=strncmp(line,"JMP ",4))==0) || (strncmp(line,"CALL ",5)==0) ){
|
||||||
if(call){
|
if(call){
|
||||||
x=4;
|
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 assembler_context_process(char* line,struct assembler_context_t *assembler_context){
|
||||||
|
int x=0;
|
||||||
switch(line[0]){
|
switch(line[0]){
|
||||||
case ':':
|
case ':':
|
||||||
if(line[1]==0)
|
if(line[1]==0)
|
||||||
@ -579,6 +583,14 @@ int assembler_context_process(char* line,struct assembler_context_t *assembler_c
|
|||||||
break;
|
break;
|
||||||
case 0:
|
case 0:
|
||||||
return 0;
|
return 0;
|
||||||
|
case ' ':
|
||||||
|
while(line[x]==' ')x++;
|
||||||
|
if(line[x]==0)
|
||||||
|
return 0;
|
||||||
|
else
|
||||||
|
return 1;
|
||||||
|
case '#':
|
||||||
|
return 0;
|
||||||
default:
|
default:
|
||||||
assembler_context->current_location+=4;
|
assembler_context->current_location+=4;
|
||||||
|
|
||||||
|
2
main.c
2
main.c
@ -130,7 +130,7 @@ int main(int argc, char* argd[] ){
|
|||||||
if(opcode==-3)
|
if(opcode==-3)
|
||||||
printf("Error label not found %s:%d\n", infile,linec+1);
|
printf("Error label not found %s:%d\n", infile,linec+1);
|
||||||
else
|
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);
|
fclose(rom);
|
||||||
free_assembler_context(assembler_context);
|
free_assembler_context(assembler_context);
|
||||||
free_simdata(simdata);
|
free_simdata(simdata);
|
||||||
|
8
test.asm
8
test.asm
@ -1,4 +1,6 @@
|
|||||||
MOV $FF0000,%SP
|
MOV $FF0000,%SP
|
||||||
|
|
||||||
|
#Test verious instructions
|
||||||
MOV $0x0001,%R0l
|
MOV $0x0001,%R0l
|
||||||
MOV $0x0000,%R0h
|
MOV $0x0000,%R0h
|
||||||
MOV $0xBEEF,%R1l
|
MOV $0xBEEF,%R1l
|
||||||
@ -17,6 +19,8 @@ RET
|
|||||||
ADD %R0,%R1
|
ADD %R0,%R1
|
||||||
RET
|
RET
|
||||||
:END
|
:END
|
||||||
|
|
||||||
|
#Test text terminal
|
||||||
MOV $0xFFFC,%R0l
|
MOV $0xFFFC,%R0l
|
||||||
MOV $0x00FF,%R0h
|
MOV $0x00FF,%R0h
|
||||||
MOV $0x0068,%R1l
|
MOV $0x0068,%R1l
|
||||||
@ -30,6 +34,8 @@ MOV $0x006c,%R1l
|
|||||||
MOV %R1,(%R0)
|
MOV %R1,(%R0)
|
||||||
MOV $0x006f,%R1l
|
MOV $0x006f,%R1l
|
||||||
MOV %R1,(%R0)
|
MOV %R1,(%R0)
|
||||||
|
|
||||||
|
# Test Vector Display
|
||||||
MOV $0xFFFF,%R1l
|
MOV $0xFFFF,%R1l
|
||||||
MOV $0xFFFF,%R1h
|
MOV $0xFFFF,%R1h
|
||||||
MOV %R1,(%R0)
|
MOV %R1,(%R0)
|
||||||
@ -45,6 +51,8 @@ MOV %R1,(%R0)
|
|||||||
MOV $0xcccd,%R1l
|
MOV $0xcccd,%R1l
|
||||||
MOV $0x3f4c,%R1h
|
MOV $0x3f4c,%R1h
|
||||||
MOV %R1,(%R0)
|
MOV %R1,(%R0)
|
||||||
|
|
||||||
|
#Test Indirect read/writes
|
||||||
MOV $0xcccd,%R1l
|
MOV $0xcccd,%R1l
|
||||||
MOV $0x3f4c,%R1h
|
MOV $0x3f4c,%R1h
|
||||||
MOV %R1,(%R0)
|
MOV %R1,(%R0)
|
||||||
|
Loading…
Reference in New Issue
Block a user