Is there a list of deprecated x86 instructions?

前端 未结 4 2190
逝去的感伤
逝去的感伤 2021-02-07 15:41

I\'m taking an x86 assembly language programming class and know that certain instructions shouldn\'t be used anymore -- because they\'re slow on modern processors; for example,

4条回答
  •  离开以前
    2021-02-07 16:01

    All CPU instructions are 100% functional to reach compatibility with older CPUs. So why to avoid some instruction? There is no realy deprecated x86 instructions! But we can say:

    1)All string istructions like rep movsb are slower.

    2) xlat is slow and very rare in use.

    3)Also the use of stack frame functions ENTER and LEAVE is slow.

    4)Uder Windows (XP, vista...) the deprecated instructions are IN and OUT, but only under CPU ring 2 (aplication level), also the int nn is deprecated, except int3 (debugger trap).

    EDIT: added simple speed test to check strings instruction rep cmp on different versions of CPUs.

    Test is made under Delphi IDE but the asm part is very easy to translate in any other IDE.

    program ProjectTest;
    
    {$APPTYPE CONSOLE}
    
    uses SysUtils, windows;
    
    const
      ArraySize = 50000;
    
    var
      StartTicks    :int64;
      EndTicks      :int64;
      arA           :array [0..ArraySize - 1]of byte;
      arB           :array [0..ArraySize - 1]of byte;
    
    begin
      FillChar(ArA, SizeOf(ArA), 255);          //Set all bytes to 0xFF
      FillChar(ArB, SizeOf(ArB), 255);          //Set all bytes to 0xFF
    
    repeat
      Sleep(100);       //Calm down
      asm
    //Save  StartTicks
        rdtsc
        mov         dword ptr [StartTicks], eax
        mov         dword ptr [StartTicks + 4], edx
    //Test LOOP
        push        edi
        mov         ecx, -ArraySize
        mov         edi, offset arA + ArraySize
        mov         esi, offset arB + ArraySize
    @loop:
        mov         al,[esi + ecx]
        cmp         [edi + ecx], al
        jnz         @exit
        inc         ecx
        jnz         @loop
    @exit:
        pop         edi
    //Save  EndTicks
        rdtsc
        mov         dword ptr [EndTicks], eax
        mov         dword ptr [EndTicks + 4], edx
      end;
    
      WriteLn('Loop ticks : ' + IntToStr(EndTicks - StartTicks));
    
      Sleep(100);       //Calm down
      asm
    //Save  StartTicks
        rdtsc
        mov         dword ptr [StartTicks], eax
        mov         dword ptr [StartTicks + 4], edx
    //Test REP
        push        edi
        cld
        mov         ecx, ArraySize
        mov         edi, offset arA
        mov         esi, offset arB
        repe        cmpsb
        pop         edi
    //Save  EndTicks
        rdtsc
        mov         dword ptr [EndTicks], eax
        mov         dword ptr [EndTicks + 4], edx
      end;
    
      WriteLn('Rep ticks  : ' + IntToStr(EndTicks - StartTicks));
    
      ReadLn                    //Wait keyboard
    until false;
    
    end.
    

    TESTs for ArraySize = 50000

    Average results...

    1)My Intel single core CPU Pentium 4 results: Loop ticks : 232000; Rep ticks : 233000

    2)My Intel Core 2 Quad CPU results: Loop ticks : 158000; Rep ticks : 375000

提交回复
热议问题