Files
bshell/bshell.runtime/runtime/opcode.c
T

27 lines
594 B
C
Raw Normal View History

#include <bshell/runtime/opcode.h>
#include <fx/int.h>
#define BSHELL_OPCODE_MAX 0xFF
#define ARG_MAX 0xFFFFFF
bshell_instruction bshell_instruction_encode(
enum bshell_opcode opcode,
uint32_t arg)
{
if (opcode > BSHELL_OPCODE_MAX) {
return BSHELL_INSTRUCTION_INVALID;
}
return fx_u32_htob((opcode & BSHELL_OPCODE_MAX) | (arg & ARG_MAX) << 8);
}
void bshell_instruction_decode(
bshell_instruction instr,
enum bshell_opcode *out_opcode,
uint32_t *out_arg)
{
instr = fx_u32_btoh(instr);
*out_opcode = (instr & BSHELL_OPCODE_MAX);
*out_arg = ((instr >> 8) & ARG_MAX);
}