Author Topic: .if the problem of conditional expressions  (Read 1201 times)

stevenxie

  • Member
  • **
  • Posts: 55
.if the problem of conditional expressions
« on: November 19, 2020, 10:43:42 PM »
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

  • Member
  • **
  • Posts: 55
Re: .if the problem of conditional expressions
« Reply #1 on: November 20, 2020, 12:06:17 AM »
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

  • Member
  • **
  • Posts: 55
Re: .if the problem of conditional expressions
« Reply #2 on: November 20, 2020, 12:12:45 AM »
Console program execution results.

hutch--

  • Administrator
  • Member
  • ******
  • Posts: 10294
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
Re: .if the problem of conditional expressions
« Reply #3 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.
hutch at movsd dot com
http://www.masm32.com    :biggrin:  :skrewy:

stevenxie

  • Member
  • **
  • Posts: 55
Re: .if the problem of conditional expressions
« Reply #4 on: November 20, 2020, 12:40:59 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

  • Member
  • **
  • Posts: 55
Re: .if the problem of conditional expressions
« Reply #5 on: November 20, 2020, 12:47:16 AM »
MASM64 SDK is SO GREAT!!!