I'm trying to write this inline assembly, which returns a random number using the rdrand
instruction. The number is stored in the eax
register, and then moved to the rng_num
variable. But I get the error that is in the title.
uint32_t rng_num;
asm volatile("movl $100, %ecx\n\t"
"__trng_cpu_ret:\n\t"
"rdrand %%eax\n\t"
"jnc .__trng_cpu_end\n\t"
"loop __trng_cpu_ret\n\t"
".__trng_cpu_fail:\n\t"
"movl $0, %%eax\n\t"
".__trng_cpu_end:\n\t"
"ret\n\t"
: "=r" (rng_num)
:
:"%eax");
This is the original x86 Intel syntax code:
mov ecx, 100 ;number of retries
retry:
rdrand eax
jnc .done ;carry flag is clear on success
loop retry
.fail:
;no random number available
.done:
;random number is is EAX