MASM:.IF与符号数的比较 [英] MASM: .IF with signed numbers comparison

查看:235
本文介绍了MASM:.IF与符号数的比较的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有:

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

r被符号整数。我希望它字节的范围内封顶了。
但问题是,当R是负的。它被看作它是无符号的。

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

如何解决?

推荐答案

最短的解决方案:

.if SDWORD PTR ecx < 0

这篇关于MASM:.IF与符号数的比较的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆