From bb7ac5c3a4f50cb34db886034df2d693d8fe3ac2 Mon Sep 17 00:00:00 2001 From: Malfurious Date: Sun, 25 Feb 2024 11:54:53 -0500 Subject: Add x86 loop instruction callout Signed-off-by: Malfurious --- docs/re/arch_x86.txt | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/docs/re/arch_x86.txt b/docs/re/arch_x86.txt index f1f2a03..85cf22f 100644 --- a/docs/re/arch_x86.txt +++ b/docs/re/arch_x86.txt @@ -150,3 +150,18 @@ for(i = 0x20; i != 0; i--) *buf_ptr = 0; buf_ptr++; ``` + + +LOOP instruction +---------------- +#from stack overflow: +#https://stackoverflow.com/questions/46881279/how-exactly-does-the-x86-loop-instruction-work + +LOOP is exactly like `dec ecx / jnz`, except it doesn't set flags. + +It's like the bottom of a `do {} while (--ecx != 0);` loop in C. If execution +enters the loop with ecx=0, wrap-around means the loop will run 2**32 times +(2**64 times in 64-bit mode). + +Unlike `rep movsb/stosb/etc`, it doesn't check for ecx=0 before decrementing, +only after. -- cgit v1.2.3