本文介绍了检查斧头上的位数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要找到一种方法来检查ax寄存器中(1)上当前的位数.我当时想在shl或shr中使用,但我不知道我到底该怎么使用它们.到目前为止,这是我的代码:org 100h
mov ax, 0xffffh
;shr ax TO DO
int 16h
ret
在某些地方,右移功能可以将位向右移动.所以我应该通过尝试每次将"16"位推"到右边来使用它,然后检查LSB 1或0标志?在我看来,这是个好主意.
解决方案
使用popcnt
指令:
popcnt bx,ax
这将bx
设置为ax中设置的位数.不过,您需要一个较新的CPU才能使用此指令.
i need to find a way to check number of bits that is current on (1) in the ax register. i was thinking to use in shl or shr, but i do not know how exactly i suppose to use them. this is my code so far:
org 100h
mov ax, 0xffffh
;shr ax TO DO
int 16h
ret
i red in some place that the shift right function can move the bits to the right. so i might should use it by try to "push" the 16 bits to the right every time, and then check the LSB 1 or 0 flag? it sound to me as good idea.
解决方案
Use the popcnt
instruction:
popcnt bx,ax
This sets bx
to the number of bits set in ax. You need a somewhat recent CPU for this instruction to be available though.
这篇关于检查斧头上的位数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!