Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!seismo!ll-xn!ames!amdahl!amdcad!tim From: tim@amdcad.AMD.COM (Tim Olson) Newsgroups: comp.misc Subject: Re: Assembly Language Message-ID: <17981@amdcad.AMD.COM> Date: Thu, 20-Aug-87 18:39:22 EDT Article-I.D.: amdcad.17981 Posted: Thu Aug 20 18:39:22 1987 Date-Received: Sat, 22-Aug-87 12:13:44 EDT References: <892@edge.UUCP> <1305@faline.bellcore.com> Reply-To: tim@amdcad.UUCP (Tim Olson) Organization: Advanced Micro Devices, Inc., Sunnyvale, Ca. Lines: 45 In article <1305@faline.bellcore.com> gtchen@faline.UUCP (George T. Chen) writes: +----- |But I'm sure the actual piece of executable code in orders of magnitude |smaller than the equivalent C program. Also, I've assumed that since you |did the program in assembly, then it will probably run faster. For that |matter, any program done in any HLL can be done in assembly and made to |run as fast if not faster. +----- Only if the person writing the assembly language is very good. The new highly-optimizing C compilers are becoming *very* good at what they do. For example, one compiler I am familiar with compiled the code fragment: if (x[i] > x[i+1]) { temp = x[i]; x[i] = x[i+1]; x[i+1] = temp; } to: const base, _x ; calculate address of x[i] consth base, _x sll temp, i, 2 add base, base, temp load val1, base ; get value of x[i] add base2, base, 4 ; calculate address of x[i+1] load val2, base ; get value of x[i+1] cpgt temp, val1, val2 ; perform "if" jmpf temp, $endif nop store val1, base2 ; swap operands store val2, base Note that the compiler optimized the array calculation expressions to reuse a common sub-expression (x[i]), and that it totally optimized away the temp variable used to swap the values! I don't think you could write it in assembly language any better than that. -- Tim Olson Advanced Micro Devices (tim@amdcad.amd.com)