Is there a list of deprecated x86 instructions?

前端 未结 4 1048
囚心锁ツ
囚心锁ツ 2021-02-07 15:33

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 15:57

    Oh, but there still might be a good reason to use the loop instruction. For example, loop label only requires two bytes. As opposed to dec cx followed by jnz label requires three bytes. Sometimes code size is more important than speed.

    I would suggest, however, that if you're just learning x86 assembly--especially if this is your first foray into assembly language--that you first concentrate on how to do things. Once you've gotten a better feel for how things work, then worry about making them faster.

    0 讨论(0)
  • 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

    0 讨论(0)
  • 2021-02-07 16:02

    Your best bet is to consult Intel's official optimization guide.

    This an other manuals can be found here.

    0 讨论(0)
  • 2021-02-07 16:08

    If you what to know what to avoid, go directly to the processor manufacturers, both intel and amd have manuals for the instruction sets their processors support and to what degree they support them, your best bet if probably the optimization volumes, but if your only just starting out, take Jim's advice, get the thing working first before you worry about speed

    0 讨论(0)
提交回复
热议问题