delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1999/05/13/19:20:28

From: XXguille AT XXiies DOT XXes (Guillermo Rodriguez Garcia)
Newsgroups: comp.os.msdos.djgpp
Subject: Re: asm code
Date: Thu, 13 May 1999 22:56:23 GMT
Organization: Telefonica Transmision de Datos
Lines: 38
Message-ID: <374357ba.9741907@noticias.iies.es>
References: <373B48C1 DOT 1660 AT bellsouth DOT net>
NNTP-Posting-Host: iies249.iies.es
Mime-Version: 1.0
X-Newsreader: Forte Agent 1.5/32.451
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019