mirror of
https://github.com/cirosantilli/linux-kernel-module-cheat.git
synced 2026-01-28 20:44:26 +01:00
x86 asm: move loop from x86-assembly-cheat
This commit is contained in:
@@ -12410,6 +12410,12 @@ JG vs JA and JL vs JB:
|
|||||||
* https://stackoverflow.com/questions/9617877/assembly-jg-jnle-jl-jnge-after-cmp/56613928#56613928
|
* https://stackoverflow.com/questions/9617877/assembly-jg-jnle-jl-jnge-after-cmp/56613928#56613928
|
||||||
* https://stackoverflow.com/questions/20906639/difference-between-ja-and-jg-in-assembly
|
* https://stackoverflow.com/questions/20906639/difference-between-ja-and-jg-in-assembly
|
||||||
|
|
||||||
|
==== x86 LOOP instruction
|
||||||
|
|
||||||
|
link:userland/arch/x86_64/loop.S[LOOP]
|
||||||
|
|
||||||
|
Vs <<x86-jcc-instructions,Jcc>>: https://stackoverflow.com/questions/6805692/x86-assembly-programming-loops-with-ecx-and-loop-instruction-versus-jmp-jcond Holy CISC!
|
||||||
|
|
||||||
=== x86 SIMD
|
=== x86 SIMD
|
||||||
|
|
||||||
History:
|
History:
|
||||||
|
|||||||
53
userland/arch/x86_64/loop.S
Normal file
53
userland/arch/x86_64/loop.S
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
/* https://github.com/cirosantilli/linux-kernel-module-cheat#x86-loop-instruction */
|
||||||
|
|
||||||
|
#include <lkmc.h>
|
||||||
|
|
||||||
|
LKMC_PROLOGUE
|
||||||
|
|
||||||
|
/* LOOP
|
||||||
|
*
|
||||||
|
* ....
|
||||||
|
* rcx--;
|
||||||
|
* if (rcx != 0) goto label
|
||||||
|
* ....
|
||||||
|
*/
|
||||||
|
mov $0, %rax
|
||||||
|
mov $3, %rcx
|
||||||
|
loop_label:
|
||||||
|
inc %rax
|
||||||
|
loop loop_label
|
||||||
|
LKMC_ASSERT_EQ(%rax, $3)
|
||||||
|
|
||||||
|
/* LOOPE
|
||||||
|
*
|
||||||
|
* ....
|
||||||
|
* rcx--;
|
||||||
|
* if (ecx != 0 && ZF == 1) goto label
|
||||||
|
* ....
|
||||||
|
*
|
||||||
|
* Application: search for first non-zero element in a range.
|
||||||
|
*
|
||||||
|
* If found, rax will contain the element index.
|
||||||
|
*
|
||||||
|
* Otherwise, rax contains length + 1.
|
||||||
|
*/
|
||||||
|
.section .rodata
|
||||||
|
loope_array: .byte 0, 0, 1, 0
|
||||||
|
.text
|
||||||
|
/* Array length. */
|
||||||
|
mov $4, %rcx
|
||||||
|
mov $-1, %rax
|
||||||
|
loope_label:
|
||||||
|
inc %rax
|
||||||
|
cmpb $0, loope_array(%rax)
|
||||||
|
loope loope_label
|
||||||
|
/* The first non-zero item (1) was at index 2. */
|
||||||
|
LKMC_ASSERT_EQ(%rax, $2)
|
||||||
|
|
||||||
|
/* LOOPNE
|
||||||
|
*
|
||||||
|
* ....
|
||||||
|
* ecx--; if (ecx != 0 && ZF == 0) goto lbl
|
||||||
|
* ....
|
||||||
|
*/
|
||||||
|
LKMC_EPILOGUE
|
||||||
Reference in New Issue
Block a user