asm code explanation

Could anyone tell me the meaning of this asm structure (maybe line for line)? I can program a very little asm, but I don't understand this function.
I think to understand most of it, bat bsf doesn't mean anything to me.
1
2
3
4
5
6
7
8
9
10
11
12
int tab(unsigned long long a){
  __asm {
	mov eax, 0
	bsf edx, dword ptr a
	jnz l1
	bsf edx, dword ptr a+4
	mov eax, 32
	jnz l1
	mov edx, -32
l1:	add eax, edx
  }
}
Thank you for your answers.
Last edited on
Google is your friend:

http://www.arl.wustl.edu/~lockwood/class/cs306/books/artofasm/Chapter_6/CH06-4.html#HEADING4-67

If you are loathe to click and interpret the code yourself, you can read what I think it does below.

BSF (bit scan forward) scans for the first set bit in the operand, starting at bit 0, clears ZF if it finds a set bit and stores its index.

Usage: BSF dest, source

So the asm code lines containing the BSF mnemonic look for the first set bit in the double word pointed to by a, then return the location of that bit (relative to the location of the pointer) to EDX.

I don't know what the purpose of the whole routine is, though.
Last edited on
Thank you very much. The purpose of this function is to get a certain bit-index of a unsigned long long hash.
I didn't knoe its purpose before and with google I found different definitions of bsf in different asm- types.
A german website for example says the mnemonic sets a bit at a certain index.(http://www.sprut.de/electronic/pic/assemble/befehle.html#bsf)
I'm sorry, I assumed you were talking about the 80x86. My bad, I should have thought of it. But from what you state in your second post in this thread, I think this function uses the same (ore a similar, I am only really at any degree of familiarity with Intel spec instruction sets) definition for BSF as the one in the 80x86 instruction set.
It is my fault. I have found about 4 different definitions and I just really had no Idea what I am dealing with. Not even what kind of assembler it is, because it is quite an old project I have found in the inet.
I replaced it with the following function, because I think that's faster. Am I right?
1
2
3
4
5
6
7
  __asm {
	  bsf	eax, dword ptr a
	  jnz	L1
	  bsf	eax, dword ptr a + 4
	  add	eax, 32
L1:
  }
Topic archived. No new replies allowed.