x86 asm: move binary arithmetic instructions from x86-assembly-cheat except cmp

This commit is contained in:
Ciro Santilli 六四事件 法轮功
2019-06-12 00:00:00 +00:00
parent 90925e7e06
commit 0028ff0ebd
12 changed files with 326 additions and 8 deletions

View File

@@ -0,0 +1,40 @@
/* https://github.com/cirosantilli/linux-kernel-module-cheat#x86-binary-arithmetic-instructions
*
* Unsigned integer division, interface similar to MUL:
*
* ....
* rax = rdx:rax / SRC
* rdx = rdx:rax % SRC
* ....
*
* DIV can be used to calculate modulus, but GCC does not use it becaues it is slow,
* and choses alternative techniques instead
* http://stackoverflow.com/questions/4361979/how-does-the-gcc-implementation-of-module-work-and-why-does-it-not-use-the
*/
#include <lkmc.h>
LKMC_PROLOGUE
/* 64-bit hello world:
*
* 5 / 2 = 2 with leftover of 1.
*/
mov $0, %rdx
mov $5, %rax
mov $2, %rbx
div %rbx
mov %rax, %r12
mov %rdx, %r13
LKMC_ASSERT_EQ(%r12, $2)
LKMC_ASSERT_EQ(%r13, $1)
/* Now with a simple carry. */
mov $1, %rdx
mov $2, %rax
mov $2, %rbx
div %rbx
mov %rax, %r12
mov %rdx, %r13
LKMC_ASSERT_EQ(%r12, $0x8000000000000001)
LKMC_ASSERT_EQ(%r13, $0)
LKMC_EPILOGUE