Created
April 18, 2018 11:09
-
-
Save velnias75/f38769504bb0948bc82eeef9ada3d237 to your computer and use it in GitHub Desktop.
Assembler integer logarithm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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