[ create a new paste ] login | about

Link: http://codepad.org/uLcDVMSn    [ raw code | fork ]

Evetro - C, pasted on Jul 9:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/// direct method for 32-bit in dumb assembly
unsigned rbN1 (unsigned arg)
{
  __asm
  {
    xor eax, eax  // eax := 0
    mov ebx, arg  // ebx := arg
    mov ecx, 32   // ecx := 32  // bits

NEXTBIT:          // loop begin
    sub ecx, 1    // --ecx
    mov edx, ebx  // edx := ebx // arg
    and edx, 1    // edx &= 1   // zero all bits except the least one
    shl edx, cl   // edx <<= (char)ecx
    or eax, edx   // eax |= edx
    shr ebx, 1    // ebx >>= 1
    test ecx, ecx // if ecx ...
    jnz NEXTBIT   // ... != 0 then next iteration
  }
  // return eax
}


Create a new paste based on this one


Comments: