【问题标题】:MASM: .IF with signed numbers comparisonMASM:.IF 带符号数字比较
【发布时间】:2014-10-23 19:23:03
【问题描述】:

我有:

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

r 是有符号整数。我希望它限制在字节限制内。 但问题是当“r”为负时。它被视为未签名。

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

如何解决?

【问题讨论】:

    标签: assembly macros x86 masm masm32


    【解决方案1】:

    最短的解决方案:

    .if SDWORD PTR ecx < 0
    

    【讨论】:

    • 非常感谢陌生人。你让我今天一整天都感觉很好。 :)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-17
    • 1970-01-01
    • 2014-01-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多