data processing immediate

This commit is contained in:
GDBWNV 2024-06-06 12:33:09 +01:00
parent b362f46d58
commit ce34f27fbd
2 changed files with 61 additions and 14 deletions

View File

@ -19,8 +19,14 @@ struct st {
// add new node to the end
void st_add(st table, void* key, void* value) {
node n = {key, value, table.tail};
(*(table.tail)).next = &n;
table.tail = &n;
if (table.head == NULL) {
table.head = &n;
table.tail = &n;
}
else {
(*(table.tail)).next = &n;
table.tail = &n;
}
}
// returns the pointer to key of the specified node, or null, if it does not exist

View File

@ -1,15 +1,8 @@
# include "global.h"
# include "a64instruction.h"
# include "symboltable.h"
//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
}
}
}
word assembleBranch(a64inst_instruction *instr, int ){
word binInstr = 0;
@ -39,15 +32,63 @@ word assembleBranch(a64inst_instruction *instr, int ){
}
}
void firstPass(a64inst_instruction instrs[], int numInstrs){
st* firstPass(a64inst_instruction instrs[], int numInstrs){
//TODO:
// -iterate over instructions, adding to symbol table
// create symbol table and map labels to addresses/lines
struct st table;
for(int i=0; i<numInstrs; i++){
// discuss defining a LABEL type
if(instrs[i].type==a64inst_LABEL){
st_add(table, &(instrs[i].data.LabelData.label), &i);
}
}
return &table;
}
word dpi(a64inst_instruction cI) {
word out = 0;
a64inst_DPImmediateData data = cI.data.DPImmediateData;
//sf
out += data.regType*(2^31);
out += data.processOp*(2^29);
out += 2^28;
// if arithmetic
if (data.DPIOpType == a64inst_DPI_ARITHM) {
out += 2^24;
// shift
if (data.processOpData.arithmData.shiftImmediate){
out += 2^22;
}
out += data.processOpData.arithmData.immediate*(2^10);
out += data.processOpData.arithmData.src*(2^5);
}
// if wide move
else {
out += 5*(2^23);
// hw
out += data.processOpData.wideMovData.shiftScalar*(2^21);
out += data.processOpData.wideMovData.immediate*(2^5);
}
// destination register
out += data.dest;
return out;
}
void secondPass(a64inst_instruction instrs[], int numInstrs){
void secondPass(a64inst_instruction instrs[], int numInstrs, st* table){
//TODO:
// iterate over instructions again, this time replacing labels
// with values from symbol table
// after a line has had all the values replaced, assemble it and append
for (int i=0; i<numInstrs; i++) {
a64inst_instruction cI = instrs[i];
switch (cI.type) {
case a64inst_DPIMMEDIATE:
dpi(cI);
break;
default:
break;
}
}
return;
}