polas
Posts: 33
Joined: Tue Jan 15, 2013 9:52 am

Assembly - any use in teaching it?

Fri Feb 08, 2013 11:18 am

As a follow on from the BASIC thread, an interesting debate has been going on about the merits of teaching assembly language - which isn't entirely off topic because some flavours of BASIC readily support mixing this in amongst the higher level code.

Whilst it can on the one hand provide a more complete view of how machines work and code is executed, do people think there is there really sufficient merit to teach programming in depth at the lower levels?

Bearing in mind that a good proportion of those people learning to code on the RPi today will become tomorrow's software engineers, and likely be programming in some higher level language; Do people think that by learning assembly code these people would have a significant advantage over those who come straight in at the higher level?

Or alternatively, could teaching at this lower level in fact ever be harmful to one's ability to formulate and write maintainable, efficient solutions to problems?

User avatar
RaTTuS
Posts: 10455
Joined: Tue Nov 29, 2011 11:12 am
Location: North West UK

Re: Assembly - any use in teaching it?

Fri Feb 08, 2013 11:37 am

learning assembly is very very useful as it gives people an understanding of machines at a low level,
the programmers of tomorrow may well not use assembly but if they don't think at a low level to some extent you'll end up the same as now where all they can do is move some figures in excell or pixels around in photoshop ...

teaching should be done both from a bottom up and top down....
How To ask Questions :- http://www.catb.org/esr/faqs/smart-questions.html
WARNING - some parts of this post may be erroneous YMMV

1QC43qbL5FySu2Pi51vGqKqxy3UiJgukSX
Covfefe

polas
Posts: 33
Joined: Tue Jan 15, 2013 9:52 am

Re: Assembly - any use in teaching it?

Fri Feb 08, 2013 12:01 pm

RaTTuS wrote:If they don't think at a low level to some extent you'll end up the same as now where all they can do is move some figures in excell or pixels around in photoshop
What I am wondering is whether or not it is all or nothing - for example there are probably plenty of Java programmers, DBAs etc out there who have well paid jobs and might have never studied assembly code in any/much detail. But if they had, would it make any difference to them in the current, technical, careers?

User avatar
joan
Posts: 14251
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Assembly - any use in teaching it?

Fri Feb 08, 2013 12:09 pm

I'd say not at school. The kids there who were interested would already have learned it themsleves.

At University, Yes. If only the lessons needed to learn a basic understanding of parameters and how they might be passed.

Of course this is all predicated on the pupils having become literate!

ShiftPlusOne
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 5951
Joined: Fri Jul 29, 2011 5:36 pm
Location: The unfashionable end of the western spiral arm of the Galaxy

Re: Assembly - any use in teaching it?

Fri Feb 08, 2013 12:23 pm

What do you believe and what are your reasons for believing it?

You could make one of these threads for each programming language out there and get a lot of responses, but I don't see what the point is. It would be another thing if you provided your own opinions on the matter first.

User avatar
rurwin
Forum Moderator
Forum Moderator
Posts: 4258
Joined: Mon Jan 09, 2012 3:16 pm
Contact: Website

Re: Assembly - any use in teaching it?

Fri Feb 08, 2013 12:40 pm

Personally, speaking as someone who got into CS earlier than the PC revolution, I don't think in the present situation that an in depth study of ARM or x86 assembler should be undertaken in schools. Once, and if, the pupils get an early introduction to programming, then they may be ready for assembler in some form before they leave secondary education.

On the other hand a simplified assembler based on emulators would be appropriate -- something like Little Man, or maybe something a little more realistic. For more advanced students toward the end of secondary education, maybe a very orthogonal instruction set such as PDP11 could be used. The Arduino could be a good tool, since the AVR instruction set is highly orthogonal. On the other hand ARM assembler with complex addressing modes and OOE seems a step too far. Similarly x86 with it's complex non-orthogonality, is horrible to write for.

Our O-level course included MINI: a one-address, one-accumulator assembler language with no indexing, indirection or subroutines. We didn't get into machine code. That was probably right for most of the students at the time. We hadn't even met a computer until we were 14, much like the students of today who, although they use them every day, have as little idea about how to program them as we did.

Of course there will always be the bright, engaged student who will study subjects beyond the curriculum, and for them the above argument doesn't hold. Such students can get into real assembler as and when they want; the tools are available.

mikerr
Posts: 2778
Joined: Thu Jan 12, 2012 12:46 pm
Location: UK
Contact: Website

Re: Assembly - any use in teaching it?

Fri Feb 08, 2013 12:53 pm

The problem with some/many programmers taught exclusively in JAVA/ high level OOP is that they often have no idea of efficiency.
(I've employed them!)

I've seen some horrible code with an object for everything and slow loops where speed increases of 10-100x (or 10x less memory usage)
can be made simply by rewriting it.

This might also be a product of computers being "so fast" nowadays.

Exposing students to low level/assembly gives them a better feel of how things happen in the background,
and can transfer to better techniques when using other languages.

In short I think assembly should be taught at some point - but not as a first language,
since it requires so much code to achieve the same results.
A first language should be quick to get results, and be one to train the logical mind.
Android app - Raspi Card Imager - download and image SD cards - No PC required !

User avatar
morphy_richards
Posts: 1603
Joined: Mon Mar 05, 2012 3:26 pm
Location: Epping Forest
Contact: Website

Re: Assembly - any use in teaching it?

Fri Feb 08, 2013 12:54 pm

I hear people saying Arm assembly is relatively simple .
I would be interested in seeing if somebody can make a few exercises ( perhaps worksheets?) that could be used as introductions.

Maybe something like simple mathematical functions on values in memory registers and display the output as LED's on the GPIO?

Perhaps something like a very simple calculator using switches and LED's

set a number and store.
set an operator (+ or - (or * or /)) and store.
set another number and store.
Calculate.
Output answer

I do think this would be a useful exercise.
It gives context to the idea that C programs get compiled into this and python programs get interpreted into (something like) this.
Nothing gives understanding like seeing it for yourself.

User avatar
Jim JKla
Posts: 2218
Joined: Sun Jan 29, 2012 11:15 pm
Location: Newcastle upon Tyne UK

Re: Assembly - any use in teaching it?

Fri Feb 08, 2013 1:17 pm

This is like those who argue against learning dead languages like Latin, Ancient Greek etc.

There will be a degree of understanding from looking at Assembler if for no other reason than to demonstarate the differences betweel using a Lower or Higher level language.

I personally doubt there was ever a better placed computer for loking at Assembler, or even Machine code.

This is a computer that is cheap and can do code from MC through Assembler and Python and C to Scratch and Basic.

There is no reason to make any computer language "persona non grata" ;)
Noob is not derogatory the noob is just the lower end of the noob--geek spectrum being a noob is just your first step towards being an uber-geek ;)

If you find a solution please post it in the wiki the forum dies too quick

polas
Posts: 33
Joined: Tue Jan 15, 2013 9:52 am

Re: Assembly - any use in teaching it?

Fri Feb 08, 2013 1:21 pm

ShiftPlusOne wrote:What do you believe and what are your reasons for believing it?

You could make one of these threads for each programming language out there and get a lot of responses, but I don't see what the point is. It would be another thing if you provided your own opinions on the matter first.
A good point - maybe it should have been called "Lower level programming" rather than being assembly specific.

The reason I raise this is because, as I said, on the BASIC thread there are some people adamant that assembly should be taught pretty early on in someone's programming education and some that are against this. Reading this, it made me consider whether learning how to program and what we teach can be considered fundamentally different between using a high level language and a lower level one. Also whether it might be easier to move between languages "horizontally" in the specific generation levels that an individuals have been taught rather than "vertically." Although in practice I am not sure that categorisation is that neat. I wonder if learning how to code "well" in a higher level language translates at all to being able to code "well" in a lower level language and vica-versa.

My personal opinion is that for the vast majority of people who we can hope to enthuse in programming, then going from a language where they can get (reasonably) fast and impressive results to one which requires far more discipline and understanding might act to put them off. For the average person, then it might be worth spending their time learning how to structure and write well maintainable solutions to problems in languages that they are likely to use in their future career; which is more likely to be higher levels ones. Not least because I think that a number of people currently coming into graduate SE jobs need quite a lot of mentoring to get their coding up to an acceptable standard. As people have said, those with above average ability are more likely to investigate lower level languages on their own at some point.

But that is just my current way of thinking and I can certainly see the flip side in terms of concentrating on one class or generation of language might be short sighted and making assumptions like I have above might not make full use of some people's potential. This is why I am interested in other people's thoughts and anecdotal evidence to either support or disprove my current view on things and generate some discussion.

ShiftPlusOne
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 5951
Joined: Fri Jul 29, 2011 5:36 pm
Location: The unfashionable end of the western spiral arm of the Galaxy

Re: Assembly - any use in teaching it?

Fri Feb 08, 2013 4:26 pm

Thanks for the response.

There is no doubt that you don't throw assembly at people in hopes of getting them excited about programming, you're right about that.

A lot of this post may be irrelevant if you're only talking about primary and secondary education, but you are talking about graduates, so probably not.

In my opinion, the main flaws in the argument you present are over-generalisation, using a one-size fits all approach, lumping all kinds of programming together while only looking at desktop applications, framing the situation as an either-or problem and taking a short-sighted managerial view. I'll try to elaborate, though I am not sure I can articulate this well enough.

First of all, the only reason that you have given to justify the idea that assembly interferes with peoples' ability to write the solutions you describe seems to be that they should be taught to write those solutions in the way you describe instead. Right off the bat, you're framing this as either assembly or "learning how to structure and write well maintainable solutions to problems in languages that they are likely to use in their future career" and that's just not the case. Any university worth the name will teach both without sacrificing on either.

"which is more likely to be higher levels ones" also throws me off. When it comes to desktop applications, maybe. However, pretty much all the devices you have have microcontrollers running code written in C. The operating system you're running along with a large portion of software it's running is probably also written in C. A quick search for the programming jobs shows a lot of C jobs as well. I agree that C++ and Java are more visible and in your face, but I don't think they are any more important or the future. In that sense, I feel that desktop applications and phone apps are the tip of the iceberg, there is a massive framework underneath it built using low level languages.

Also, universities give you the tools and the skills you need to specialise in whatever you need. In that sense, the university teaches you programming as an art in and of itself. You should be able to take what you have learned and use it to pick up a new language, adapt to a new industry and so on. That's what I mean when I say you're over-generalising - programming is a dynamic and broad subject. Simply viewing programming as using a specific language to accomplish a specific goal is short-sighted, imho. That's where I think assembly comes in. Everything that runs on a cpu comes down to pure logic and assembly is the interface between software and pure logic. It helps you understand what the computer is doing and that helps you to appreciate the code you're writing on a deeper level. It gives you a thought framework when it comes to optimizing your code. There is a limit to what the compiler can do for you.

Don't get me wrong, I am not talking about writing x86 desktop applications in assembly as a requirement, for example. I am talking about AVR assembly. You can grab the instruction set and VMLab and pick it up in a matter of days. The way in which it is taught is another issue though. Any time assembly is brought up among university students, it is with hate and relief that they don't have to touch it ever again. I think there is a lot of room for improvement there.
</rant>

:)

User avatar
rurwin
Forum Moderator
Forum Moderator
Posts: 4258
Joined: Mon Jan 09, 2012 3:16 pm
Contact: Website

Re: Assembly - any use in teaching it?

Fri Feb 08, 2013 4:33 pm

I think our university had a fantastic idea then. They had us do a lab exercise in SPSS, on punch cards (no I'm not that old; they were antique even then.)

We had no room to hate mere assembler.

ShiftPlusOne
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 5951
Joined: Fri Jul 29, 2011 5:36 pm
Location: The unfashionable end of the western spiral arm of the Galaxy

Re: Assembly - any use in teaching it?

Fri Feb 08, 2013 4:41 pm

Heh, even I think that's going too far. :D

tufty
Posts: 1456
Joined: Sun Sep 11, 2011 2:32 pm

Re: Assembly - any use in teaching it?

Fri Feb 08, 2013 5:07 pm

Assembler's just another tool, and there are reasons for teaching the basics. Not, obviously, as a first (or even second) language, but there are very good reasons for teaching it. I would *not* teach a particular platform; rather the concepts of assembly language. For this, Knuth's MMIX is probably the best tool, although there are arguments for using something like Java bytecode or LLVM intermediate representation.

If you want to teach kids, you might even look at 0x10c's DCPU-16...

Although I enjoy writing assembler myself, I would also argue that for 99.99% of programmers it's utterly useless to know any particular brand of assembly. Higher level languages make it almost entirely obsolete to use assembly directly. Yeah, I'll get flamed for that, but I stand by it.

The situation is very close to that of programing GPUs. It used to be that you had to write shaders and GPU code in general in assembler, specific to the card manufacturer, taking into account the restrictions of the target platform. These days, you use OpenGL, OpenCL or CUDA, and to hell with worrying about low level platform issues in most cases. Knowing roughly what your language is doing under the hood is useful, but not essential.

User avatar
DavidS
Posts: 4334
Joined: Thu Dec 15, 2011 6:39 am
Location: USA
Contact: Website

Re: Assembly - any use in teaching it?

Fri Feb 08, 2013 8:06 pm

It is an interesting question:

On the one had the probability of 70% of programmers using Assembley in there proffsional life is very low (unfortunately) do to the requirements of there employers.

On the other hand; for a second time in computer history we have reached a point where we need to teach programmers to write optimal code. Once again we are considdering slow memory wasting programming acceptable, how do we expect to take ful advantage of the newer faster more memory hardware if we are using more to do the same or less than we did on an 8-bitter? In the 1970s (pre PC age) this whas a problem with many of the mainframe and inicomputer Operating systems and applicnations, it has become a problem again. There is no reason to make extreme waste of processing time and RAM just because "It is there anyway". I have seen many apps and Operating Systems fall into this pattern. For example tell me why Linux(with the neeed HW modules) + a Standard set of GNU tools and libs + X11R6 + TWM + GTK + LeafPad taks 31MB of ram (not including disk buffers) and 46MB storage space? So there is the need to teach low level programming in order to help curb these bad bad bad programming habits. It does not matter what language the end up using they need to understand why there Stack gets so big, why that slows things down, why they ned to structure there code in an effecient way if they want to do more than a Commodore 65 is capable of.
RPi = The best ARM based RISC OS computer around
More than 95% of posts made from RISC OS on RPi 1B/1B+ computers. Most of the rest from RISC OS on RPi 2B/3B/3B+ computers

Bakul Shah
Posts: 320
Joined: Sun Sep 25, 2011 1:25 am

Re: Assembly - any use in teaching it?

Fri Feb 08, 2013 8:30 pm

Alan Perlis once quipped that a Lisp programmer knows the value of everything but the cost of nothing. More or less the same can be true of anyone who only uses high level languages. If you want to find out how much some part of your program costs in terms of space or cpu cycles, it helps to look at generated code. That is much more difficult to do with a purely interpreted language like Python but with C/C++ or even Lisp/Scheme (in implementations that have a compiler), it is pretty easy. In C, you can just use the "-S" option. For instance:

Code: Select all

$ echo "main(){}" > x.c
$ cc -S x.c
$ cat x.s
        ...
main:
        ...
        str     fp, [sp, #-4]!
        add     fp, sp, #0
        mov     r0, r3
        add     sp, fp, #0
        ldmfd   sp!, {fp}
        bx      lr
        ...
You can write and -S compile tiny .c files like this to start understanding the cost of various language features, to see what happens when various optimization flags are used and so on. You can then try C++ and understand how it implements its classes. etc. etc. I have found compiler/optimizer bugs by poring over assembly output. Knowing it is also useful during debugging. If you don't have source to some function, you can still single step at the instruction level using gdb. And knowing it gives you a very idea of the processor architecture. Once you are comfortable with one, it is not hard to pick up asm for other processors (including MMIX!).

Assembly programming is not necessarily simple but most processor instructions are indeed simple and you can understand each fairly easily.

So in my view, if you want to be a really good programmer you should understand the assembly language of your primary platform. So yes! Assembly programming should be taught, And taught early. And have them write simple asm programs. Doing so would give them a solid grounding in how processors work + it would also be a very good incentive to learn HLL :-)

User avatar
jackokring
Posts: 816
Joined: Tue Jul 31, 2012 8:27 am
Location: London, UK
Contact: ICQ

Re: Assembly - any use in teaching it?

Sat Feb 09, 2013 1:06 am

I taught myself 6502 assembler from a book and had a go at a line draw subroutine C64, and got close enough to see it as a miss division. (shift amount). I had read some Z80 before this, and got the general idea.

It is true that those interested will learn from the net and books, but they have to know the words machine code, instruction set, mnemonic, assembler and arm processor to get far on google.

Learning the half-adder plus a clocked latch (flip-flop) with a push button and LED set is perhaps more fun, and educationally directive.
Pi[NFA]=B256R0USB CL4SD8GB Raspbian Stock.
Pi[Work]=A+256 CL4SD8GB Raspbian Stock.
My favourite constant 1.65056745028

User avatar
DexOS
Posts: 876
Joined: Wed May 16, 2012 6:32 pm
Contact: Website

Re: Assembly - any use in teaching it?

Sat Feb 09, 2013 2:05 am

When for example you teach electronics, do you not teach the basic first, or do you just say, press the switch and light comes on.
To me assembly or C does not matter, i like assembly, but others will prefer C.
The main point is it needs to be low level.

Because theres a trend these days to hide how complex things are.
But theres no getting away from it, things like computers are complex.
So like any complex thing or problem you need to break it down into easy understandable chunks.
This is were programming languages like assembly and C come in, but thats not whats happening, instead we are adding more complexity with very high level languages.
In the old days when computers were simpler, coders could understand how they worked, as they got more complected the coders learn't as they when on.
So now in a lot of respect, we are depending on these older coders to help the coders of today, by for example coding a low level lib, like that released by Gordon for the Pi.

The above situation can be seen in things like arduino coding, 2% of coders do the libs (and know low level stuff) and 98% add 10 lines of code, and thing they are learning something :roll: .
But they are learning nothing, but one day those old coders will retire and no one will be left that understands how things work.

We need to teach kids the low level stuff, so this does not happen.
Theres going to be more and more jobs for low level coders, and the high level coders will be 10 a penny.
We in the developed world, need highly trained workers, that understand things at a low level.

Example: if you were to ask which big high tec Co would have no openings in there company for low level programming job, it would be facebook.
But you would be wrong: https://www.facebook.com/careers/depart ... 20software
Batteries not included, Some assembly required.

pygmy_giant
Posts: 1562
Joined: Sun Mar 04, 2012 12:49 am

Re: Assembly - any use in teaching it?

Sat Feb 09, 2013 3:18 pm

I guess if you know how assembler works you can write your HL code in a similar fashion so it optomises at compile time into an efficient binary. The trick with HL languages may be to use the HL feature set sparingly and only with complex problems which the human brain can't communicate in a way the cpu would prefer to be spoken to.

Programming languages exist as a way to allow humans and machines to communicate as their hardware functions in a fundamentally different fashion. In the past people strove to make programming languages as english/algebra-like as possible. I suspect that a lot of the superficially elegant ways of HL coding that were taught as 'good practice' are in fact, once compiled, from the computers point of view, complicated spaghetti bloat.

I'm not sure there is much need to actually write in assembler, but if you have a broad overview of how the CPU works then you are going to be able to write more efficient code.

Its nice to hear someone else effectively say this above.

User avatar
Jim JKla
Posts: 2218
Joined: Sun Jan 29, 2012 11:15 pm
Location: Newcastle upon Tyne UK

Re: Assembly - any use in teaching it?

Sat Feb 09, 2013 4:17 pm

One of the things I was taught although I have not had much chance to use it was to write functions in a high level code then use a disassembler to deconstruct to see if you can find wasted cycles in the code.

Obviously you have to keep your functions short doing this with a big chunk of code is almost imposible.
Noob is not derogatory the noob is just the lower end of the noob--geek spectrum being a noob is just your first step towards being an uber-geek ;)

If you find a solution please post it in the wiki the forum dies too quick

User avatar
joan
Posts: 14251
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Assembly - any use in teaching it?

Sat Feb 09, 2013 4:32 pm

I'd like to know the percentage of software engineers who have ever needed to use assembler for speed reasons. In my own experience that sort of need disappeared decades ago.

User avatar
aTao
Posts: 1087
Joined: Wed Dec 12, 2012 10:41 am
Location: Howlin Eigg

Re: Assembly - any use in teaching it?

Sat Feb 09, 2013 4:46 pm

Remind me, what are the goals of The Foundation? Is it computer awareness, computer programming or is it as I think computing? (or a nice mixed bag of all three).

Computing requires understanding of electronics, logic, maths, bits, bytes, machine code, assembler, interpreted languages, compiled languages and (I hate to admit) A.I.

To neglect any of these is exactly the failings that The Foundation wish to address.
>)))'><'(((<

User avatar
joan
Posts: 14251
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Assembly - any use in teaching it?

Sat Feb 09, 2013 4:52 pm

If I had to summarise the aim it would be to encourage children to hobby program.

User avatar
Jim JKla
Posts: 2218
Joined: Sun Jan 29, 2012 11:15 pm
Location: Newcastle upon Tyne UK

Re: Assembly - any use in teaching it?

Sat Feb 09, 2013 4:55 pm

aTao wrote:Remind me, what are the goals of The Foundation? Is it computer awareness, computer programming or is it as I think computing? (or a nice mixed bag of all three).

Computing requires understanding of electronics, logic, maths, bits, bytes, machine code, assembler, interpreted languages, compiled languages and (I hate to admit) A.I.

To neglect any of these is exactly the failings that The Foundation wish to address.
Wot no formal methods? ;)
Noob is not derogatory the noob is just the lower end of the noob--geek spectrum being a noob is just your first step towards being an uber-geek ;)

If you find a solution please post it in the wiki the forum dies too quick

User avatar
joan
Posts: 14251
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Assembly - any use in teaching it?

Sat Feb 09, 2013 5:11 pm

Jim JKla wrote:...
Wot no formal methods? ;)
I'd give the module on the impact of big versus little endian systems on the mores of the post 1990 feminism movement priority. But comme ci, comme ça.

Return to “Staffroom, classroom and projects”