Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!seismo!mcvax!enea!diab!pf From: pf@diab.UUCP (Per Fogelstrom) Newsgroups: comp.misc Subject: Re: Assembly Language Message-ID: <300@diab.UUCP> Date: Mon, 24-Aug-87 05:24:03 EDT Article-I.D.: diab.300 Posted: Mon Aug 24 05:24:03 1987 Date-Received: Thu, 27-Aug-87 07:18:24 EDT References: <892@edge.UUCP> <1305@faline.bellcore.com> <17981@amdcad.AMD.COM> Reply-To: pf@.UUCP (Per Fogelstrom) Organization: Diab Data AB, Taby, Sweden Lines: 98 Summary: After 17 years, i vote for HLL. In article <17981@amdcad.AMD.COM> tim@amdcad.UUCP (Tim Olson) writes: > >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. Oh dear! This really confirms what i allways suspected about risc cpu's. Very happy that i've givi'n up ass'(mbly) programming :-))))). This example should really scare away the "assembly programmers"! TWELVE !! instructions for doing something that should not take more than FIVE !! And keeping track of the register contents even if they have mnemonic names! I have tested the example on our own C-compiler genereating code for the famous (:-)) NS32000 cpu, and it throws this out: cmpd 4(r1)[r0:d],r1[r0:d] bge donotdothis movd r1[r0:d],r2 movd 4(r1)[r0:d],r1[r0:d] movd r2,4(r1)[r0:d] Before You start to flaming me about performence; I just wanted to show the difference between a risc and a cisc's solution to the same HLL code. I think my example is easier to read, but it does not justify that it should be written in assembler rather than C. A bad compiler should not justify writing a program in assembly. Even if the generated code size sticks in your eyes. The extra time spent on writing the same program in assembly is a waste, unless there are aspects of performence put into it. Compilers improve (mostly) and if you are lucky, you might be able to recompile the program with a better compiler later. (I've been using the first 'PLM' compiler for the i8008 and i8080. It was a terrible thing. It was trying to drown the programmer in machine code. BUT! it improved, generating better code, and fewer bugs !). I have seventeen(17) years of experience in assembly programming. (My first on an IBM 1401, if that can be called assembly :-)). I have worked with the development of three real time operating systems, the last one a UN*X SV compatible and in "C". I've spent a whole summer squezing 6 kbytes out of a 20 kbytes basic interpreter for a PC (and that before the IBM era).. Guess how that code looked after that :-).So i think i have a pretty good idea about the difference between assembly and HLL. So let the suicide-makers program in assembly, even if they don't have to. I don't bother unless i have to maintain any of their code. Conclusion: One should have *very* good reasons (read "very high speed requirements") for using assembly. People defending assembly for large programming projects does'nt belive in porting. The just belive that there is only one kind of cpu type on the market. Programmers should spend more time on writing comments explaining what the program does and how, than writing "clever" assembly code that no one exept an "expert" can understand. Using the same time effort for writing the same program in assembly and in some HL- language "should" produce a better documented program in HLL. AND REMEMBER !!!!!!! NO PROGRAM LANGUAGE IS SELF-DOCUMENTING !!!! How understandable and maintinable a program is, depends *ONLY* on how good the documentation is. Nonsens comments like "moving this data here and that data there" is not documentation, it's filling. Explain *WHY* i'ts moved etc.! ** ASK ME ! I WILL SHURLEY VOTE FOR HLL ** -- Per Fogelstrom, Diab Data AB SNAIL: Box 2029, S-183 02 Taby, Sweden ANALOG: +46 8-7680660 UUCP: seismo!mcvax!enea!diab!pf