data processing immediate
This commit is contained in:
parent
b362f46d58
commit
ce34f27fbd
@ -19,9 +19,15 @@ struct st {
|
|||||||
// add new node to the end
|
// add new node to the end
|
||||||
void st_add(st table, void* key, void* value) {
|
void st_add(st table, void* key, void* value) {
|
||||||
node n = {key, value, table.tail};
|
node n = {key, value, table.tail};
|
||||||
|
if (table.head == NULL) {
|
||||||
|
table.head = &n;
|
||||||
|
table.tail = &n;
|
||||||
|
}
|
||||||
|
else {
|
||||||
(*(table.tail)).next = &n;
|
(*(table.tail)).next = &n;
|
||||||
table.tail = &n;
|
table.tail = &n;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// returns the pointer to key of the specified node, or null, if it does not exist
|
// returns the pointer to key of the specified node, or null, if it does not exist
|
||||||
void* st_search(st table, void* key) {
|
void* st_search(st table, void* key) {
|
||||||
@ -1,15 +1,8 @@
|
|||||||
|
# include "global.h"
|
||||||
|
# include "a64instruction.h"
|
||||||
|
# include "symboltable.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){
|
|
||||||
//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 assembleBranch(a64inst_instruction *instr, int ){
|
||||||
word binInstr = 0;
|
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:
|
//TODO:
|
||||||
// -iterate over instructions, adding to symbol table
|
// -iterate over instructions, adding to symbol table
|
||||||
// create symbol table and map labels to addresses/lines
|
// 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:
|
//TODO:
|
||||||
// iterate over instructions again, this time replacing labels
|
// iterate over instructions again, this time replacing labels
|
||||||
// with values from symbol table
|
// with values from symbol table
|
||||||
// after a line has had all the values replaced, assemble it and append
|
// 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;
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue
Block a user