Hi All ,

I have a question regarding to if statement ,,,

my question is : How can I compare between 2 values ?!


let's suppose I want to see if (x > y )

print "x greater than y"

if ( x < y )

print "y greater than x"


Please help to do this ,,,


Thank you

Most processors have a 'cmp' instruction to compare things.
Look it up in your processor reference manual.

Thank you guys for ur reply


I did the cmp but still it didn't work


here in the following code , I'm trying to make simple code which make a compression between the input number with zero ,,, I think I did every thing right but when I compile it , it always gives "This number is greater than 0" , even I put it -5 or any negative number


Could please help me ?!!!

.386
.MODEL FLAT

INCLUDE io.h

ExitProcess PROTO NEAR32 stdcall, dwExitCode:DWORD

cr            EQU    0dh   ;  
Lf            EQU    0ah   ;  



.STACK  4096             ;  

.DATA                    ;  

Array       DWORD      count DUP (?)

direction   BYTE  cr,Lf,Lf, "This program design to cmpare between two values:"

prompt      BYTE    cr,Lf,Lf,  'Please insert your number :',0
grades      BYTE     16 DUP (?)



value        BYTE    16 DUP (?)
ACount       BYTE     cr,Lf,Lf,' This number is greater than 0'    ; display the As number
result_1     BYTE    11 DUP (?)
             BYTE    cr, Lf, 0
      

        
BCount       BYTE     cr,Lf,Lf,' This number is less than 0 '    ; 
result_2     BYTE    11 DUP (?)
             BYTE    cr, Lf, 0



.CODE
_start:

            output direction         	;  
            

            output prompt           	;  
            input  grades,16        	;  

            atod   grades           	;  
    
            cmp   grades    , 0            ;  

           jle     BsCount  
           jge    AsCount 


AsCount:    
            dtoa    result_1,  eax        ;  
           output   ACount          ;  
           jmp      quit
BsCount:    
           dtoa    result_2,  eax        ;  
           output  BCount          ;  
           jmp     quit

         


quit:       INVOKE ExitProcess, 0      		 			; exit with return code 0

PUBLIC _start                          		 		; make entry point public

            END                        		 		; end of source code

> cmp grades , 0
You're comparing the function address itself with 0, not the result it returned in the previous line.

Hi salem


Could u please explain more ?!


I 'm trying to compare the input that I entered with zero ...

What does atod do?
Does it return a result, and if so, how?
Are you comparing with that result?

This article has been dead for over six months. Start a new discussion instead.