ref: ca36422ac94e1a1313ff508987f494c7ffaa7520
parent: 8e4ba8d2e436a985c77e08212b65dd31157dea3f
author: Rangi <remy.oukaour+rangi42@gmail.com>
date: Fri Apr 30 14:00:31 EDT 2021
Parse 'ld hl, sp - <e8>' correctly Fixes #864
--- a/src/asm/parser.y
+++ b/src/asm/parser.y
@@ -487,6 +487,7 @@
%type <constValue> const_3bit
%type <expr> reloc_8bit
%type <expr> reloc_8bit_no_str
+%type <expr> reloc_8bit_offset
%type <expr> reloc_16bit
%type <expr> reloc_16bit_no_str
%type <constValue> sectiontype
@@ -1344,6 +1345,16 @@
}
;
+reloc_8bit_offset : T_OP_ADD relocexpr {
+ rpn_CheckNBit(&$2, 8);
+ $$ = $2;
+ }
+ | T_OP_SUB relocexpr {
+ rpn_UNNEG(&$$, &$2);
+ rpn_CheckNBit(&$$, 8);
+ }
+;
+
reloc_16bit : relocexpr {
rpn_CheckNBit(&$1, 16);
$$ = $1;
@@ -1863,9 +1874,9 @@
| z80_ld_a
;
-z80_ld_hl : T_Z80_LD T_MODE_HL T_COMMA T_MODE_SP T_OP_ADD reloc_8bit {
+z80_ld_hl : T_Z80_LD T_MODE_HL T_COMMA T_MODE_SP reloc_8bit_offset {
out_AbsByte(0xF8);
- out_RelByte(&$6, 1);
+ out_RelByte(&$5, 1);
}
| T_Z80_LD T_MODE_HL T_COMMA reloc_16bit {
out_AbsByte(0x01 | (REG_HL << 4));
--- a/test/link/all-instructions.asm
+++ b/test/link/all-instructions.asm
@@ -220,6 +220,7 @@
add sp,$DB
ld [$ABCD],sp
ld hl,sp+$DB
+ ld hl,sp-$25
ld sp,hl
pop af
@@ -243,8 +244,6 @@
nop
scf
stop
-BYTE = 0
-REPT 256
+FOR BYTE, 256
stop BYTE
-BYTE = BYTE + 1
ENDR
binary files a/test/link/all-instructions.out.bin b/test/link/all-instructions.out.bin differ