Hello. I did the sum and sub. I am happy

How can I know if two numbers are the same

It must return an INT
Int = 1 if they are the same
Int = 0 if are different.
Posted on 2005-04-14 13:25:03 by luise.valencia
compare_numbers proc uses ebx, number_one_value:dword, number_two_value:dword

mov eax,number_one_value
mov ebx,number_two_value

cmp eax,ebx
je theyarethesame

; they arent the same

xor eax,eax
ret

theyarethesame:

xor eax,eax
inc eax
ret

compare_numbers endp

you really should do your own homework though, otherwise you will not learn a damn thing
Posted on 2005-04-14 15:05:32 by evlncrn8
I am learning a lot with you

I am gonna try to comment the code and tell me if I have something wrong

mov eax,number_one_value    'Mov parameter 1 to eax
mov ebx,number_two_value  'Mov parameter 2 to eax

cmp eax,ebx                        'This makes a bit comparison and sets a flag if they are equal right?
je theyarethesame                'This reads that flaf

; they arent the same

xor eax,eax                          'As they are not the same you make an xor, and xor of equal numbers is 0
ret

theyarethesame:

xor eax,eax                            'The same eax = 0
inc eax                                  'eax =1
ret                                        'It returns eax.

compare_numbers endp
Posted on 2005-04-14 15:52:49 by luise.valencia
It dosent return nothing, it only terminate the function and "clean" the stack from the function, if the function that call this function need that the return value is in eax, then you should say more like: Im storing the return value in eax because is a "protocol" I must follow and then Im terminating the function with macro ret.
Posted on 2005-04-14 18:17:26 by rea
I need to return an int.
1 if they are the same
0 if they are not the same

How would it be?
Posted on 2005-04-14 22:04:31 by luisvalencia
In fact the anterior way for write is OK for return a value in your case 0 or 1.

But Im saying that you explanation is a little "bad", tought you have understood, I only whant to "clean" a little more your explanation.

``xor eax,eax                            'The same eax = 0inc eax                                  'eax =1ret                                        'It returns eax.``

You have make "literal" comments, mean taht you have commented what can be watched from the mnemonics, but not the porpuose when you see the porpuose, you will catch that it dosent return eax with ret, but ret is the return point of the anterior secuence of mnemonics.

``xor eax,eax                            ; This two lines, fill the value in eax in concordance with a "protocol" that exist and say that theinc eax                                  ; function that call this function will try access the result of this function in eaxret                                        ; Return to the caller and clean the stack and arguments``

You see ret is not returning the value in eax, because it was filled before. Also when you return ( ret macro in masm ) from the function, you are actually not returning a value, you are returning to the next instruction after the call to this function also "ret" align the stack "cleaning" the locals in the stack and the arguments in the stack if they exist in this call.

Posted on 2005-04-14 23:36:54 by rea
Well its not working

I put an 1 and 1. and it says there anot the same
``SonIgualesFloat proc var1:REAL4, var2:REAL4    LOCAL retval:REAL4    PUBLIC SonIgualesFloat        mov eax,var1	mov ebx,var2	cmp eax,ebx	je theyarethesame	; they arent the same	xor eax,eax	ret	theyarethesame:	xor eax,eax	inc eax	ret            SonIgualesFloat endp``

``void menuSonIgualesFloat(void){     int ch;     float f1;     float f2;     printf("Primer numero\n\n");	 if(scanf("%f",&f1)== 1)	 {           printf("Segundo numero\n\n");	       if(scanf("%f",&f2) == 1)           {            int x;            x = SonIgualesFloat(f1, f2);            if(x == 1)            {                  printf("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();              }   }``
Posted on 2005-04-15 00:11:57 by luisvalencia
The assumption you are making is that different types of NaN are not equal, nor are + and - 0, nor are denormalised zeros.

If you need to guard against these cases, you'll need to do a bit more work.

Mirno
Posted on 2005-04-15 06:44:40 by Mirno

.......
XOR EAX,EAX
MOV EDX,Var1
CMP EDX,Var2
SETE AL                ;EAX=1 if Var1=Var2, else EAX=0
.......
Posted on 2005-04-15 09:37:29 by MikDay
Hm, checking if two floating-point numbers are the same without using FPU... I wouldn't do that. The "correct" way is to subtract the numbers and check whether the result is larger than "some pretty small value", because floating point numbers aren't 100% stable.
Posted on 2005-04-16 08:55:39 by f0dder
It still returns 0 and not 1.

1 and 1 must be the same binary representation so it must return an 1 if same but I still dont get it to work.
`` SonIgualesFloat proc var1:REAL4, var2:REAL4    LOCAL retval:PTR    PUBLIC SonIgualesFloat        mov eax,var1	mov ebx,var2	cmp eax,ebx	je theyarethesame	; they arent the same	xor eax,eax	ret	theyarethesame:	xor eax,eax	;inc eax 	;XOR EAX,EAX    MOV EDX,var1    CMP EDX,var2    SETE AL 	            SonIgualesFloat endp``
Posted on 2005-04-16 09:33:59 by luisvalencia
that last code snip wont return at all, you're missing the ret
Posted on 2005-04-16 12:18:18 by evlncrn8
Perhaps I have confused the guy?? about what is return from function and what is save a value in concordance with a "protocol" and how this combination "makes" the feel to return something from the function?.
Posted on 2005-04-17 10:49:19 by rea
And you need a xor eax, eax (which you missed out).
Posted on 2005-04-17 11:23:30 by roticv

Well its not working

I put an 1 and 1. and it says there anot the same

As a check, have your C code compare and show the actual values of f1 and f2 in hex format. If f1 and f2 are exactly the same, the problem is parameter passing. If it's a problem with parameters, then it's because the compiler is creating double (REAL8) values before passing them to your ASM function. (If the compiler is a C compiler, or a C++ compiler compiling in C mode, this is a rule of C.)
Posted on 2005-04-17 13:24:08 by tenkey