Add helper getBits() for decode w/ S

This commit is contained in:
Themis Demetriades 2024-05-30 14:57:36 +01:00
parent e2e97bbff9
commit 4b10d18e26
2 changed files with 30 additions and 0 deletions

26
src/decode.c Normal file
View File

@ -0,0 +1,26 @@
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#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);
}
}

4
src/decode.h Normal file
View File

@ -0,0 +1,4 @@
#include "global.h"
#include "a64instruction.h"
a64inst_instruction *decode(word w);