if clause not working as I expect.

This is a discussion on if clause not working as I expect. within the C Programming forums, part of the General Programming Boards category; Hello. I have a function in assemby that returns an 1 if the numbers are the same and 0 if ...

  1. #1
    Registered User
    Join Date
    Apr 2005
    Posts
    13

    if clause not working as I expect.

    Hello. I have a function in assemby that returns an 1 if the numbers are the same and 0 if the numbers are not the same.

    I print the variable before the IF clase and Its returning 1 if same and 0 if not same but its always going to the else clause and not the if clause.

    This is my C Code.


    Code:
    void menuSonIgualesFloat(void)
    {
         int ch;
         float f1;
         float f2;
         printf("--------------------Funcion Son Iguales Float------------------\n");
         printf("Entre Primer numero:");
    	 if(scanf("%f",&f1)== 1)
    	 {
               printf("Entre Segundo numero:");
    	       if(scanf("%f",&f2) == 1)
               {
                int y;
                y = SonIgualesFloat(&f1, &f2);
                printf("Resultado de la funcion es: %d\n", y);
                
                if(y == 1)
    
                {
    // ITs not STEPING INTO HERE. 
                     printf(" Los Numeros Son Iguales");
                } 
                else
                {
                      printf(" No Son Iguales");
                }
                
               } 
               else
               {
                   printf("Datos incorrectos");
               }               
         }
         else
         {
              printf("Datos Incorrectos, debe usar el punto para la separacion de decimales");     
         }
    
    	while ( (ch = getchar()) != '\n' && ch != EOF) ;
    
    	printf("\n\nPress ENTER to continue.");
    	while ( (ch = getchar()) != '\n' && ch != EOF)
    ;
       if(ch=='\n' || ch==EOF)
       {
          printmenu();           
       }
       
    }
    This is my assembly funcion

    Code:
    SonDiferentesFloat proc var1:REAL4, var2:REAL4
        PUBLIC SonIgualesFloat
        
        mov eax, [var1]
        mov eax, [eax]
    	mov ebx, [var2]
    	mov ebx, [ebx]
    	
    
    	cmp eax,ebx
    	jne theyarenotthesame
    	;they arent the same
    
    		xor eax,eax		
    		ret
    
    	theyarenotthesame:
    	
    		xor eax,eax
    		inc eax
    		ret    
    SonDiferentesFloat endp
    
    end;

  2. #2
    Registered Trademark
    Join Date
    Apr 2005
    Posts
    19
    problems like these happen to me also. I work around them with a
    Code:
    do { } while() { }
    more explanation of these clauses are on the internet.

    pointers also can be used along with for loops and more. just get creative

  3. #3
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Quote Originally Posted by Fender Bender
    problems like these happen to me also. I work around them with a
    Code:
    do { } while() { }
    more explanation of these clauses are on the internet.

    pointers also can be used along with for loops and more. just get creative
    I'm not sure what you're trying to state above here, but your do-while syntax is askew.
    Code:
    do
        ...this...
    while( ...this test is true... )
    The second pair of braces you have are not included in anything to do with the do-while loop. They'd be something that always happens as soon as the do-while is done, no matter what. They wouldn't be a part of the loop itself:
    Code:
    do
    {
        ...this happens every time through the loop...
    }
    while( ...this is true... )
    {
        ...this happens after the loop is done, no matter what...
        ...the braces don't do anything except define a new scope block...
    }

    Quzah.
    Last edited by quzah; 04-16-2005 at 05:23 PM. Reason: Fixing an apparent forum bug with the color magenta??
    Hope is the first step on the road to disappointment.

  4. #4
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,417
    > This is my assembly funcion
    Why on earth is this in ASM?

    You're not going to get past the problems of comparing two FLOATS for equality (see many previous posts on this topic) simply by coding in assembler.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  5. #5
    Registered User
    Join Date
    Apr 2005
    Posts
    13
    because I want to learn assembler linked to C.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Function not working
    By sloopy in forum C Programming
    Replies: 31
    Last Post: 11-12-2005, 07:08 PM
  2. Program Not working Right
    By raven420smoke in forum C++ Programming
    Replies: 2
    Last Post: 09-16-2005, 03:21 AM
  3. Trying to eject D drive using code, but not working... :(
    By snowfrog in forum C++ Programming
    Replies: 3
    Last Post: 05-07-2005, 07:47 PM
  4. x on upper right corner not working
    By caduardo21 in forum Windows Programming
    Replies: 1
    Last Post: 02-20-2005, 07:35 PM
  5. cygwin -> unix , my code not working properly ;(
    By CyC|OpS in forum C Programming
    Replies: 4
    Last Post: 05-18-2002, 04:08 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21