Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!mips!pacbell.com!ucsd!ucrmath!rhyde From: rhyde@ucrmath.ucr.edu (randy hyde) Newsgroups: comp.sys.apple2 Subject: Re: Re- HLLs vs. Assembly Message-ID: <13517@ucrmath.ucr.edu> Date: 11 Apr 91 02:35:50 GMT References: <9104110129.AA11471@apple.com> Organization: University of California, Riverside Lines: 39 Another classic example as to why you should know assembly in order to write decent HLL code (in this case Pascal): Most introductory CS texts equate IF..THEN..ELSE IF..THEN..ELSE IF... statements with CASE statements. Many HLL programmers go through life thinking they're equivalent. Sure, logically they do the same thing; reality is another story. In general, they are implemented in completely different ways. The CASE statement uses the index variable as an index into an array of addresses and transfers control to the corresponding location. If..then.. else if... statements work in the obvious fashion. Poor souls who think that these two mechanisms are equivalent are missing out. On the one hand, CASE statements can be *Orders of Magnitude* faster than the IF..THEN..ELSE approach (depending on the number of cases). Unfortunately, the code generated can also be *orders of magnitude* larger if the cases are widely separated. The "abstract model" of the language doesn't consider this important point. In the "abstract model", CASE is logically equivalent to the IF..THEN..ELSE IF approach. Likewise, too many HLL programmers have *no idea* of the performance loss they get hit with when they use 2-D or higher dimension arrays (yeah, C programmers know about this, but C isn't exactly a "high" level language, most properly call it a medium level language). The HLL hides this little detail from them. Had they been forced to indexed into two-dimensional arrays at one point in their lives they would know about this. In one quarter (10 weeks) at Cal Poly or UCR I haven't anywhere near enough time to teach assembly language properly to disinterested students. Out of 30 students, most of them are going to wind up like the dissenting opinion around here because they are not good enough to handle assembly language (that is not to say that the dissenters around here aren't very good, I'm just stating that these students aren't going to be very good and they'll be the first to chime in and knock assembly in the future). Maybe 5-10 students will actually get good at it. Faced with this, I make *damn* sure that if they learn nothing else in the class, they learn exactly what that Pascal compiler is doing for them in terms of Pascal->8086 code generation. That way, even if they never write another line of assembly code in their lives, at least they're (presumably) aware of what the compiler is doing. I consider this the minimum necessary information (concerning assembly) that they possess. *** Randy Hyde