Parse 'ld hl, sp - <e8>' correctly

Fixes #864
This commit is contained in:
Rangi
2021-04-30 18:00:31 -04:00
committed by Eldred Habert
parent 8e4ba8d2e4
commit ca36422ac9
3 changed files with 15 additions and 5 deletions

View File

@@ -487,6 +487,7 @@ enum {
%type <constValue> const_3bit %type <constValue> const_3bit
%type <expr> reloc_8bit %type <expr> reloc_8bit
%type <expr> reloc_8bit_no_str %type <expr> reloc_8bit_no_str
%type <expr> reloc_8bit_offset
%type <expr> reloc_16bit %type <expr> reloc_16bit
%type <expr> reloc_16bit_no_str %type <expr> reloc_16bit_no_str
%type <constValue> sectiontype %type <constValue> sectiontype
@@ -1344,6 +1345,16 @@ reloc_8bit_no_str : relocexpr_no_str {
} }
; ;
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 { reloc_16bit : relocexpr {
rpn_CheckNBit(&$1, 16); rpn_CheckNBit(&$1, 16);
$$ = $1; $$ = $1;
@@ -1863,9 +1874,9 @@ z80_ld : z80_ld_mem
| z80_ld_a | 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_AbsByte(0xF8);
out_RelByte(&$6, 1); out_RelByte(&$5, 1);
} }
| T_Z80_LD T_MODE_HL T_COMMA reloc_16bit { | T_Z80_LD T_MODE_HL T_COMMA reloc_16bit {
out_AbsByte(0x01 | (REG_HL << 4)); out_AbsByte(0x01 | (REG_HL << 4));

View File

@@ -220,6 +220,7 @@ jrlabel:
add sp,$DB add sp,$DB
ld [$ABCD],sp ld [$ABCD],sp
ld hl,sp+$DB ld hl,sp+$DB
ld hl,sp-$25
ld sp,hl ld sp,hl
pop af pop af
@@ -243,8 +244,6 @@ jrlabel:
nop nop
scf scf
stop stop
BYTE = 0 FOR BYTE, 256
REPT 256
stop BYTE stop BYTE
BYTE = BYTE + 1
ENDR ENDR

Binary file not shown.