static int func_name (const uint8_t * address)
{
int result;
asm ("movl $1f, %0; movzbl %1, %0; 1:"
: "=&a" (result) : "m" (*address));
return result;
}
I have gone through inline assembly references over internet. But i am unable to figure out what this code is doing, eg. what is $1f ? And what does "m" means? Isn't the normal inline convention to use "=r" and "r" ?
$1f
is the address of the 1
label. The f
specifies to look for the first label named 1
in the forward direction. "m"
is an input operand that is in memory. "=&a"
is an output operand that uses the eax
register. a
specifies the register to use, =
makes it an output operand, and &
guarantees that other operands will not share the same register.
Here, %0
will be replaced with the first operand (the eax
register) and %1
by the second operand (The address pointed to by address
).
All these and more are explained in the GCC documentation on Inline assembly and asm contraints.