MC decoder API specification

Usage

Here’s an example of using DecodeInstruction (without namespace).

#include "mcdecoder.h"

/* Decode an instruction */
const uint8_t kCodes[] = { 0x00, 0x48, 0x2d, 0xe9, };

DecodeRequest request;
DecodeResult result;
bool succeeded;

request.codes = &kCodes[0];
succeeded = DecodeInstruction(&request, &result);

/* Decoding succeeded? */
if (succeeded) {
    /* Which instruction is decoded? */
    switch (result.instruction_id) {
    case InstructionId_k_push:
        /* Get the decoded result for push */
        printf("instruction: push\n");
        printf("cond: %d\n", result.instruction.push.cond);
        printf("register_list: %d\n", result.instruction.push.register_list);
        break;
    case InstructionId_kUnknown:
        /* Handle an unknown instruction */
        break;
    }
}

Types

struct DecodeRequest

Decoding request

const uint8_t *codes

Codes to be input

struct DecodeResult

Decoding result

InstructionId instruction_id

Decoded instruction id

union instruction

Decoding result for an instruction

InstructionDecodeResult_<instruction> <instruction>

Decoding result for <instruction>

where

  • <instruction>: Instruction name

enum InstructionId

Instruction id to identify a decoded instruction

InstructionId_k_<instruction>

Id for <instruction>

where

  • <instruction>: Instruction name

enumerator InstructionId_kUnknown

Id for an unknown instruction

InstructionDecodeResult_<instruction>

Decoding result for <instruction>

where

  • <instruction>: Instruction name

<type> <field>

Decoding result for <field>

where

  • <type>: Appropriate unsigned integer type for the field: uint8_t, uint16_t or uint32_t

  • <field>: Field name

Macros

InstructionId INSTRUCTION_ID_MAX

Number of instruction ids

Functions

bool DecodeInstruction(const DecodeRequest *request, DecodeResult *result)

Decode an instruction

Parameters:
  • request – Decoding request

  • result – Decoding result

Returns:

true if an instruction matches codes. false otherwise