start classifying opcodes and writing skeleton for twopass assembly

This commit is contained in:
EDiasAlberto 2024-06-04 01:30:17 +01:00
parent cadac4e1bb
commit 422b0f3e62
2 changed files with 25 additions and 0 deletions

View File

@ -14,6 +14,17 @@
// - count operands and match type/values
// - 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 *operandsDupe = strdup(str);
int operandCount = 0;
@ -43,8 +54,10 @@ a64inst_instruction *parser(char asmLine[]){
if(opcode[0]=="."){
//type is directive
//define new type in a64instr struct
} else if(opcode[strlen(opcode)-1]==":") {
//type is label
//use symbol table to assemble
} else {
//type is instruction
int operandCount = 0;

12
src/twopassassembly.c Normal file
View 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
}
}
}