-
Notifications
You must be signed in to change notification settings - Fork 11
/
rabbit_codewords.c
27 lines (23 loc) · 873 Bytes
/
rabbit_codewords.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include "rabbit_codewords.h"
/* Transform the packed representation of an instruction into the unpacked
* representation. */
struct unpacked_s decode(rabbitw instr) {
/* Fetch the space modes from the instruction. */
uint8_t modes = (instr >> 24) & 0xF;
/* Offsets of the space modes in the mode nibble. */
static const uint8_t RB_ADDRA_LSB = 0, RB_ADDRB_LSB = 1, RB_ADDRC_LSB = 2,
RB_IMMED_LSB = 3;
return (struct unpacked_s){
.modes =
{
.immediate = (modes >> RB_IMMED_LSB) & 0x1,
.regc_deref = (modes >> RB_ADDRC_LSB) & 0x1,
.regb_deref = (modes >> RB_ADDRB_LSB) & 0x1,
.rega_deref = (modes >> RB_ADDRA_LSB) & 0x1,
},
.opcode = instr >> 28,
.regc = (instr >> 8) & 0xF,
.regb = (instr >> 4) & 0xF,
.rega = instr & 0xF,
};
}