From 1c69ae6a1508ca6041998c8db3aab3b4fa002488 Mon Sep 17 00:00:00 2001 From: florian Date: Tue, 26 Sep 2017 20:14:41 +0000 Subject: [PATCH] handle correctly "reg+const" operands in avr assembler, fixes issue #32016 git-svn-id: trunk@37328 - --- compiler/avr/agavrgas.pas | 9 ++++----- compiler/avr/raavrgas.pas | 14 ++++++++++++-- tests/webtbs/tw32150.pp | 1 + 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/compiler/avr/agavrgas.pas b/compiler/avr/agavrgas.pas index eb44c73c15..e9264f9535 100644 --- a/compiler/avr/agavrgas.pas +++ b/compiler/avr/agavrgas.pas @@ -104,7 +104,7 @@ unit agavrgas; NR_R30: s:=s+'Z'; else - s:=gas_regname(base); + s:=s+gas_regname(base); end; if addressmode=AM_POSTINCREMENT then s:=s+'+'; @@ -112,7 +112,7 @@ unit agavrgas; if offset>0 then s:=s+'+'+tostr(offset) else if offset<0 then - s:=s+tostr(offset) + s:=s+tostr(offset); end else if assigned(symbol) or (offset<>0) then begin @@ -157,9 +157,8 @@ unit agavrgas; begin hs:=ReplaceForbiddenAsmSymbolChars(o.ref^.symbol.name); if o.ref^.offset>0 then - hs:=hs+'+'+tostr(o.ref^.offset) - else - if o.ref^.offset<0 then + hs:=hs+'+'+tostr(o.ref^.offset) + else if o.ref^.offset<0 then hs:=hs+tostr(o.ref^.offset); getopstr:=hs; end diff --git a/compiler/avr/raavrgas.pas b/compiler/avr/raavrgas.pas index 0d5898929d..eeb9545e78 100644 --- a/compiler/avr/raavrgas.pas +++ b/compiler/avr/raavrgas.pas @@ -514,9 +514,19 @@ Unit raavrgas; oper.opr.typ:=OPR_REFERENCE; reference_reset_base(oper.opr.ref,tempreg,0,1,[]); - oper.opr.ref.addressmode:=AM_POSTINCREMENT; - consume(AS_PLUS); + { add a constant expression? } + if actasmtoken=AS_PLUS then + begin + consume(AS_PLUS); + if actasmtoken in [AS_INTNUM,AS_ID] then + begin + l:=BuildConstExpression(true,false); + inc(oper.opr.ref.offset,l); + end + else + oper.opr.ref.addressmode:=AM_POSTINCREMENT; + end; end else if (actasmtoken in [AS_END,AS_SEPARATOR,AS_COMMA]) then Begin diff --git a/tests/webtbs/tw32150.pp b/tests/webtbs/tw32150.pp index c0db11538b..7213d37d4a 100644 --- a/tests/webtbs/tw32150.pp +++ b/tests/webtbs/tw32150.pp @@ -7,6 +7,7 @@ procedure test(out x: byte); assembler; nostackframe; asm movw R30, R24 st Z, R1 + ldd r22, z+3 end; var a8: byte;