本文介绍了获得EAX寄存器的x86汇编语言的第一位的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在x86汇编语言,是有可能得到一个寄存器的第一位?我想获得的第一位 EAX 注册,并将其移动到 EBX ,但我不知道如何要做到这一点呢。

  .STACK 2048。数据ExitProcess的原型,退出code:DWORD。code
开始:
MOV EAX,3;
;现在我要EAX的第一位进入EBX。我怎样才能获得EAX的第一位?
调用了ExitProcess,0
年底启动


解决方案

如果以第一位你的意思是至少显著位,然后尝试:

  ...
 MOV EBX,EAX
 和EBX,01

您显然不明白的指令进行操作的所有的在一个名为寄存器一次位,而和指令结合自己的操作数逐位。

下面的作品,也和可以说是一种更直接的跨$ P $您的要求ptation(获得EAX的第一位,然后放入EBX),但它破坏EAX的内容:

  ...
 和EAX,1
 MOV EBX,EAX

在组装code,因为你有几个寄存器,其内容往往是precious,因此摧毁了一个寄存器的内容在计算一个新的结果一般是可以避免的。 (如果你不能,你不能,但这种情况下,很容易避免的)。

最后,你可以写:

  ...
 MOV EBX,1
 和EBX,EAX

这工作得很好,并且是一样快像其他两个。我preFER第一,因为它强调恕我直言,值我凭借第一提的是,在1,这仅仅是一个偶然的常量的关心(EAX的内容)。似乎不是这种风格就像它的问题很多,但如果你写了很多code的,的尤其的神秘的东西,如汇编程序,这样做最大限度后来可读性是值得很多。

这是值得你的麻烦,找到英特尔的参考手册和的阅读的他们仔细了解每一个机器指令做了什么。这似乎是一个艰巨的任务,因为它是一个大书;只着眼于说明您最初似乎需要。

In x86 assembly language, is it possible to obtain the first bit of a register? I want to obtain the first bit of the eax register and move it into ebx, but I'm not sure how to do this yet.

.stack 2048

.data

ExitProcess proto, exitcode:dword

.code
start:
mov eax, 3;
;now I want to move the first bit of eax into ebx. How can I obtain the first bit from eax?
invoke  ExitProcess, 0
end start
解决方案

If by "first bit" you mean the least significant bit, then try:

 ...
 mov   ebx, eax
 and   ebx, 01

You apparently don't understand that instructions operate on all the bits in a named register at once, and the "and" instructions combine their operands bit-by-bit.

The following works, too, and is arguably a more direct interpretation of your request ("get the first bit of eax, and then put in EBX") but it destroys the contents of EAX:

 ...
 and   eax, 1
 mov   ebx, eax

In assembly code, because you have few registers, their contents tend to be precious, so destroying one register's content in computing a new result is generally avoided. (When you can't, you can't, but this case it is easy to avoid).

Finally, you could write:

 ...
 mov   ebx, 1
 and   ebx, eax

This works fine, and is just as fast as the other two. I prefer the first because it emphasizes IMHO the value I care about (content of EAX) by virtue of mentioning it first, over the "1", which is just an incidental constant. This kind of style may not seem like it matters much, but if you write a lot of code, especially arcane stuff such as assembler, doing it to maximize later readability is worth a lot.

It is worth your trouble to find the Intel reference manuals, and read them carefully to understand what each machine instruction does. That seems like a daunting task because its a big book; just focus on the instructions you initially seem to need.

这篇关于获得EAX寄存器的x86汇编语言的第一位的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 09:42