mirror of
https://github.com/cirosantilli/linux-kernel-module-cheat.git
synced 2026-01-23 02:05:57 +01:00
x86 asm: move cmp from x86-assembly-cheat
This commit is contained in:
@@ -12364,6 +12364,7 @@ Bibliography:
|
|||||||
** link:userland/arch/x86_64/div_overflow.S[DIV overflow]
|
** link:userland/arch/x86_64/div_overflow.S[DIV overflow]
|
||||||
** link:userland/arch/x86_64/div_zero.S[DIV zero]
|
** link:userland/arch/x86_64/div_zero.S[DIV zero]
|
||||||
** link:userland/arch/x86_64/idiv.S[IDIV]
|
** link:userland/arch/x86_64/idiv.S[IDIV]
|
||||||
|
* link:userland/arch/x86_64/cmp.S[CMP]
|
||||||
|
|
||||||
=== x86 SIMD
|
=== x86 SIMD
|
||||||
|
|
||||||
|
|||||||
@@ -42,4 +42,18 @@ LKMC_PROLOGUE
|
|||||||
*/
|
*/
|
||||||
addq memory_immediate, memory_register
|
addq memory_immediate, memory_register
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* ADD and many other instructions automatically update the status flags
|
||||||
|
* which controls branches.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Equals 0. */
|
||||||
|
mov $1, %rax
|
||||||
|
add $-1, %rax
|
||||||
|
LKMC_ASSERT(je)
|
||||||
|
|
||||||
|
/* Not equals 0. */
|
||||||
|
mov $2, %rax
|
||||||
|
add $-1, %rax
|
||||||
|
LKMC_ASSERT(jne)
|
||||||
LKMC_EPILOGUE
|
LKMC_EPILOGUE
|
||||||
|
|||||||
21
userland/arch/x86_64/cmp.S
Normal file
21
userland/arch/x86_64/cmp.S
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
/* https://github.com/cirosantilli/linux-kernel-module-cheat#userland-assembly
|
||||||
|
*
|
||||||
|
* Compare two numbers and set the flags register.
|
||||||
|
*
|
||||||
|
* `cmp X, Y` does `X - Y` and ignores the exact result, but sets
|
||||||
|
* all flags that would be set on the subtraction, just like SUB does.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <lkmc.h>
|
||||||
|
|
||||||
|
LKMC_PROLOGUE
|
||||||
|
/* 2 == 2 */
|
||||||
|
mov $2, %rax
|
||||||
|
cmp $2, %rax
|
||||||
|
LKMC_ASSERT(je)
|
||||||
|
|
||||||
|
/* 2 > 1 */
|
||||||
|
mov $2, %rax
|
||||||
|
cmp $1, %rax
|
||||||
|
LKMC_ASSERT(ja)
|
||||||
|
LKMC_EPILOGUE
|
||||||
Reference in New Issue
Block a user