我有:
mov ecx, r
.if ecx < 0
mov cl, 0
.elseif ecx > 255
mov cl, 255
.endif
mov [eax + 2], cl
r是有符号整数。我希望它在字节限制内限制它。 但问题是&#34; r&#34;是否定的。它被视为未签名。
Input -> Expected output
r = 300 -> 255
r = 12 -> 12
r = -134 -> 0
What actually happenes:
r = 300 -> 255
r = 12 -> 12
r = -134 -> 255 <--------- Here it gets treated as if -134 is bigger than 255
如何解决?
答案 0 :(得分:3)
最短的解决方案:
.if SDWORD PTR ecx < 0