generate branch struct from operands (INCOMPLETE)

This commit is contained in:
EDiasAlberto 2024-06-06 13:22:54 +01:00
parent 6177b2f748
commit b93ab76b82
2 changed files with 36 additions and 1 deletions

View File

@ -14,6 +14,39 @@
// - count operands and match type/values
// - generate final a64inst and return
void generateBranchOperands(a64inst_instruction *instr, char* opcode, char *operandList[]){
switch(instr->data.BranchType){
case a64inst_UNCONDITIONAL:
//define and sign extend immediate offset
//use symbol table
break;
case a64inst_REGISTER:
char *endptr;
instr->data.BranchData.processOpData.src = strtol(operandList[0] + 1, endptr, 2)
break;
case a64inst_CONDITIONAL:
char* condition = strtok(strdup(opcode), "b.");
condition = strtok(NULL, "");
if(strcmp(condition, "eq")==0){
instr->data.BranchData.processOpData.cond = EQ;
} else if (strcmp(condition, "ne")==0){
instr->data.BranchData.processOpData.cond = NE;
} else if (strcmp(condition, "ge")==0){
instr->data.BranchData.processOpData.cond = GE;
} else if (strcmp(condition, "lt")==0){
instr->data.BranchData.processOpData.cond = LT;
} else if (strcmp(condition, "gt")==0){
instr->data.BranchData.processOpData.cond = GT;
} else if (strcmp(condition, "le")==0){
instr->data.BranchData.processOpData.cond = LE;
} else if (srtcmp(condition, "al")==0){
instr->data.BranchData.processOpData.cond = AL;
}
break;
//calculate offset from symbol table.
}
}
void classifyOpcode(char* opcode, a64inst_instruction *instr, char *operandList[]){
if((int isUnconditional = strcmp(opcode, "b")) == 0 ||
(int isRegister = strcmp(opcode, "br")) == 0 ||
@ -27,6 +60,7 @@ void classifyOpcode(char* opcode, a64inst_instruction *instr, char *operandList[
instr->data.BranchData.BranchType = a64inst_CONDITIONAL;
//instr->data.branchData.processOpData.cond = {remove first two chars of opcode}
}
generateBranchOperands(instr, opcode, operandList);
} else if((int isLoad = strcmp(opcode, "ldr")) == 0 || (int isStore = strcmp(opcode, "str")) == 0){
//loading/storing instruction; classify operands
char *address = operandList[1];

View File

@ -13,7 +13,7 @@ void generateSymbolTable(a64inst_instruction instrs[], int numInstrs){
}
}
word assembleBranch(a64inst_instruction *instr, int ){
word assembleBranch(a64inst_instruction *instr){
word binInstr = 0;
binInstr += (5^28); //101 start of branch instr
switch (instr->data.BranchData.BranchType)
@ -41,6 +41,7 @@ word assembleBranch(a64inst_instruction *instr, int ){
default:
break;
}
return binInstr;
}
void firstPass(a64inst_instruction instrs[], int numInstrs){