Mail Archives: djgpp/1999/05/13/19:20:28
El día Thu, 13 May 1999 17:48:49 -0400, seth <sethpark AT bellsouth DOT net>
escribió:
>Hello, I just started trying to learn Assembler.
>I have a few questions....
>Is adding/subtracting ect. necessarily alot faster in Asm than in C?
>Such as:
> mov ax, 5
> mov bx, 5
> add ax, bx
>
>Would that be faster than
>
> int one, two;
> one+=two;
Not usually. The compiler will optimise the code as much as possible,
and many times this means that it will optimise it more than you.
>Also, could someone give me some example code on how to add four numbers
>and find the average with Asm?
Using Intel syntax (the same you used above, which is NOT the one that
djgpp will understand : AT&T) and assumming that the four numbers are
integers that can be added into a 32 bit register without overflow:
mov eax, number1
add eax, number2
add eax, number3
add eax, number4
shr eax, 2 ; same as divide by 4
Regards,
GUILLE
----
Guillermo Rodriguez Garcia
XXguille AT XXiies DOT XXes (ya sabes :-)
- Raw text -