From f91057644c1f1813bf1373b5158e6b658210d570 Mon Sep 17 00:00:00 2001 From: Bobby Bingham Date: Sat, 14 Jan 2017 16:18:16 -0600 Subject: Switch addpc to use pc-offset instead of immediate operand This makes more sense, as the argument is really a signed offset from the program counter. --- mnemonics.c | 2 +- parser.y | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/mnemonics.c b/mnemonics.c index 4a21992..38a35f8 100644 --- a/mnemonics.c +++ b/mnemonics.c @@ -34,7 +34,7 @@ const struct mnemonic mnemonics[] = { { "ble", 0x6a00, { {PCOFF, 0}, } }, /* branch if less than or equal */ { "bra", 0x6e00, { {PCOFF, 0}, } }, /* branch always */ { "jmp", 0x7000, { {REGPTR, 5}, } }, /* branch always */ - { "addpc", 0x8000, { {REG, 9}, {IMM, 0} } }, /* add program counter and immediate */ + { "addpc", 0x8000, { {REG, 9}, {PCOFF, 0} } }, /* add program counter and immediate */ { "nop", 0xffff, { } }, /* no operation */ }; diff --git a/parser.y b/parser.y index 3ca1c2c..4396fd1 100644 --- a/parser.y +++ b/parser.y @@ -88,6 +88,7 @@ void yyerror(const char *msg) %type a_regp_reg %type a_reg_regp %type a_reg_imm +%type a_reg_pcoff %type a_pcoff %type intlit @@ -136,7 +137,7 @@ inst: | T_BLE a_pcoff { $$ = INSTRUCTION_ARGS(BLE, $2); } | T_BRA a_pcoff { $$ = INSTRUCTION_ARGS(BRA, $2); } | T_JMP a_regp { $$ = INSTRUCTION_ARGS(JMP, $2); } - | T_ADDPC a_reg_imm { $$ = INSTRUCTION_ARGS(ADDPC, $2); } + | T_ADDPC a_reg_pcoff { $$ = INSTRUCTION_ARGS(ADDPC, $2); } | T_NOP { $$ = INSTRUCTION(NOP); } ; @@ -152,6 +153,8 @@ a_reg_regp: T_SPACE T_REG "," T_REGPTR { $$ = MKARGS($2, $4); } a_reg_imm: T_SPACE T_REG "," imm { $$ = MKARGS($2, $4); } +a_reg_pcoff: + T_SPACE T_REG "," pcoff { $$ = MKARGS($2, $4); } a_pcoff: T_SPACE pcoff { $$ = MKARGS($2); } -- cgit v1.2.3