A spin-off from the
Comparing 128-bit numbers aka OWORDs thread.Uppercase in flags means "set":
cmp eax, edx
eax -1
edx 1
flags: czSo
ecx -2So far, so clear: Sign? is set, because eax=-1 is obviously below edx=+1
cmp eax, edx
eax -2013265784
edx 1996488823
flags: czsO
ecx 285212689Oops :redface:
eax=-2013265784, edx=+1996488823, and Sign? is clear??
cmp eax, edx
jl IsLower"If eax is below edx, then jump to the IsLower branch"
Nope... the documentation says "cmp sets flags like sub but it doesn't subtract". And eax minus edx is ecx=285212689 in this case, so the cmp says "positive".
I'll add it to
Tips, Tricks & Traps...
include \masm32\MasmBasic\
MasmBasic.inc ;
download Init mov eax, -1
; clearly below zero mov edx, 1
; clearly above zero mov ecx, eax
; create a copy sub ecx, edx
; "cmp with action" cmp eax, edx
deb 4, "cmp eax, edx, result in ecx", ecx, eax, edx, x:eax, x:edx, flags
mov eax, 88000088h
; clearly below zero mov edx, 77000077h
; clearly above zero mov ecx, eax
sub ecx, edx
cmp eax, edx
deb 4, "cmp eax, edx, result in ecx", ecx, eax, edx, x:eax, x:edx, flags
Inkey CrLf$, 'uppercase in flags means "set"'
Exitend start