From ca36422ac94e1a1313ff508987f494c7ffaa7520 Mon Sep 17 00:00:00 2001 From: Rangi Date: Fri, 30 Apr 2021 18:00:31 -0400 Subject: [PATCH] Parse 'ld hl, sp - ' correctly Fixes #864 --- src/asm/parser.y | 15 +++++++++++++-- test/link/all-instructions.asm | 5 ++--- test/link/all-instructions.out.bin | Bin 1388 -> 1390 bytes 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/asm/parser.y b/src/asm/parser.y index 31d7feab..b9351524 100644 --- a/src/asm/parser.y +++ b/src/asm/parser.y @@ -487,6 +487,7 @@ enum { %type const_3bit %type reloc_8bit %type reloc_8bit_no_str +%type reloc_8bit_offset %type reloc_16bit %type reloc_16bit_no_str %type 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 { rpn_CheckNBit(&$1, 16); $$ = $1; @@ -1863,9 +1874,9 @@ z80_ld : z80_ld_mem | 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)); diff --git a/test/link/all-instructions.asm b/test/link/all-instructions.asm index 4e321ffc..84e5f301 100644 --- a/test/link/all-instructions.asm +++ b/test/link/all-instructions.asm @@ -220,6 +220,7 @@ jrlabel: add sp,$DB ld [$ABCD],sp ld hl,sp+$DB + ld hl,sp-$25 ld sp,hl pop af @@ -243,8 +244,6 @@ jrlabel: nop scf stop -BYTE = 0 -REPT 256 +FOR BYTE, 256 stop BYTE -BYTE = BYTE + 1 ENDR diff --git a/test/link/all-instructions.out.bin b/test/link/all-instructions.out.bin index d6c500e603aaab829fec3546f5520a55403f822b..ddd5cdaf93937436c55ac8637162cb8cce8389c1 100644 GIT binary patch delta 12 TcmaFE^^R*p1oP%FW-%rJA~*yd delta 12 TcmaFI^@eLh1oP%7W)UU;B1i-v