assemble branch instructions

This commit is contained in:
EDiasAlberto 2024-06-06 13:01:26 +01:00
parent 262fd6219d
commit 6177b2f748
2 changed files with 9 additions and 5 deletions

View File

@ -10,7 +10,7 @@
//TODO: //TODO:
// - use string matching to get opcode, and operands (DONE) // - use string matching to get opcode, and operands (DONE)
// - check operand count (DONE) // - check operand count (DONE)
// - match opcode to a64 struct types (PARTIALLY DONE) // - match opcode to a64 struct types (DONE)
// - count operands and match type/values // - count operands and match type/values
// - generate final a64inst and return // - generate final a64inst and return

View File

@ -1,3 +1,5 @@
#include "global.h"
//generates assembled code based on two pass assembly method //generates assembled code based on two pass assembly method
void generateSymbolTable(a64inst_instruction instrs[], int numInstrs){ void generateSymbolTable(a64inst_instruction instrs[], int numInstrs){
@ -13,26 +15,28 @@ void generateSymbolTable(a64inst_instruction instrs[], int numInstrs){
word assembleBranch(a64inst_instruction *instr, int ){ word assembleBranch(a64inst_instruction *instr, int ){
word binInstr = 0; word binInstr = 0;
binInstr += (5^28); //101 start of branch instr
switch (instr->data.BranchData.BranchType) switch (instr->data.BranchData.BranchType)
{ {
case a64inst_UNCONDITIONAL: case a64inst_UNCONDITIONAL:
//000101 //000101
//25-0: sign extended simm26 //25-0: sign extended simm26
binInstr += instr->data.processOpData.unconditionalOffset;
break; break;
case a64inst_REGISTER: case a64inst_REGISTER:
//1101011 //10000
//0000
//11111 //11111
//000000 //000000
//9-5: address from register //9-5: address from register
//0000 //0000
binInstr += ((instr->processOpData.src)^5);
break; break;
case a64inst_CONDITIONAL: case a64inst_CONDITIONAL:
// 01010100 // 01010100
// 25-5: sign extended offset // 25-5: sign extended offset
// 4-0: 0{condition} // 4-0: 0{condition}
binInstr += ((instr->processOpData.offset)^5);
binInstr += instr->processOpData.cond;
break; break;
default: default:
break; break;