start classifying opcodes and writing skeleton for twopass assembly
This commit is contained in:
parent
cadac4e1bb
commit
422b0f3e62
13
src/parser.c
13
src/parser.c
@ -14,6 +14,17 @@
|
|||||||
// - count operands and match type/values
|
// - count operands and match type/values
|
||||||
// - generate final a64inst and return
|
// - generate final a64inst and return
|
||||||
|
|
||||||
|
void classifyOpcode(char* opcode, a64inst_instruction *instr){
|
||||||
|
if(strcmp(opcode, "b") == 0 || strcmp(opcode, "br") == 0 || strncmp(opcode, "b.", strlen("b.")) == 2){
|
||||||
|
instr->type = a64inst_BRANCH;
|
||||||
|
} else if(strcmp(opcode, "ldr") == 0 || strcmp(opcode, "str") == 0){
|
||||||
|
//loading/storing instruction; classify operands
|
||||||
|
instr->type = a64inst_SINGLETRANSFER;
|
||||||
|
} else {
|
||||||
|
//data processing
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
char *tokeniseOperands(char* str, int operandCount, char *operands[]){
|
char *tokeniseOperands(char* str, int operandCount, char *operands[]){
|
||||||
char *operandsDupe = strdup(str);
|
char *operandsDupe = strdup(str);
|
||||||
int operandCount = 0;
|
int operandCount = 0;
|
||||||
@ -43,8 +54,10 @@ a64inst_instruction *parser(char asmLine[]){
|
|||||||
|
|
||||||
if(opcode[0]=="."){
|
if(opcode[0]=="."){
|
||||||
//type is directive
|
//type is directive
|
||||||
|
//define new type in a64instr struct
|
||||||
} else if(opcode[strlen(opcode)-1]==":") {
|
} else if(opcode[strlen(opcode)-1]==":") {
|
||||||
//type is label
|
//type is label
|
||||||
|
//use symbol table to assemble
|
||||||
} else {
|
} else {
|
||||||
//type is instruction
|
//type is instruction
|
||||||
int operandCount = 0;
|
int operandCount = 0;
|
||||||
|
|||||||
12
src/twopassassembly.c
Normal file
12
src/twopassassembly.c
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
//generates assembled code based on two pass assembly method
|
||||||
|
|
||||||
|
void generateSymbolTable(a64inst_instruction instrs[], int numInstrs){
|
||||||
|
//TODO:
|
||||||
|
//generate symbol table based on inputted assembly code and labels
|
||||||
|
for(int i=0; i<numInstrs; i++){
|
||||||
|
// discuss defining a LABEL type
|
||||||
|
if(instrs[i]->type==LABEL){
|
||||||
|
// symbol table stuff here
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user