Skip to content

Instantly share code, notes, and snippets.

@Silva97
Last active September 30, 2019 21:34
Show Gist options
  • Save Silva97/046d6a869db15409a201f95cc539bb0d to your computer and use it in GitHub Desktop.
Save Silva97/046d6a869db15409a201f95cc539bb0d to your computer and use it in GitHub Desktop.
Exemplo de divisão de um número de 128 bits
#include <stdio.h>
#include <inttypes.h>
int asmdiv(uint64_t highq, uint64_t lowq, uint64_t divisor)
{
uint64_t quotient;
uint64_t modulous;
__asm__ __volatile__ (
"movq %[highq], %%rdx\n\t"
"movq %[lowq], %%rax\n\t"
"divq %[div]\n\t"
"movq %%rax, %[quot]\n\t"
"movq %%rdx, %[mod]\n\t"
: [quot] "=m" (quotient),
[mod] "=m" (modulous)
: [highq] "irm" (highq),
[lowq] "irm" (lowq),
[div] "rm" (divisor)
);
// Mais código??
printf("Quociente: %" PRIx64 "\n"
"Resto: %" PRIx64 "\n",
quotient, modulous);
return quotient;
}
int main(void)
{
// https://defuse.ca/big-number-calculator.htm
asmdiv(0x1fff, 0xffffffffffffffff, 864213455343);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment