Fog Creek Software
Discussion Board




Is it still worth learning ML ?

Is it still worth Machine Language ?

Does mastering Machine Language makes you
a more efficient C programmer ?

TimexLoader
Thursday, February 12, 2004

"Knowing" machine language is certainly useful for writing efficient C, but "mastery" may be excessive unless you're writing a C compiler.

I noticed that https://employmentopportunities.recruitsoft.com/servlets/CareerSection?art_ip_action=FlowDispatcher&flowTypeNo=13&pageSeq=2&jobOfferNo=93593&csNo=2&art_servlet_language=en&selected_language=en&JServSessionIdemploymentopportunities=2anpf8ghb0rfyrb51.RJS44661 for example doesn't explicitly mention "machine language" though it does mention hardware.

Christopher Wells
Thursday, February 12, 2004

Having a passable knowledge of assembler is very useful for debugging.

I don't think it will make you a better C programmer directly (unless you write device drivers or operating system internals reguarly).  A good understanding of what modern chips can do will help there without having to know the details of the instruction set.

On the other hand learning ML ( http://www.smlnj.org/ ) is a good way to get into functional programming and will probably make you a better programmer overall than learning a low level machine language.

Rob Walker
Thursday, February 12, 2004

All the truly great programmers I've worked with (I've been programming over 20 years) have all been experts with assembly language at one time or another in their lives.

Bathmophobic skier
Thursday, February 12, 2004

Do you think their mastery of assembly is a function of their greatness or merely an artifact of the era in which they started programming?

Rob VH
Thursday, February 12, 2004

Assembly language programmers tend to understand computers at the lowest possible level.  Everything else - operating systems, higher level languages, etc - builds upon that.

It's like learning algebra.  You can be a graphics programmer without it, but you're a much better graphics programmer if you understand the matrix operations that drive it.

Bathmophobic skier
Thursday, February 12, 2004

machine language != assembly language != assembler

Can't anyone keep their terms straight!

annoyed
Thursday, February 12, 2004

I've been messing around with asm recently, and currently it's one of my two favorite languages.  I think it's an honest language that gives you power and doesn't hide out of fear behind some grammar whose purpose is to hinder you from writing both really good and really bad programs.  I just wish there was a stronger macro language for it than you'd usually find.

Though I haven't seen all the lectures, these seem good:
http://www.aduni.org/courses/hcw/
http://ocw.mit.edu/OcwWeb/Electrical-Engineering-and-Computer-Science/6-004Computation-StructuresFall2002/RelatedResources/

That second one is BSim (bsim.jar/beta.uasm), and it's pretty nice.  You can email me if you have problems running it...  It shows the machine instructions and you could even program in them if you were inclined.  There are other learning simulators, but things like Spim don't work well on Windows.

Keep in mind that ML is the name of a language that stands for "meta-language" (it's a misnomer now; it grew out of some language used only to reason about other languages, but the name stuck).  As I understand, ML asks you to take certain restrictions in your coding style (static typechecking, functional programming) in order for the compiler to easily prove some things about your program.  Hopefully someone can correct me if I'm wrong, since I've just skimmed through a couple of ML dialects.  OCaml in particular looks interesting.  But nothing seriously to do with machine language. ;)

Tayssir John Gabbour
Thursday, February 12, 2004

Knowing assembly won't mean you're a better graphics programmer than one who doesn't.. I've seen the worst programs created by coders, and have also seen some small gems written in VB..

Understanding you machine will give you an edge, for sure. But remember that a programmer nowadays is more a designer than coder..

rrobin
Thursday, February 12, 2004

Knowing what happens 'behind the scenes' makes you a better programmer not only in C, but also in Java and all the 'higher-level' languages. I would doubt the advantage of knowing the assembly language for every possible processor, and even remembering all the instructions. However the ‘general knowledge’ is definitely valuable.
Learning Standard ML is good as an introduction to functional programming. However you might discover that LIPS is much more popular and there is much more literature and support for this language.

Alexander Chalucov (http://www.alexlechuck.com)
Thursday, February 12, 2004

The point is that you have to know how a CPU works or else you'll be constantly baffled by new languages or new systems or simply unexpected behavior of a language you know.

You don't have to be an expert, and it doesn't matter if you learn ML or assembly, or which ML or assembly, but I wouldn't trust any programmer who doesn't have any idea how a CPU ultimately executes a program. That's the real issue.

Chris Nahr
Thursday, February 12, 2004

Ok, so is an "assembler" a concrete dialect of the assembly language family, or does it only refer to an implementation of a dialect?

By the same token, do you putz with a schmuck, or schmuck with a putz?  Deep questions of mankind.

Tayssir John Gabbour
Thursday, February 12, 2004

I think "assembly language" is the language that an "assembler" compiles into machine language. That said, you should probably avoid close contact with anyone who treats the distinction as a religious issue...

Chris Nahr
Thursday, February 12, 2004

>Rob Walker: On the other hand learning ML ( http://www.smlnj.org/ ) is a good way to get into functional programming and will probably make you a better programmer overall than learning a low level machine language.

So I'm not the only person to think about ML upon glancing the subject title...

SC
Thursday, February 12, 2004

I've been learning assembly for writing a small toy OS, for learning purposes (of course!). I have to say it's making me a better programmer. You know in Lisp they say that code is data, data is code? I never really knew what that meant until I had started writing asm, where you outline .text and .data (and .bss) parts explicity. I mean, I knew what it meant, but I hadn't really internalized like now.

Having a go at writing OS level code has been an incredible learning experience too. I've gotten a proper feeling for memory management, IPC, etc.

.
Thursday, February 12, 2004

>>You know in Lisp they say that code is data, data is code?<<

I should qualify this by saying that I can't code Lisp to save my life :). Not yet anyway. It's in my todo.txt though.

.
Thursday, February 12, 2004

I'm not trying to be pedantic, but I think the OP needs a recap:

Assembly language, in a nutshell, is a low level language that allows the programmer to manipulate the contents of registers and memory addresses.  Learning assembly is fundamental to understanding how a computer operates.  For example, I never really knew what "created on the stack" and "created on the heap" meant until I took a assembly/computer architecture course.  Assembly also allows you do certain things that cannot be done in C.  Whether you need that knowledge in your particular career depends on what you'll be programming, but most people who've learned it's invaluable.  It's still commonly used in embedded and graphics (e.g. games) programming.

An assembler compiles assembly language instructions into machine language (aka, machine code, machine instructions).  Although they are commonly displayed in hex, machine language instructions are binary numbers that have special meaning to the processor for which they've been compiled.

Anything that you can do in machine language, you can do in assembly language, therefore assembly language is the lowest level that the vast majority of programmers and computer scientists learn.  Machine language is the domain of the engineers that design the chips.

So if your title question meant "is it still worth learning assembly language", then I'd say the answer is yes.

Nick
Thursday, February 12, 2004


> machine language != assembly language != assembler
>
> Can't anyone keep their terms straight!

I program in machine language:

  B9 13 00 00 00
  B8 CC CC CC CC

and have no time that fancy assembly language stuff:

  mov ecx,13h
  mov eax,0CCCCCCCCh

so it goes without saying I don't like assemblers :)

Jussi (www.zeusedit.com)
Thursday, February 12, 2004

Just like to put in a plug for PureBasic for anybody interested in learning asm.

Purebasic provides a gentle introduction into asm in two ways:

1)  You can write inline ASM that has full reference to the basic variables.

2)  An option of the compiler will show you the basic compiled into Asm, so you can see how to do stuff.

http://www.purebasic.com

Ged Byrne
Thursday, February 12, 2004

To say you need to be a wiz at machine language (or assembly) to be a top notch high level language programmer is just stupid.

I think people who say this have correlation and causation mixed up.

If someone is a brilliant high level programmer, chances are that they'll be great at assembly too. You know why? Because they're good at programming!

I'm sure if they used brainfuck, they'd be great at that too. Yet we don't see anyone claiming you have to be an expert brainfuck programmer to be a great programming in C++.

It's the same situation, just assembly is known by more people than brainfuck!

Sum Dum Gai
Thursday, February 12, 2004

> I think people who say this have correlation and causation mixed up.

Not entirely: people who know assembly know not only what's being said to the machine, but also what the machine is reading.

Christopher Wells
Thursday, February 12, 2004



I was hoping this thread was about this ML...

http://www.csc.vill.edu/~dmatusze/resources/ocaml/ocaml.html

functional X
Thursday, February 12, 2004

"Not entirely: people who know assembly know not only what's being said to the machine, but also what the machine is reading."

Nobody has yet presented anything that shows this to be a useful skill, however. People are just assuming that knowing this makes you a better programmer.

Furthermore, there's no reason why one can't understand how computers work without actually being an assembly programmer. Assembly programming may be a common way to obtain such knowledge, but it's not the only way. With today's CPUs that work very differently than their external instruction set suggests, one might even say being an assembly programmer isn't enough to give you such knowledge.

Sum Dum Gai
Thursday, February 12, 2004

If you know assembler, you get pointers.

The other guy
Friday, February 13, 2004

But if you get pointers, do you understand assembly language?

As someone who used to play with assembly language, I'm still not convinced by anything in this thread that an understanding of assembly makes a stronger programmer. The best I've seen is that understanding of assembly is potential EVIDENCE of a strong programmer.

And lest we forget, actual programming is only half the battle.

Shodan
Friday, February 13, 2004

functional X - SPLITTER! The only true ML is Standard ML!

For which, I was stunned to find out, there is a .NET compiler *boggle* - http://research.microsoft.com/projects/sml.net


Friday, February 13, 2004

> Nobody has yet presented anything that shows this to be a useful skill, however. People are just assuming that knowing this makes you a better programmer.

Well, the question is specifically whether it makes you a "more efficient C programmer" (not better or more useful; also I took that to mean "efficient code" rather than "efficient programmer").

I accept that without knowing assembler you can get an idea of the cost of malloc(), for example by reading the C source that implements malloc(), or by profiling it ... but you might lack intuition about the cost of allocating a local variable (on the stack).

I won't prove it, I'm just expressing a personal opinion that knowing assembly has helped me to understand C and to write (time and/or space) efficient C.

>  With today's CPUs that work very differently than their external instruction set suggests, one might even say being an assembly programmer isn't enough to give you such knowledge.

That's true. Still, look at .'s post:

  "You know in Lisp they say that code is data, data is code? I never really knew what that meant until I had started writing asm, where you outline .text and .data (and .bss) parts explicity. I mean, I knew what it meant, but I hadn't really internalized like now."

Doesn't that sound as if . is now better equipped to understand the CPU's cache, now that he or she understands that both data and code are chunks of bytes?

Christopher Wells
Friday, February 13, 2004

It depends on what kind of software you’re intending to work with.

I’m a long time assembler and C programmer, and I used to make exactly the point that all the good high-level programmers know assembly language – which means that they probably understand programming at the machine-level. (The definition of “assembly language” is that each source code line translates to exactly one machine operation.)

These days, I don’t recommend you bother, unless it just interests you – or you’re working close to the operating system or the metal. Frankly, if all you want to do is sling Java code to generate basic business apps, machine code is overkill. In fact, people with a little knowledge of assembler/mc who try to outsmart the compiler do far more harm than good.

You also need to be aware that there isn’t one machine code. There are many and they’re very different from each other. So “learning machine code” is more of an academic exercise than a seriously useful job skill for most people. Having said that, software machine code and chip internals are far more interesting than ho-hum code slinging – so I still say go for it.

http://www.sysprog.net/hlasm.html

Celia Redmore
Friday, February 13, 2004

Remember, for the guys who program the microcode (like the guys at Intel), assembly is a high level language.


Friday, February 13, 2004

Microcode is not used widely in the most recent processors. In today’s x86 world most (all except transmeta?) processors are RISC processors on the inside and have a translation unit which translates x86 into their internal ‘micro-op’s. Some more complex instruction are still supported through microcode, but compilers do not use them.

Alexander Chalucov (http://www.alexlechuck.com)
Friday, February 13, 2004

1.  ". . . where you outline .text and .data (and .bss) parts explicity . . ."
BEEP!  assumption alert!
In some architectures (including those where I first learned, and spent many happy days & nights coding, assembly language), there's no such distinction.
Once upon a time, learning the concept (and acquiring the practice) of hand-rolled re-entrant coding was a revelation, the latest way to get a coder's coolness/novelty"fix".

2.  I'd been using HLLs for about a year before learning assembly.  Haven't used assembly (or those machine architectures) for years, but it gave me a closer-to-the-metal understanding which
(a) made me a better coder all-around ever since then, and
(b) took my career in new directions (kernel coding, performance analysis, etc.).

Learning how any single architecture handles things like interrupts, wait-states, vm, smp, serializable op-codes, etc., is definitely an advantage for feeling comfortable when using locks/mutexes, threads & parallelism, etc.

My advice is to dabble enough to get your feet wet in the practice of using an op-code-level debugger and reading a disassembly of a compiled program.  But I wouldn't spend more than a couple of weeks (or a one-term night-class) doing it, unless you plan to get into kernel-level coding.

ano nymous
Friday, February 13, 2004

>> people who know assembler [....] who try to outsmart the compiler do more harm than good

Right on Celia!

The level of optimization required by Pentium IV is so contorted that writing assembly by hand would produce *slower* code.

You have to intertwine instructions to account for the internal architecture, just too much stuff to consider.

I looked at some compiled C++ code, the assembly was so stripped down and perfectly optimized, I would have spent *days* to get *close* to that kind of perfection.

.... and of course I have a quote for the occasion.

"He who hasn't hacked assembly language as a youth has no heart. He who does so as an adult has no brain."

Alex.ro
Saturday, February 14, 2004

*  Recent Topics

*  Fog Creek Home