Re: HLA v1.86 is now available




Herbert Kleebauer wrote:

I don't understand why the output has to be in decimal instead
of the simpler hex format, but anyway, let's take a closer look:

Uh, because during that first week the students probably don't even
*know* what hexadecimal representation is.


Let's start with the instructions Evenbit used in his example:
move, add, addc and bsr (to call the external functions getc,
putc and exit).

These are not sufficient to write your own integer to string conversion
routine. Even if they were, students in a typical assembly course
generally don't have the algorithmic background to write such a routine
on their own.

I already showed a program to add two decimal
digits using only this four instructions.

I'm not sure exactly what you mean by this statement. Certainly adding
two integer values is a first-week kind of project. But the whole
concept of "decimal digits" in your discussion assumes that students
understand what a decimal digit is. That's not something they're going
to be prepared to deal with after one or two lectures at the beginning
of a typical assembly language course.


Because the students
also have to learn the other instructions, let us add a few of
them:

And then add a few more, and a few more.
This is all fine, but the students can't pick all this up
instantaneously. And there is a lot more to learn in an assembly
language programming course than machine instructions. Unfortunately,
most of that information (e.g., machine organization) needs to be
taught at the *beginning* of the course. When do they learn about
hexadecimal representation, for example? About registers? About memory
organization? Generally, they have to have a decent handle on all
these subjects before they're ready to master a lot of machine
instructions, and certainly before they write a function like puti.


They already know the instruction to call a subroutine,

Really? When did they learn this? Was this something they already knew
coming into the course? In one respect, you're right -- they do know
how to call a subroutine, if they call it the same way they did in
their HLLs. That's why HLA is so useful at the beginning of an assembly
language course -- they can call a subroutine using syntax that is
almost identical to what they were using in C++ or Java in their
prerequisite courses. This saves them the pain of having to learn about
the stack, the call instruction, the return instruction, and how to
pass parameters to that subroutine during the first few weeks of the
course when they are busy learning machine organization and other
preliminary subjects.

so now we also add the instruction to return from a subroutine
(rts) so we not only can use the given subroutines (getc, putc, exit),
but also can write our own subroutines.

Yep. But that occurs later in the course. See the comments above.

We also add a branch instruction
(br) so we not only can use sequential code.

Oh, and let us not forget the 16 conditional branch instructions.
And don't forget the CMP instruction. Oh yes, let's not forget that the
students have to learn a whole new programming paradigm to effectively
use these instructions to solve problems. Yep. This is definitely a
first or second week project we've got here.


And because they already
know about the carry flag (from the addc)

Of course, if they know about the carry, they also know about the zero
flag, the overflow flag, and the sign flag (which implies that they
know about concepts like two's-complement arithmetic). Yes, siree,
they've pick up all of this during the first week or two of the course.

we also add the conditional
branch instructions which depends on the value of the carry flag
(bcc, bcs).

As I said earlier, 16 new instructions.

This additional instructions shouldn't be hard to
understand and we now have a total of 8 instructions:

Learn to count. Jcc along is actually *16* different instructions. And
that's not counting the synonyms like JA, JAE, JB, JBE, JE, JNE, and so
on.


move: copy data
add: addition
addc: addition with carry
bsr: branch to subroutine
rts: return from subroutine
br: branch
bcc: branch if Carry is clear (execute the next instruction if Carry is not clear)
bcs: branch if Carry is set (execute the next instruction if Carry is not set)

With this 8 instructions the students should be able to write
there own decimal output routine.

Well, it *really* helps to have div in there, too. But let's say that
these eight instructions are enough. What about all the prerequisite
material? Like a discussion of registers, memory, numeric
representation, addressing modes, ... (the list goes on and on)?

Obviously, you have no experience teaching students assembly language
or you'd know that you can simply throw "8 instructions" out and expect
the students to be able to write *anything*, much less a decimal
conversion routine.


And if they are not able to
understand this 8 instructions, then they are also not able
to write a program which needs your pre written output routine
for output.

That's where you're wrong. You see, the difference between your
approach and the AoA/HLA approach is that you throw out a *ton* of new
concepts that the students have to master, including a brand new
programming paradigm. Me? I say "well, you already know how to print
numbers in C++ or Java, so we'll use a scheme that is *very* similar in
assembly language to do the same thing." Yeah, they have to learn a
tiny bit of new syntax (stdout.put rather than printf, for example),
but the concepts are all the same, the paradigm is still the same.
IOW, I *leverage* their existing knowledge so they can, in a few
minutes in their first lab, write a "Hello, World!" program or print
the sum of two integers. My way is laboratory tested. It works and it
works well. Your way? Well, it's a very typical suggestion from someone
who has never taught a class and has forgotten all the prerequisite
knowledge they had to obtain before they were capable of writing
anything at all in assembly language.



Here a possible solution:

And following are my annotations to your code:


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
move.l #0,r1

What is a register? What is a ".l" object?

bsr.l out_dec_r1

To use bsr, the students better know about the stack.
Also, how are the parameters passed to this subroutine. I.e., the
students expect to be able to pass the parameters in a parameter list,
just like their HLLs; you've got to spend time explaining how to pass
parameters in registers, and *which* registers (i.e., why not r0?),
before they can write code like this.



move.l #1,r1
bsr.l out_dec_r1

move.l #1234567890,r1
bsr.l out_dec_r1

Same comments as above.


move.l #$ffffffff,r1
bsr.l out_dec_r1

What is this $FFFFFFFF stuff? Don't forget, students in your course
don't know about hexadecimal representation yet. Of course, you'll
probably want to teach them about binary and other radixes at the same
time. They don't need that information for this project, but generally
it makes sense to teach them about numeric representation all in one
unit. And that consumes more time.


bsr.l exit



out_dec_r1:
move.l #-1000000000,r2

Are these binary numbers I see? If so, you'd better have taught them
about this.

bsr.l _100
move.l #-0100000000,r2
bsr.l _100
move.l #-0010000000,r2
bsr.l _100
move.l #-0001000000,r2
bsr.l _100
move.l #-0000100000,r2
bsr.l _100
move.l #-0000010000,r2
bsr.l _100
move.l #-0000001000,r2
bsr.l _100
move.l #-0000000100,r2
bsr.l _100
move.l #-0000000010,r2
bsr.l _100
move.l #-0000000001,r2
bsr.l _100
move.b #13,r0
bsr.l putc

What's a ".b" object?

move.b #10,r0
bsr.l putc
rts.l

Of course, to know about bsr and rts, they'd need to be taught about
the stack.




_100: move.b #'0',r0
_20: move.l r1,r3
add.l r2,r1
bcc.b _10
add.b #1,r0
br.b _20
_10: move.l r3,r1
bsr.l putc
rts.l

Although you've demonstrated that you can do a numeric conversion
without a div instruction, the above is an *incredibly* bad algorithm
to do this job. The last thing you want to do with students early in
their education is teach them *really bad* algorithms such as this one.
If you do that, then they'll wind up believing this is the way such
code would be written for the remainder of their careers. This is just
*bad* pedagogy. And you don't resort to bad pedagogy just so you can
get the students to do something a little bit sooner than they
otherwise would be able to. Better to just *give* them a decent puti
routine they can call and use different projects that teach them the
right way to do things.


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

And again, this is not obsolete DOS code,

Who said anything about DOS?

but pure CPU
instructions. It becomes OS dependent only, when you
add the external functions getc, putc and exit.

And the point I'm making is that you add the external function puti and
the students can start printing numeric data in their first laboratory
session. Something they're *not* going to be able to do with your "8
instructions puti" (which is really something like 23 instructions).





Then in a next step add the push and pop instructions, the
sub and at least two logical (and, not) instructions and
they will be able to write any subroutine they need for
learning assembly programming themselves after the first
week of the course.

Go ahead. Teach a course sometime. I would *love* to see what the
students thought of your course if you expect them to master all the
material needed to write your routine in one week (which, remember, is
*12 hours* of their time for your course).

Of course, I know how your course would go. You'd hand the students the
Intel manual on the first day and tell them they're on their own. Yep,
I'd bet the reviews on that class would be stellar :-)
Cheers,
Randy Hyde

.



Relevant Pages

  • Re: HLA Stdlib v2.2 is now available.
    ... But HLA was written so Randy could teach assembly language ... long time to wait) If not all students make the "descent"... ... The first four chapters really aren't about programming. ... various machine instructions that allow them to learn the basic x86 ...
    (alt.lang.asm)
  • Re: Teaching Assembly Language Programming
    ... focusing on learning assembly language. ... distraction for many students: nightly keggers. ... programming projects around the things I wanted the ... The chapter on floating-point instructions would deprecate the use ...
    (alt.lang.asm)
  • Re: Why I stop attacking HLA
    ... To me using instructions like cmp and the basic jcc is pure logic, ... You can always *push* one subject ... You should not explain so many instructions without giving students the ... > past when using MASM or some other x86 assembler. ...
    (alt.lang.asm)
  • Re: Why I stop attacking HLA
    ... mastering other concepts in assembly language (such as how to do ... students crying about "busy work" and nonsensical assignments because ... instructions, then they're going to be more ... far as when they've started with a high-level assembler. ...
    (alt.lang.asm)
  • Re: PwrPts WordArt SaveAs (for JPG & BMP) changes BkGnd to BLACK
    ... the instructions were dated for Feb of 2002 (actually evolved earlier but we ... The instructions (made for many students to use, ... there is a problem (the black background thing) and you ... I would like to suggest that the JPG save should behave as I have suggested ...
    (microsoft.public.powerpoint)