Re: Book on Assembly




santosh wrote:
This is exactly what is done (or, at least, what I do). I'm not sure I
follow what you're trying to say. Obviously, in order to implement
HLL-like control structures with CMP and Jcc, you must first teach them
the semantics of the CMP and Jcc instructions. The next step, before
you let them write a whole lot of code, is to tell them how to use
those CMP and Jcc instructions to simulate an IF statement, or a WHILE
loop, or...

This is exactly what I have in mind, but, surprisingly, you do the
exact opposite in AoA 32 bits. You start with the traditional HLL
control structures, built opaquely into HLA and explanations on using
CMP+Jcc start quite late into the book.

That is a *completely* different issue.
The students already know HLL-like control structures. By letting them
use them during the first few weeks of the course, you get time to
concentrate on other subjects (like machine organization) while still
allowing them to write programs. The bottom line is that this allows
them to write programs their first week in the course and begin
learning about instructions like MOV and ADD, as well as how to use the
compiler, editor, command-line, etc. You cannot simply throw a couple
dozen instructions at students on the first day of class, plus describe
things like numeric representation, memory organization, registers, and
so on, and expect them to start writing programs. This material takes
*weeks* to cover. If you wait until the students have learned enough
about machine organization and the x86 to be able to deal with CMP/Jcc,
then you've lost about 1/3 of the term. I'm a big fan of having the
students start writing code the first week. Yep, it's not *really*
assembly, but it does contain *some* assembly (e.g., some basic
instructions like MOV, ADD, SUB, and so on).

I think you are confusing a pedagogical approach (leveraging HLL
knowledge in an assembly course) with the current debate, which is
don't teach students how to do structured control structures in
assembly language.



Blind use of IF, WHILE, FOR etc., is exactly what the students would
have already learnt, (assuming they took a HLL course). Why repeat the
same with HLA?

Because during the first three or so weeks of the course you don't have
time to cover things like CMP and Jcc. Believe it or not, there is a
*lot* of prerequisite information to cover first. Things like "what is
hexadecimal and binary representation?", "What is a bit, byte, word,
dword, etc.?", "what is a register?", and "how are variables
represented in memory?" No, the students do not come into the class
already possessing this knowledge. Indeed, in the view of most
universities, this is *exactly* the reason they are taking an assembly
course -- to learn this kind of stuff.

The advantage of letting the students use high-level assembly
statements like IF and WHILE is that you can put off the discussion of
CMP/Jcc until later in the quarter, after you've had time to cover the
prerequisite material, yet the students can still be writing programs
from the very beginning. No, a lot of the code they're writing isn't
true assembly; but *some* of it is. This allows them to learn the
material in a gradual basis and get used to assembly language rather
than being hit over the head by it four weeks into the quarter. Having
taught the course both ways, I can attest to the fact that the gradual
approach is *much* better. The average student in the course gets much
farther along by the end of the quarter.


Why not *start* off with CMP and Jcc and encourage the
students to build semantic equivalents of IF, WHILE, FOR, SWITCH etc.,

Read the above. There are too many prerequistes before you get to the
point they can understand things like CMP and Jcc. If every student
came into the course knowing machine organization already, things would
be different. But this isn't the case in most assembly courses I've
taught (though Cal Poly Pomona did have a digital logic course that was
a prerequisite to the assembly programming class that covered a lot of
the machine organization material; that was great, but most schools
don't waste two terms on the subject).


using these? This could start towards the middle of the course, after
the basics have been dealt with.

That's exactly what happens in the courses I've taught -- we get to
control structures after the basics have been dealt with. What you're
not realizing is what those "basics" are; those basics are machine
organization.

Probably what you missed was the original point, which is that students
should *not* be taught about simulating IF/WHILE/etc, that they should
just use the CMP/Jcc paradigm in whatever way comes natural to them
(i.e., arbitrary control structures). I've seen this in action, it is a
disaster.

I would partly agree with the above. Assuming the students are already
proficient with a HLL, I would think that starting off directly with
CMP/Jcc would be better. However, they should *not* be merely left to
implement their own versions of HLL control constructs at their own
leisure. Instead the instructor can *show* them on how to do it in
standard ways, and then let them replicate it themselves. I should
think most students would do reasonably well, and any errant use can be
caught and corrected by the instructor.

Again, I think you're confusing the AoA pedagogical approach with the
topic of this thread. If I understand what you're saying, you're saying
that students shouldn't be taught assembly using HLL-like control
structures such as IF/WHILE/etc., instead, they should be taught
immediately to emulate those statements using CMP/Jcc. That's certainly
a valid opinion and many people subscribe to it. But that's not what is
being debated here. What's being debated is whether students should be
taught how to emulate the control structures at all or if they should
be left to figure out how to achieve what they want on their own.
Having seen what happens in real classrooms, I'm of the opinion that
when you teach students CMP/Jcc, you should be teaching them how to
create structured, non-spaghetti (i.e., reducible flow graph) programs
at the same time. Left to their own devices, chaos usually results.




Now I'm not saying that teaching them to use pre-built versions of IF,
WHILE etc., is bad; repetitive practise is always good in programming.
I just fell that it may be quicker and more efficient to start of with
assembly primitives and build up the HLL controls rather than vice
versa, as you do in AoA (32 bits).

If all the prerequisite material was out of the way on day one and you
started covering the machine instructions on the first day of class,
I'd probably agree with you. But because you don't have time to cover
CMP, Jcc, the flags, the meaning of the flags etc., before covering
other, more important issues (for example, it doesn't make sense to
explain JS and JNS if you haven't explained the difference between
signed and unsigned numbers) and other, more important instructions
(like data movement, arithmetic and logical operations, and a handful
of others). Keep in mind, I taught assembly language the traditional
way about 10 years before I introduced HLA and AoA/32. I'm quite aware
of the strengths and weaknesses of that approach. In the end, though
the AoA/32 students got a little farther into the subject and were
writing better final projects than the students who learned with MASM
and AoA/16.
Cheers,
Randy Hyde

.



Relevant Pages

  • Re: Book on Assembly
    ... in terms of CMP and Jcc. ... HLL-like control structures with CMP and Jcc, ... those CMP and Jcc instructions to simulate an IF statement, ...
    (alt.lang.asm)
  • Re: Book on Assembly
    ... to create their own control structures. ... Some spaghetti is better than some other spaghetti. ... And the spaghetti students write, without having been taught how to ... the classical control structures in assembly language. ...
    (alt.lang.asm)
  • Re: Book on Assembly
    ... that all code exists as some form of spaghetti. ... then the students produce *bad* ... "spaghetti code" implies that the control structures in a program ... decade+ that I taught assembly language at the University level, ...
    (alt.lang.asm)