News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

.if the problem of conditional expressions

Started by stevenxie, November 19, 2020, 10:43:42 PM

Previous topic - Next topic

stevenxie

Hi,hutch. Can if allow variables or registers to be compared between positive and negative numbers? I wrote the code, but after debugging,. if can only be valid for variable or register comparison within the range of positive or negative numbers.
include \masm32\include64\masm64rt.inc

.data
      int01 dq 1
      int02 dq 2
      int03 dq 3
      int04 dq -45
.code
      entry_point proc

     
     

            mov r12,-18
            mov r13,-8
            .if r12 } r13
           
            printf("\t\t\t\t%ld %ld\n",int03,int04)

           
         
             printf("\t\t\t\t%ld %ld",int01,int02)
           .endif
         


          waitkey
          conout "r12=",str$(r12),lf
          conout "r13=",str$(r13),lf
          waitkey
         .exit

      entry_point endp
end

stevenxie

Hi hutch. I see, I can use CMP、JG、JL、JEQ、JNE、JLE、JGE and other instruction mnemonics to construct my code to achieve conditional judgment control flow function. This is the advantage of pure manual command mnemonics. thorough, deep and straightforward!

include \masm32\include64\masm64rt.inc

.data
      int01 sqword 1
      int02 sqword 2
      int03 sqword 3
      int04 sqword 4
      cmpa sqword -45
      cmpb sqword 45
.code

      entry_point proc

            mov r12,18
            mov r13,-(18)
              cmp cmpb,r13
              jg lb2
              printf("\t\t\t\t%ld %ld\n",int03,int04)
              jmp lb1
           
         
            lb2:
              printf("\t\t\t\t%ld %ld\n",int01,int02)

            lb1:
              waitkey
              conout tab,tab,tab,tab,"r12=",str$(r12),lf
              conout tab,tab,tab,tab,"r13=",str$(r13),lf
              waitkey

            .exit

      entry_point endp
end

stevenxie


hutch--

Hi Steven,

The difference between signed versus unsigned is based on the conditional flags set by a previous action, a CMP or ADD and SUB among others. With numbers in the signed range, there is no effective difference between JA (jump above) and JG (jump if greater) below the half way mark but once you get into the negative number range you must use the correct Jxx (conditional jump) with negative numbers.

stevenxie

Quote from: hutch-- on November 20, 2020, 12:24:19 AM
Hi Steven,

The difference between signed versus unsigned is based on the conditional flags set by a previous action, a CMP or ADD and SUB among others. With numbers in the signed range, there is no effective difference between JA (jump above) and JG (jump if greater) below the half way mark but once you get into the negative number range you must use the correct Jxx (conditional jump) with negative numbers.

dear hutch,thank for you very much! I am very glad tonight. :eusa_boohoo: :skrewy:

stevenxie