maemo.org - Talk

maemo.org - Talk (https://talk.maemo.org/index.php)
-   General (https://talk.maemo.org/forumdisplay.php?f=7)
-   -   Learn Programming - asm on arm (https://talk.maemo.org/showthread.php?t=27056)

Matan 2009-02-23 16:56

Re: Learn Programming - asm on arm
 
In short:

Quote:

C is a language that combines all the elegance and power of assembly language with all the readability and maintainability of assembly language.
...

lardman 2009-02-23 17:10

Re: Learn Programming - asm on arm
 
Quote:

with all the readability and maintainability of assembly language.
Hmm, well I think it's easier to read (and therefore maintain) C myself, but perhaps I'm just not getting the joke in that quote.

CVBruce 2009-02-23 17:32

Re: Learn Programming - asm on arm
 
...I want to learn assembler, in order to understand how the machine works, then indeed, to make a little C stuff ! it's the main goal...

Some well commented assembler source code will provide you with much of what you want to know.

Believe it or not, before I could afford a computer, I used to write Z80 assembler programs on paper. I made a little chart showing all of the registers, then I would manually execute the program using pencil and eraser.

When I took my assembler class, the first programs we wrote were in machine language. All input was via front panel switches, output was by front panel lights. We would load the program into memory one instruction at a time, and then step to the next memory location.

You only need to do a little of this to get the idea of how a cpu works.

CVBruce 2009-02-23 17:40

Re: Learn Programming - asm on arm
 
Quote:

C is a language that combines all the elegance and power of assembly language with all the readability and maintainability of assembly language.
If you go back and read the interviews and articles of Dennis Ritchie, his goal was to produce a portable high level assembly language.

Your quote on C is exactly right. C was designed to be a language for expert programmers. Unfortunately most people think they are experts. I have looked at a great deal of C code over my career, and I have to say that there is more crap out there then you would believe, including the code I wrote.

Serge 2009-02-23 17:41

Re: Learn Programming - asm on arm
 
Quote:

Originally Posted by pycage (Post 266442)
Speed is not a matter of choosing a certain language, speed is a matter of choosing the right algorithms.

Apart from that, writing whole programs in assembler is not recommended on modern operating systems because you would have to program against a C-level interface. But nothing (except for portability) speaks against writing small functions (e.g. for image processing) in assembler. But don't get the illusion that asm is faster than C. Most C-compilers nowadays produce optimized asm code that is faster than anything you would write yourself in asm.

But unfortunately gcc for arm is not one of these compilers. It does rather poor job at instructions scheduling and registers allocation. Leaf functions containing loops and nontrivial branching logic can be hand optimized quite well using assembly with rather good results. Of course optimizing these functions only makes sense if they are performance hotspots.

CVBruce 2009-02-23 17:59

Re: Learn Programming - asm on arm
 
Quote:

Originally Posted by Matan (Post 266432)
C is no compromise. If you never programmed in assembly (or C, C++, python, perl) then your assembly code is not going to be faster than your C code for anything more useful then a countdown loop, for at least a few years. By then, even ARM might be superscalar and out of order, so you will need to start optimizing your super fast code all over again.

If you do want to learn ARM assembly (it is useful for a lot of things, just not for speed), you need the ARM ARM, since that is the standard text.

I agree with this, but I think, it is more a function of modern optimizing compilers rather than the language per se.

TA-t3 2009-02-23 18:30

Re: Learn Programming - asm on arm
 
Quote:

Originally Posted by CVBruce (Post 266564)
I agree with this, but I think, it is more a function of modern optimizing compilers rather than the language per se.

.. combined with the complexity of writing assembly on modern CPUs: Optimizing for the pipeline, out-of-order execution, delay slots, and other tricks (depending on which CPU you're programming for). Those things can be really tricky to get right when doing assembly programming by hand. Back in the days when I did assembly programming myself I didn't have to think of any of that (6502, z80,6809, minicomputer assembly).

briand 2009-02-23 18:35

Re: Learn Programming - asm on arm
 
Quote:

Originally Posted by TA-t3
Back in the days when I did assembly programming myself I didn't have to think of any of that (6502, z80,6809, minicomputer assembly).

ha.. cool. I had the honor and great privilege to work alongside (and learn from) the guy who (literally!!) wrote the book on 6809 Assembly programming -- Lary Myers.

jthiemann 2009-02-23 23:34

Re: Learn Programming - asm on arm
 
I've programmed assembler on the ZX81 (Z80), C64 (6502/6510), Amiga (68000) (those for fun), for the 68HC11, PIC (16C74), and TI DSPs (c50) (for pay) and PPC (for school). I've spent a lot of time coding C for fun, school and work, too. And a smattering of other languages as well, from FORTH to Lisp.

Now? I write in MATLAB, and am learning Python. There is a golden rule: the right tool for the right job. Don't use ASM "just because". If you want to learn about the internals of CPUs, be aware that architectures are all different, and evolve. My 6502 assembler didn't prepare me for RISC, or the Harvard architecture of the PIC chips. What you learn for ARM today can't easily be carried over to i686, or the cell processor or DSP chips, or whatever the chip designers are dreaming of today. VHDL might be more useful!

If your goal is to learn about to-the-metal computer programming, I recommend getting yourself an Arduino or maybe a Parallax Propeller kit. I've got myself the former and they're great fun. Programmable with very little ramp-up in C, and ASM if you dig a little. Dead easy to interface.

If you want to write applications, start with Python, until you hit a performance or capability bottleneck. Then switch to C++ or C.

If you want to learn about OS design, hit the books. Then learn C. Then look at the Linux source. Read more books. OS design is very complex and academic these days, and there are many difficult algorithms at play.


All times are GMT. The time now is 20:50.

vBulletin® Version 3.8.8