ulas.arch = (struct ulas_arch){NULL, 0, ULASINSTRS_SM83};
ulas.arch.regs_names = ULAS_SM83_REGS;
ulas.arch.regs_len = ULAS_SM83_REGS_LEN;
+ ulas.arch.endianess = ULAS_LE;
break;
default:
ULASPANIC("Unknown architecture\n");
#ifndef ARCHS_H_
#define ARCHS_H_
+enum ulas_endianess {
+ ULAS_BE,
+ ULAS_LE
+};
+
/**
* Insturction table:
* It is simply a table of all possible instructions for
unsigned long regs_len;
const struct ulas_instr *instrs;
+ enum ulas_endianess endianess;
};
void ulas_arch_set(enum ulas_archs arch);
}
// expression results in order they appear
- // TODO: this should probably become a union of sort to allow float expressions
+ // TODO: this should probably become a union of sort to allow float
+ // expressions
int exprres[ULAS_INSTRDATMAX];
int expridx = 0;
memset(&exprres, 0, sizeof(int) * ULAS_INSTRDATMAX);
assert(datread < ULAS_INSTRDATMAX);
assert(expridx < ULAS_INSTRDATMAX);
- // TODO: implement big endian here
if (dat[datread] == ULAS_E8 || dat[datread] == ULAS_A8) {
dst[written] = (char)exprres[expridx++];
} else if (dat[datread] == ULAS_E16) {
- // write 16-bit le values
short val = (short)exprres[expridx++];
- dst[written++] = (char)(val & 0xFF);
- dst[written] = (char)(val >> 8);
+ if (ulas.arch.endianess == ULAS_BE) {
+ dst[written++] = (char)(val >> 8);
+ dst[written] = (char)(val & 0xFF);
+ } else {
+ // write 16-bit le values
+ dst[written++] = (char)(val & 0xFF);
+ dst[written] = (char)(val >> 8);
+ }
} else {
dst[written] = (char)dat[datread];
}