该汇编指令的含义是什么? [英] What is The Meaning of This Assembly instruction?

查看:30
本文介绍了该汇编指令的含义是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

写下面几行是什么意思?

What is meant by writing the following lines?

OR AX,AX

JGE LABEL

据我所知,OR 不是比较运算符.而且,像JGE/JE/JL"这样的分支语句只能在我在 CMP 的任何比较过程之后使用它们时才能使用.

To my knowledge, OR is not a comparison operator. And, Branching statements like, "JGE/JE/JL" can only be used only when I have used them after any Comparison process by CMP.

推荐答案

根据一个值设置 FLAGS 是 cmp ax, 0 的替代方案,
但也做同样事情的首选方法是test ax,ax.

It's an alternative to cmp ax, 0 to set FLAGS according to a value,
but the preferred way which also does the same thing is test ax,ax.

or 指令是按位运算,不是比较,所以你首先是对的.

or instruction is bitwise operation, not comparison, so you are right in the first thing.

但是关于分支你完全错了,条件跳转Jcc 并不关心在它之前执行了什么指令,它只会在某些条件下检查标志寄存器 EFLAG.(基本上CPU中没有一条指令关心前面的指令,它是状态机,每条指令都很好地定义了它将如何修改CPU的当前状态,而CPU的状态的内容寄存器(但它们都是段寄存器,(E)FLAG 也是寄存器,控制寄存器很少,在现代 x86 CPU 上还有 FPU 和 MMX/SSE 单元寄存器).

But about branching you are completely wrong, the conditional jump Jcc doesn't care what instruction was executed before it, it will only check the flag register EFLAG for certain conditions. (basically no instruction in CPU cares about previous instruction, it's state machine and each instruction is well defined how it will modify current state of CPU, and state of CPU is content of registers (but all of them, segment registers, also (E)FLAG is register and there are few control registers, and on modern x86 CPU also the FPU and MMX/SSE unit registers).

并且 or 也将修改标志寄存器,就像许多其他指令一样:

And the or will modify flag registers too, as many other instructions:

OF 和 CF 标志被清除;根据结果​​设置 SF、ZF 和 PF 标志.AF 标志的状态未定义.

The OF and CF flags are cleared; the SF, ZF, and PF flags are set according to the result. The state of the AF flag is undefined.

JGE 是:

如果大于或等于 (SF=OF),则跳短.

Jump short if greater or equal (SF=OF).

OR 之后的 OF 将为零,SF 将等于 ax 的最高位(对于值 0x0000 .. 0x7FFF它将是 0,对于值 0x8000 .. 0xFFFF 它将是 1).因此,当 ax 的值在 0 .. 0x7FFF (32767) 范围内时,将执行分支跳转.

The OF will be zero after OR, and SF will be equal to the top bit of ax (for values 0x0000 .. 0x7FFF it will be 0, for values 0x8000 .. 0xFFFF it will be 1). So the branching jump will be executed when ax is value from range 0 .. 0x7FFF (32767).

这是针对零测试寄存器的常见但不是最佳的习惯用法,更好的方法是test ax,ax,这也是按位运算(and),但是结果被丢弃,只修改标志,现代 x86 CPU 理解这个习语,它具有与 cmp ax,0 相同或更好的性能.OR 可能会在内部将运算结果存储回 ax,这可能导致性能不如 test.

It's the common, but unoptimal idiom for testing register against zero, the better way is test ax,ax, which is again bitwise operation (and), but the results is discarded, and only flags are modified, modern x86 CPUs understand this idiom and it has the same or better performance than cmp ax,0. The OR may internally store the result of operation back into ax, which may result in less optimal performance than test.

你可以随时使用条件跳转,它会检查FLAGS寄存器中的值,所以一个类似奔腾时代的旧优化是做CMP几条指令提前给 CPU 时间将更改写入 FLAGS 并在一些不影响标志的指令之间执行(如 MOV 和类似的),但在现代 x86 上,这是反性能措施,因为现代单元将在解码指令对时 cmp something jge label 以特殊方式对待它们,有点像单个操作......但这些都是与性能相关的细节,这需要了解特定目标x86 CPU的底层微架构知识,如果您只是在学习8086的基础知识,则无需担心这些,首先要注意正确理解指令的作用,因此您可以阅读任何asm源,并与指令指南一起,您可以确定性地预测此类代码的结果,理解以及 CPU 在高(寄存器/内存内容)级别上发生的所有更改.一些代码在开始时是否需要多一个时钟来执行并不重要.

You can use the conditional jump any time, it will check the value in FLAGS register, so one old optimization from Pentium-like era was to do CMP few instructions ahead to give CPU time to write the change to FLAGS and execute between some instructions not affecting flags (like MOV and similar), but on modern x86 this is counter-performance measure, as modern unit will upon decoding pair of instructions cmp something jge label treat them in special way, sort of as single operation... but these are all performance related details, which require the knowledge of the underlying micro-architecture of particular target x86 CPU, if you are just learning basics of 8086, there's no need to worry about these yet, focus first to correctly understand what instructions do, so you can read any asm source, and together with the instruction guide you can deterministically predict what will be result of such code, understanding all the changes going on in the CPU on the high (registers/memory content) level. Whether some code takes one more clock to execute is less important in the beginning.

这篇关于该汇编指令的含义是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆