MASM: .IF with signed numbers comparison

2019-07-20 18:24发布

I have:

    mov ecx, r
    .if ecx < 0
        mov cl, 0
    .elseif ecx > 255
        mov cl, 255
    .endif
    mov [eax + 2], cl

r is signed integer. I want it to cap it within byte limit. But problem is when "r" is negative. It is treated as if it is unsigned.

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

How to fix it?

1条回答
干净又极端
2楼-- · 2019-07-20 18:59

Shortest solution:

.if SDWORD PTR ecx < 0
查看更多
登录 后发表回答