diff --git a/src/decode.c b/src/decode.c new file mode 100644 index 0000000..f258122 --- /dev/null +++ b/src/decode.c @@ -0,0 +1,26 @@ +#include +#include +#include +#include "decode.h" + +#define BYTE_BITS 8 + +// Retrieve the bits between positions 'lsb' (inclusive) and 'msb' (exclusive) from a given word +// as a new zero-extended word. +static word getBits(word wrd, uint8_t lsb, uint8_t msb) { + + // Ensure LSB and MSB are within range of word size, and in the correct order + assert(lsb < msb && msb < BYTE_BITS); + + wrd &= (1 << msb) - 1; + return wrd >> lsb; +} + +a64inst_instruction *decode(word wrd) { + + a64inst_instruction *inst = malloc(sizeof(a64inst_instruction)); + if (inst == NULL) { + fprintf(stderr, "Ran out of memory while attempting to decode an instruction!\n"); + exit(1); + } +} diff --git a/src/decode.h b/src/decode.h new file mode 100644 index 0000000..75f2655 --- /dev/null +++ b/src/decode.h @@ -0,0 +1,4 @@ +#include "global.h" +#include "a64instruction.h" + +a64inst_instruction *decode(word w); \ No newline at end of file