Add helper getBits() for decode w/ S
This commit is contained in:
parent
e2e97bbff9
commit
4b10d18e26
26
src/decode.c
Normal file
26
src/decode.c
Normal 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
4
src/decode.h
Normal file
@ -0,0 +1,4 @@
|
||||
#include "global.h"
|
||||
#include "a64instruction.h"
|
||||
|
||||
a64inst_instruction *decode(word w);
|
||||
Loading…
Reference in New Issue
Block a user