assembly - MS ASM 8086 Comparison and Conditional Jumping -
what conditional jumping checking before jump label in example :
mov eax, 0 mov ecx, 1 repeatagain: add eax, ecx cmp ecx, 3 inc ecx jle repeatagain nop ret and conditional jumping checking in example (where checking equality before proceeding jumping ?):
mov eax, 0 mov ecx, 1 repeatagain: add eax, ecx inc ecx cmp ecx, 3 jle repeatagain nop ret i explained little bit confusing hope got point.
all jxx commands check bitstate of special register called "flags". many instructions change state of register indirectly. jxx command takes branch depending on result of last such instruction.
thus order matters here: inc ecx / jle repeatagain branching if (and if) ecx <= 0 after increment (i.e. 2 billions of iterations, until ecx overflowed in highest/sign bit). while cmp ecx, 3 / jle repeatagain branching if ecx <= 3 (i.e. 3 iterations only).
where checking equality before proceeding jumping ?
well, it's cmp ecx, 3 (which sets "flags" state, if you've calculated expression ecx - 3, i.e. ecx - 3 less zero, equal zero, or greater zero?), in fact loop broken "greater" condition. i.e. backward branch not taken when ecx becomes 4.
Comments
Post a Comment