MASM: .IF with signed numbers comparison

时光毁灭记忆、已成空白 提交于 2019-12-11 03:22:30

问题


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:


Shortest solution:

.if SDWORD PTR ecx < 0


来源:https://stackoverflow.com/questions/26535786/masm-if-with-signed-numbers-comparison

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!