From: Lukas Krickl Date: Tue, 20 Feb 2024 12:39:21 +0000 (+0100) Subject: Added basic be/le flag to arch X-Git-Url: https://git.krickl.dev/?a=commitdiff_plain;h=44cb04571386dd29bc3003ef34901dd25e323a7a;p=ulas%2F.git Added basic be/le flag to arch --- diff --git a/src/archs.c b/src/archs.c index 371ae7b..5b28aeb 100644 --- a/src/archs.c +++ b/src/archs.c @@ -320,6 +320,7 @@ void ulas_arch_set(enum ulas_archs arch) { 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"); diff --git a/src/archs.h b/src/archs.h index 83b4e41..d0f84ac 100644 --- a/src/archs.h +++ b/src/archs.h @@ -1,6 +1,11 @@ #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 @@ -65,6 +70,7 @@ struct ulas_arch { unsigned long regs_len; const struct ulas_instr *instrs; + enum ulas_endianess endianess; }; void ulas_arch_set(enum ulas_archs arch); diff --git a/src/ulas.c b/src/ulas.c index 8643804..6852c8a 100644 --- a/src/ulas.c +++ b/src/ulas.c @@ -1803,7 +1803,8 @@ int ulas_asminstr(char *dst, unsigned long max, const char **line, } // 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); @@ -1864,14 +1865,18 @@ int ulas_asminstr(char *dst, unsigned long max, const char **line, 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]; }