Last active
September 30, 2019 21:34
-
-
Save Silva97/046d6a869db15409a201f95cc539bb0d to your computer and use it in GitHub Desktop.
Exemplo de divisão de um número de 128 bits
This file contains hidden or 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
#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