Skip to content

Instantly share code, notes, and snippets.

@velnias75
Created April 18, 2018 11:09
Show Gist options
  • Save velnias75/f38769504bb0948bc82eeef9ada3d237 to your computer and use it in GitHub Desktop.
Save velnias75/f38769504bb0948bc82eeef9ada3d237 to your computer and use it in GitHub Desktop.
Assembler integer logarithm
# unsigned int ilog(unsigned int value, unsigned int base);
# (c) 2018 by Heiko Schaefer
.section .text
.globl ilog
.type ilog, @function
ilog:
pushl %ebp
movl %esp, %ebp
movl 8(%ebp),%ebx # value
movl 12(%ebp),%ecx # base
movl %ebx, %eax
xorl %ebx, %ebx
0:
cmpl %ecx,%eax
jb 1f
cdq
divl %ecx
incl %ebx
cmpl $0x01,%eax
ja 0b
1:
movl %ebx,%eax
movl %ebp, %esp
popl %ebp
ret
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment