From e3ca2a3043c2add6fcea726bd3891983be17bdaf Mon Sep 17 00:00:00 2001 From: nickysn Date: Thu, 12 Oct 2017 15:12:40 +0000 Subject: [PATCH] + added helper functions get_x86_string_op_si_param and get_x86_string_op_di_param * use get_x86_string_op_si_param in the nasm writer git-svn-id: trunk@37450 - --- compiler/x86/agx86nsm.pas | 11 +---------- compiler/x86/cpubase.pas | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 10 deletions(-) diff --git a/compiler/x86/agx86nsm.pas b/compiler/x86/agx86nsm.pas index 659beed6fb..7bfd6780b6 100644 --- a/compiler/x86/agx86nsm.pas +++ b/compiler/x86/agx86nsm.pas @@ -989,16 +989,7 @@ interface else if is_x86_parameterized_string_instruction_op(fixed_opcode) then begin writer.AsmWrite(#9#9); - case fixed_opcode of - A_MOVS,A_OUTS: - i:=1; - A_CMPS,A_LODS: - i:=0; - A_SCAS,A_STOS,A_INS: - i:=-1; - else - internalerror(2017101102); - end; + i:=get_x86_string_op_si_param(fixed_opcode); if (i<>-1) and (taicpu(hp).oper[i]^.typ=top_ref) and (taicpu(hp).oper[i]^.ref^.segment<>NR_NO) then writer.AsmWrite(std_regname(taicpu(hp).oper[i]^.ref^.segment)+' '); diff --git a/compiler/x86/cpubase.pas b/compiler/x86/cpubase.pas index 8f7e31ada6..e40c87893b 100644 --- a/compiler/x86/cpubase.pas +++ b/compiler/x86/cpubase.pas @@ -325,6 +325,12 @@ uses function is_x86_parameterized_string_instruction_op(op: TAsmOp): boolean; function x86_param2paramless_string_op(op: TAsmOp): TAsmOp; function get_x86_string_op_size(op: TAsmOp): TOpSize; + { returns the 0-based operand number (intel syntax) of the ds:[si] param of + a x86 string instruction } + function get_x86_string_op_si_param(op: TAsmOp):shortint; + { returns the 0-based operand number (intel syntax) of the es:[di] param of + a x86 string instruction } + function get_x86_string_op_di_param(op: TAsmOp):shortint; {$ifdef i8086} { return whether we need to add an extra FWAIT instruction before the given @@ -752,6 +758,36 @@ implementation end; + function get_x86_string_op_si_param(op: TAsmOp):shortint; + begin + case op of + A_MOVS,A_OUTS: + result:=1; + A_CMPS,A_LODS: + result:=0; + A_SCAS,A_STOS,A_INS: + result:=-1; + else + internalerror(2017101102); + end; + end; + + + function get_x86_string_op_di_param(op: TAsmOp):shortint; + begin + case op of + A_MOVS,A_SCAS,A_STOS,A_INS: + result:=0; + A_CMPS: + result:=1; + A_LODS,A_OUTS: + result:=-1; + else + internalerror(2017101202); + end; + end; + + {$ifdef i8086} function requires_fwait_on_8087(op: TAsmOp): boolean; begin