是否有已弃用的 x86 指令列表?

发布于 2024-10-15 18:22:26 字数 109 浏览 8 评论 0原文

我正在参加 x86 汇编语言编程课程,并且知道某些指令不应再使用 - 因为它们在现代处理器上速度很慢;例如循环指令。

我尚未找到任何被视为已弃用且应避免使用的指令列表;任何指导将不胜感激。

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, the loop instruction.

I haven't been able to find any list of instructions that are considered deprecated and should be avoided; any guidance would be appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

寻梦旅人 2024-10-22 18:22:26

您最好的选择是查阅Intel官方优化指南

您可以在 找到此手册。在这里

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

This an other manuals can be found here.

呆° 2024-10-22 18:22:26

噢,但是使用loop指令可能仍然有充分的理由。例如,循环标签仅需要两个字节。与 dec cx 后跟 jnz label 不同,需要三个字节。有时代码大小比速度更重要。

不过,我建议,如果您刚刚学习 x86 汇编(特别是如果这是您第一次涉足汇编语言),那么您首先要专注于如何做事。一旦你对事情的运作方式有了更好的认识,就可以考虑让它们变得更快。

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.

计㈡愣 2024-10-22 18:22:26

所有 CPU 指令均 100% 有效,可与旧版 CPU 兼容。那么为什么要避免一些指导呢?没有真正弃用的 x86 指令!但我们可以说:

1)所有字符串指令,如 rep movsb 都比较慢。

2) xlat 速度慢且很少使用。

3)此外,使用堆栈帧函数ENTER 和LEAVE 也很慢。

4)在Windows(XP,vista...)下不推荐使用指令IN和OUT,但仅在CPU环2(应用程序级别)下,int nn也被弃用,除了int3(调试器陷阱) )。

编辑:添加了简单的速度测试来检查不同版本CPU上的字符串指令rep cmp

测试是在Delphi IDE下进行的,但asm部分是很容易在任何其他 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.

ArraySize = 50000 的测试

平均结果...

1)我的 Intel 单核 CPU Pentium 4 结果:循环计数:232000;重复刻度数:233000

2)我的 Intel Core 2 四核 CPU 结果:循环刻度数:158000;代表刻度:375000

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

高跟鞋的旋律 2024-10-22 18:22:26

如果您想知道要避免什么,请直接联系处理器制造商,英特尔和 AMD 都有其处理器支持的指令集以及支持程度的手册,如果可能是优化量,那么您最好的选择,但如果您唯一的选择刚开始,听从吉姆的建议,先让事情正常运转,然后再担心速度

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文