Chapter8 Bit Manipulation

首先我们来看几条比较熟悉的指令。

and    destination, source(实现某位置0)

or   destination, source(实现某位置1)

xor   destination, source(某位跟1异或取反,跟0异或是自身,本身异或为清0,如xor ax, ax)

not   destination(取反)

1.The results of these operations are put into the destination.

2.The not instruction does not affect any flags.

3.The carry flag CF and the overflow flag OF are both reset to 0.

4.The other flags like SF, ZF, PF are set or reset according to the value of the result of the operation.

test   destination, source

It has the same functions as the and insturction except that destination operand are not changed. That is to say the only job of a test is to set flags.(可联系cmp和sub指令)

它的用处主要有:

1.Examine a particular bit of a byte or a word.比如test  dx, 2000h

就是用来测试寄存器dx  bit13的情况。通常来讲这条指令后面总是跟着一个jz或者jnz指令,而它的结果就是使得往目的地成功跳转如果bit13相应的为0或者1。

2.Get information about a value in a register.For example, 

test    cx, cx    这条指令的结果还是自身,但是它改变了flags的值,从中我们可以得到一些信息。有人说那and cx, cx不也可以实现这么一个功能吗?木有错,但是用test看起来就说明我们此操作的目的就只是测试test不是吗?



接着我们看下移位操作指令,这个如果不弄清楚的话会很容易头晕的。

                        左     右

      logical: shl shr

arithmetic:     sal sar

The source code format of any shift instruction is

s- detination, count

There are three versions of the count operand.

1.Number 1.

2.Another number serving as a byte-size immediate operand.

3.The register specification cl.

看完了基本格式后再看下具体的一些情况。

1.算术左移和逻辑左移是完全一样的。

2.SF, ZF,PF 根据最终得到结果赋值,OF指令只对single-bit才有用,它的值是由你那标志位有木有改变决定的,如果改变了它就为1,否则为0。

3.When a left shift instruction is executed, the bits in the destination slide to the left and 0 bits fill in on the right. The bits that fall of the left are lost except for the very last one shifted off, it is saved in the carry flag CF.

4.算术右移和逻辑右移是不完全一样的。

相同之处在于:With both, the bits in the destination slide to the right and the bits that fall off the right are lost except for the very last one shifted off, which is saved in CF.

不同之处在于:逻辑右移左边那些位直接添0就好了,而算术右移则是添原来标志位sign bit的值。


sh-d   detination, source, cx/immediate

移出操作跟一般的移位操作一样,不同之处在于添的内容是源操作数里的内容(位)。比如说往左移吧,那么往右添的就是源操作数左边相应的那些位;右移则在左边添上源操作数右边相应的那几位。最终结果保留在destination里面,source operand 保持不变。相应标志位的改变跟前面所说的完全一致。


ro- destination, count

循环移位跟single-bit shift基本相同,除了:

1.腾出来的位和CF值均由抛掉的位来填充。

2.影响的标志位仅CF和OF;OF值变化和前面的一致,只对single-bit rotate shift有效。


rc- destination, count     (提醒联系带进位的加法)

它跟ro-的唯一区别就是把CF值值放进了循环,也就是说,移出的位先移向CF,完了CF的原值(就是被移进之前的值)移向腾出的那个位。



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值