NASM - The Netwide Assembler

NASM Forum => Programming with NASM => Topic started by: TightCoderEx on December 22, 2012, 02:55:07 AM

Title: Unsiged comparison
Post by: TightCoderEx on December 22, 2012, 02:55:07 AM
Seems I can never find the information when I'm looking for it.

1: Are JB & JA proper opcodes for comparing unsigned values
2: Is there a better way to set ZF = 1, other than exclusive oring AH.

Code: [Select]
          ret ; RAX = Converted value or Error Code.

; Determine if AL is a digit.
; If false ZF = 0 and AL unmodified
; If  true ZF = 1 and AL MSB striped

      .IsDigit cmp al, '9'
      ja $ - 3
      cmp al, '0'
      jb $ - 7
      and al, 15
      xor ah, ah
      ret
Title: Re: Unsiged comparison
Post by: Gunner on December 22, 2012, 03:41:58 AM
The values below zero, are negative values, Jump if Below will not work, instead you need to use Jump if Signed

Most arithmetic such as add, sub, inc, dec, sar, sal and bitwise operations such as test, shl, shr, or, neg etc... modify the ZF.  XOR modifies the regsiter, maybe that is not what you want, instead use test reg, reg which does not modify the register but the EFLAGS.

All information is in the INTEL and AMD developer manuals

*** Edit ***
Just realized your not comparing 0 but instead, the ascii zero.

Title: Re: Unsiged comparison
Post by: Frank Kotler on December 22, 2012, 05:26:22 AM
I think "jb" and "ja" are fine. I question where those jumps are supposed to go. Labels - even meaningful labels - are free, y'know. :)

Best,
Frank

Title: Re: Unsiged comparison
Post by: TightCoderEx on December 22, 2012, 05:09:39 PM
Labels - even meaningful labels - are free, y'know. :)

I generally use labels, especially where offsets aren't immediately obvious. Hopefully I don't move RET immediately before .IsDigit, that could cause some interesting problems.