Assembly code snippets

Back to the snippets overview

Details

TitleDecToBin
AuthorSloat
Submitted by:Sloat
Date added:2002-06-14 06:04:28
Date modified:2002-06-20 04:20:26

Comments

stores a 32-bit number in a buffer as binary removing leading zeros. improvements welcome!

best-case: number = 0 ... 3 ticks
worst-case: number >= 80000000h (highest bit set) ... ~252ticks
tested on an amd k6-2

Snippet

buff db 128 dup (?)
number equ 45432
....


mov eax, number
or eax, eax
jz _exit
bsr edx, eax
mov ecx, 31
sub ecx, edx
shl eax, cl
lea edx, buff
@@:
    shl eax, 1
    setc BYTE PTR[edx]
    add BYTE PTR[edx], 30h
    inc edx
    inc ecx
cmp ecx, 32
jl @B
_exit: