x86 asm: logical instructions move from x86-assembly-cheat

This commit is contained in:
Ciro Santilli 六四事件 法轮功
2019-06-12 00:00:02 +00:00
parent cefb1a823d
commit 5f50217fdd
5 changed files with 58 additions and 0 deletions

View File

@@ -0,0 +1,9 @@
/* https://github.com/cirosantilli/linux-kernel-module-cheat#x86-logical-instructions */
#include <lkmc.h>
LKMC_PROLOGUE
mov $0x00FF, %rax
and $0x0F0F, %rax
LKMC_ASSERT_EQ(%rax, $0x000F)
LKMC_EPILOGUE

View File

@@ -0,0 +1,9 @@
/* https://github.com/cirosantilli/linux-kernel-module-cheat#x86-logical-instructions */
#include <lkmc.h>
LKMC_PROLOGUE
mov $0x0FF0, %rax
not %ax
LKMC_ASSERT_EQ(%rax, $0xF00F)
LKMC_EPILOGUE

View File

@@ -0,0 +1,9 @@
/* https://github.com/cirosantilli/linux-kernel-module-cheat#x86-logical-instructions */
#include <lkmc.h>
LKMC_PROLOGUE
mov $0x00FF, %rax
or $0x0F0F, %ax
LKMC_ASSERT_EQ(%rax, $0x0FFF)
LKMC_EPILOGUE

View File

@@ -0,0 +1,22 @@
/* https://github.com/cirosantilli/linux-kernel-module-cheat#x86-logical-instructions */
#include <lkmc.h>
LKMC_PROLOGUE
mov $0x00FF, %rax
xor $0x0F0F, %ax
LKMC_ASSERT_EQ(%rax, $0x0FF0)
/* xor to set to zero idiom
*
* http://stackoverflow.com/questions/1135679/does-using-xor-reg-reg-give-advantage-over-mov-reg-0
*
* xor can be used to set a register to 0 instad of mov:
*
* Compileres often do this to generate shorter instrucitons,
* but there are also cases where `mov` is better.
*/
mov $0x1020, %rax
xor %ax, %ax
mov $0x0000, %ax
LKMC_EPILOGUE