ASM: Fixed potential bug in the assembler's parser

This commit is contained in:
(Tim) Efthimis Kritikos 2024-02-14 02:50:51 +00:00
parent 79577d7b4e
commit d8c50156a8

View File

@ -263,7 +263,7 @@ uint32_t assemble_line(char *line, struct assembler_context_t *assembler_context
uint16_t opcode;
int x;
int call;
if( ((call=strncmp(line,"JMP",3))==0) || (strncmp(line,"CALL",4)==0) ){
if( ((call=strncmp(line,"JMP ",4))==0) || (strncmp(line,"CALL ",5)==0) ){
if(call){
x=4;
opcode=0x10;
@ -312,23 +312,23 @@ uint32_t assemble_line(char *line, struct assembler_context_t *assembler_context
return 0xFFFFFFFF;
}else{
uint8_t r1,r0,params;
if(strncmp(line,"ADD",3)==0){
if(strncmp(line,"ADD ",4)==0){
x=3;
opcode=0x2000;
params=2;
}else if(strncmp(line,"SUB",3)==0){
}else if(strncmp(line,"SUB ",4)==0){
x=3;
opcode=0x2001;
params=2;
}else if(strncmp(line,"SL",2)==0){
}else if(strncmp(line,"SL ",3)==0){
x=2;
opcode=0x2002;
params=1;
}else if(strncmp(line,"SR",2)==0){
}else if(strncmp(line,"SR ",3)==0){
x=2;
opcode=0x2003;
params=1;
}else if(strncmp(line,"CMP",3)==0){
}else if(strncmp(line,"CMP ",4)==0){
x=3;
opcode=0x2004;
params=2;
@ -371,7 +371,7 @@ uint32_t assemble_line(char *line, struct assembler_context_t *assembler_context
return 0xFFFFFFFF;
}else
return 0xFFFFFFFF;
}else if(strncmp(line,"MOV",3)==0){
}else if(strncmp(line,"MOV ",4)==0){
uint32_t data;
x=3;
while(line[x]==' ')x++;
@ -458,18 +458,18 @@ uint32_t assemble_line(char *line, struct assembler_context_t *assembler_context
return 0xFFFFFFFF;
}else
return 0xFFFFFFFF;
}else if(strncmp(line,"HALT",4)==0){
}else if(strncmp(line,"HALT ",5)==0||strncmp(line,"HALT\0",5)==0){
x=4;
while(line[x]==' ')x++;
if(line[x]==0)
return 0x20050000;
else
return 0xFFFFFFFF;
}else if(strncmp(line,"RET",3)==0){
}else if(strncmp(line,"RET ",4)==0||strncmp(line,"RET\0",4)==0){
return 0x10000000;
}else if(*line==':'){
return 0xFFFFFFF0;
}else if(strncmp(line,"PUSH",4)==0){
}else if(strncmp(line,"PUSH ",5)==0){
x=4;
while(line[x]==' ')x++;
if(line[x]=='%'){
@ -483,7 +483,7 @@ uint32_t assemble_line(char *line, struct assembler_context_t *assembler_context
}
}else
return 0xFFFFFFFF;
}else if(strncmp(line,"POP",3)==0){
}else if(strncmp(line,"POP ",4)==0){
x=3;
while(line[x]==' ')x++;
if(line[x]=='%'){