Why is a 16-bit register used with BSR instruction in this code snippet?

Posted by sharptooth on Stack Overflow See other posts from Stack Overflow or by sharptooth
Published on 2009-11-30T07:46:55Z Indexed on 2010/03/15 19:49 UTC
Read the original article Hit count: 330

Filed under:
|
|

In this hardcore article there's a function find_maskwidth() that basically detects the number of bits required to represent itemCount dictinct values:

unsigned int find_maskwidth( unsigned int itemCount )
{
    unsigned int maskWidth, count = itemCount;
    __asm {
        mov eax, count
        mov ecx, 0
        mov maskWidth, ecx
        dec eax
        bsr cx, ax
        jz next
        inc cx
        mov maskWidth, ecx
    next:
    }
    return maskWidth; 
}

the question is why do they use ax and cx registers instead of eax and ecx?

© Stack Overflow or respective owner

Related posts about x86

Related posts about assembly