0

I'm trying to implement a function StrPos in assembler. I have 64-bit processor and FPC. When I'm compiling this shows the following errors:

    function StrPos(Str1, Str2: PChar): LONGINT; assembler;
    asm
        PUSH    DS
        CLD
        XOR AL,AL
        LES EDI,Str2 // error: asm: [les reg32, reg32] Invalid combination of opcode and operands
        MOV CX,0FFFFH
        REPNE   SCASB
        NOT CX
        DEC CX
        JE  @@2
        MOV DX,CX
        MOV BX,ES
        MOV DS,BX
        LES EDI,Str1 // error: asm: [les reg32, reg32] Invalid combination of opcode and operands
        // .........
    end;

Please, help me

Mila
  • 3
  • 2
  • I'm trying to figure out your target architecture. LES looks like you are using some 16bit operating system? Who does this anymore? – David Wohlferd May 31 '14 at 02:12
  • I'm trying to compile that code from pascal STRINGS.PAS library on my 64 bit computer in free pascal ide with emended assembly, but here's some errors, because code from old library that was created for 16 bit processor. I need to rewrite this function for it work without any error. – Mila May 31 '14 at 06:29
  • Well, my first advice would be: Don't write this in asm. Surely FPC has a string library? Just because this is written in asm doesn't mean that it will be magically faster. Using inline asm typically has optimization penalties that will likely swamp any perceived benefits here. The statements highlighted are not the only issues with this code. The registers will need to be changed from DX to RDX, the 0FFFH isn't 64bit, etc. MOV EDI,Str1 might fix your compile errors, but there's more. Are you ABSOLUTELY sure this must be asm? – David Wohlferd May 31 '14 at 06:44

1 Answers1

0

20 year old 16-bit assembler can't be used in FPC.(*) Generally one uses the strpos in the Strings or the sysutils unit, both of which come with FPC.

For special cases, one can remove the need for assembler by using system.indexbyte() which is a basic scasb portable intrinsic.

(*) well strictly speaking, there is a 16-bit FPC backend in trunk, but I guess you are not interested in that, since that also won't run on 64-bit OSes.

Marco van de Voort
  • 25,628
  • 5
  • 56
  • 89