Error in argument order when generating assembler code for indirect addressing

Summary

In the use of variables in assembler inserts, their order is not generated correctly.......

System Information

  • Operating system: Windows
  • Processor architecture: x86
  • Compiler version: trunk
  • Device:

Steps to reproduce

Below is an example of code that doesn't work and why it doesn't work...

Example Project

program project1; //x32

{$mode objfpc}{$H+}

uses {$IFDEF UNIX}
  cthreads, {$ENDIF}
  Classes { you can add units after this };

  procedure Norm(Len: PtrUint; var P1, P2); assembler; nostackframe;
  asm

           MOVD    XMM0,  [P1+EAX*4]
           MOVD    [P2+EAX*4],XMM0
  end;

  procedure BAD(Len: PtrUint; var P1, P2); assembler; nostackframe;
  asm

           MOVD    XMM0,  [P1+LEN*4]
           MOVD    [P2+Len*4],XMM0
  end;


type
  AR = packed array [0..7] of byte;
var
  Data1: AR = (1, 1, 1, 1, 1, 1, 1, 1);
  Data2: AR = (2, 2, 2, 2, 2, 2, 2, 2);
  i: byte;
begin
  NORM(1, Data1, Data2);
  for i := 0 to 7 do Write(Data2[i]);
  BAD(1, Data1, Data2);
  for i := 0 to 7 do Write(Data2[i]);
  readln;
end.

The FPC in the "BAD" procedure generates

"; [20] MOVD [P2+Len*4],XMM0
%LINE 20+0
		movd [eax+ecx*4],xmm0
CPU p4"

instead of correct

; [20] MOVD [P2+Len*4],XMM0
%LINE 20+0
		movd [ecx+eax*4],xmm0
CPU p4

What is the current bug behavior?

What is the expected (correct) behavior?

Relevant logs and/or screenshots

Possible fixes