Author Topic: comparing two numbers  (Read 6363 times)

minomic

  • Guest
comparing two numbers
« on: May 09, 2013, 09:10:38 PM »
Hi guys, first of all forgive me if my English is not perfect but this is not my first language.
Anyway what I'm trying to do is just comparing two numbers. More precisely I have to verify that a number is less than or equal to 64000. What I'm doing is reading the string typed by the user and converting it into a number (this should be OK since I make it display the number after conversion and it is always right) stored in NUM, defined as

Code: [Select]
NUM               DW    0
Then I try to compare this number with 64000 by doing this:

Code: [Select]
MOV   AX,NUM
CMP   AX,NUM_MAX
JLE   NO_ERR_SUP
CALL  ERR_SUP
JMP   START
......

where NUM_MAX is defined as

Code: [Select]
NUM_MAX           DW    64000
The problem is it (rightly) accepts 45678 but not 34 or 100. After some tests I found out that the smallest number accepted is 32768 which is 2^15.
How can I solve this?
Thank you!

jj2007

  • Member
  • *****
  • Posts: 9630
  • Assembler is fun ;-)
    • MasmBasic
Re: comparing two numbers
« Reply #1 on: May 09, 2013, 09:21:10 PM »
JLE does a signed comparison, so 32768 is negative.
jae does unsigned comparison, so 32768 to 65535 are positive.

minomic

  • Guest
Re: comparing two numbers
« Reply #2 on: May 09, 2013, 09:32:20 PM »
Thank you very much, I don't know how I could miss that!  :icon_redface:
In fact I had understood that it had something to do with the first byte but couldn't solve the problem.
Thank you again!