gbasm: add support for "ld, r8, r8"

This commit is contained in:
2017-05-20 16:47:57 -07:00
parent a5f3ae7ad6
commit 70a7e80d3e

View File

@@ -74,7 +74,25 @@ int inc_dec_check(const struct gbasm_parsed_inst *inst,
return 0;
}
size_t inc_emit(struct emitter *emitter,
static int ld_check(const struct gbasm_parsed_inst *inst,
const struct gbasm_op_info *op_info)
{
if (inst->num_operands < 2) {
gbasm_too_many_args_error(inst, op_info);
}
if (inst->num_operands > 2) {
gbasm_too_few_args_error(inst, op_info);
}
if (!gbasm_argtype_in_set(op_info->operand_types[0], inst->operands[0].type)) {
gbasm_arg_wrong_type_error(inst, op_info);
}
return 0;
}
static size_t inc_emit(struct emitter *emitter,
const struct gbasm_parsed_inst *inst)
{
uint8_t opcode = 0x00;
@@ -144,6 +162,18 @@ size_t dec_emit(struct emitter *emitter,
return 1;
}
size_t ld_emit(struct emitter *emitter,
const struct gbasm_parsed_inst *inst)
{
uint64_t opcode = 0x40;
opcode += inst->operands[0].r8.type * 8;
opcode += inst->operands[1].r8.type;
emit(emitter, &opcode, 1);
return 1;
}
struct gbasm_op_info gbasm_op_infos[] = {
{
@@ -260,6 +290,14 @@ struct gbasm_op_info gbasm_op_infos[] = {
.length = length_one_byte,
.emit = dec_emit,
},
{
.opcode = "ld",
/* support all of the other operands */
.operand_types = { GBASM_OPERAND_REG_8, GBASM_OPERAND_REG_8 },
.check = ld_check,
.length = length_one_byte,
.emit = ld_emit,
},
};