ld: add support for loading 8-bit immediates

This commit is contained in:
2017-05-28 23:46:41 -07:00
parent 6a9e8b06a7
commit 7900ac28ff
5 changed files with 83 additions and 25 deletions

View File

@@ -15,9 +15,10 @@ static bool gbasm_argtype_in_set(uint32_t argtype_set, uint32_t argtype)
return !!(argtype & argtype_set);
}
static bool imm_is_8_bit(uint16_t val)
static bool imm_is_8_bit(int val)
{
return (val <= 127) && (val >= -128);
/* Allow signed or unsigned representation */
return (val <= 255) && (val >= -128);
}
static int check_no_args(const struct gbasm_parsed_inst *inst,
@@ -94,9 +95,13 @@ static int ld_check(const struct gbasm_parsed_inst *inst,
gbasm_arg_wrong_type_error(inst, op_info);
}
if (inst->operands[0].type == GBASM_OPERAND_REG_8 &&
imm_is_8_bit(inst->operands[1].imm.value)) {
if (inst->operands[0].type == GBASM_OPERAND_REG_8) {
if (!imm_is_8_bit(inst->operands[1].imm.value)) {
DEBUG_LOG("inst->operands[1].imm.value = %d",
inst->operands[1].imm.value);
gbasm_invalid_imm_error(inst, op_info);
}
}
return 0;