Author Topic: Unsiged comparison  (Read 5748 times)

Offline TightCoderEx

  • Full Member
  • **
  • Posts: 103
Unsiged comparison
« 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

Offline Gunner

  • Jr. Member
  • *
  • Posts: 74
  • Country: us
    • Gunners Software
Re: Unsiged comparison
« Reply #1 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.

« Last Edit: December 22, 2012, 03:45:08 AM by Gunner »

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2513
  • Country: us
Re: Unsiged comparison
« Reply #2 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


Offline TightCoderEx

  • Full Member
  • **
  • Posts: 103
Re: Unsiged comparison
« Reply #3 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.