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)

benohit 2009-02-22 21:24

Learn Programming - asm on arm
 
Hello all,

I hope there are some people who can advise me :
I would want to learn basic programming, beginning with ASM first.
then, i would learn C, then a little C++ stuff, and then perl and python.

But i need these things :
- a guide of ARM "assembleur"
- tools for programming in asm code on my n810

THanks in advance !

Bundyo 2009-02-22 21:26

Re: Learn Programming - asm on arm
 
Assembler isn't something that can be called basic ;)

BrentDC 2009-02-22 22:01

Re: Learn Programming - asm on arm
 
Quote:

Originally Posted by benohit (Post 266307)
Hello all,

I hope there are some people who can advise me :
I would want to learn basic programming, beginning with ASM first.
then, i would learn C, then a little C++ stuff, and then perl and python.

But i need these things :
- a guide of ARM "assembleur"
- tools for programming in asm code on my n810

THanks in advance !

You got the languages in the wrong order! :eek: Start with Python, man.

baksiidaa 2009-02-22 22:35

Re: Learn Programming - asm on arm
 
Quote:

Originally Posted by BrentDC (Post 266318)
You got the languages in the wrong order! :eek: Start with Python, man.

I second that.

Besides being beginner-friendly, you don't need to compile when using Python, so you can instantly try out your code. You can also open a command-line interface, so that you can try out individual commands.

benohit 2009-02-22 22:40

Re: Learn Programming - asm on arm - which tools to install ?
 
Quote:

Originally Posted by BrentDC (Post 266318)
You got the languages in the wrong order! :eek: Start with Python, man.

I took a look at this language indeed,but, i'm fed up with slow performance of "modern" applications.
I know python is very interesting.
I know how to do :
- algorithmic
- shell scripting
- basic to turbo pascal
- php
But since i use computers (since 1992), i don't want to debate about this, but, i'm look for performance you know.

I prefer e17 to gnome+compiz
I prefer mp3blaster to xmms
I prefer vim to gedit

I want to know how things work, and to be able to use my n810 for real tasks, than to wait for a web page to be loaded on zimbra for example, or a map to be loaded in gmaps too.

Python is used in every tools in ubuntu for update-manager and all things, but i'm the man to launch "apt-get update ; apt-get dist-upgrade". I prefer scripting a daemon instead of using a "good-looking" app that takes some time to launch its scripts, to launch the graphical stuff, update the information in its window, wait for a user interaction, etc...

So please just let me know about asm on arm stuff please ! i will then be a forever-smiling man !
Why not programming in python, but in months... ;-)

Aural 2009-02-22 22:47

Re: Learn Programming - asm on arm
 
Well, I'm not a very good programmer, but a few years ago I looked into this free ebook on PC asm, I know it isn't ARM asm, but it could be a useful start. I just happened upon this thread so I don't happen to have any useful links to free books for ARM assembly, but I'd imagine a lot of the same principles still apply and can be utilized.

Here is the link to the aforementioned book:
http://www.drpaulcarter.com/pcasm/

Hope it helps and best of luck!

attila77 2009-02-22 23:26

Re: Learn Programming - asm on arm - which tools to install ?
 
Quote:

Originally Posted by benohit (Post 266328)
I took a look at this language indeed,but, i'm fed up with slow performance of "modern" applications.
I know python is very interesting.

It's a question of balance. Assembly development can be very daunting and long winded. If you are after performance, you are probably better off writing your app in python, profiling it, and then replacing specifing routines/functions with assembly ones.

Also, after doing quite some assembly myself (admittedly not ARM) I must say it's far from what assembly was in 1992, mostly for two reasons:

1) The operating system. With DOS it was dead easy, nobody cared what your assembly code did, you had simple BIOS routines to interact with the user and that was it. That's no longer the case. Just interacting with the OS to copy a file or read a keypress can be hell.

2) You need to grow a head of the size of a basketball. Seriously. With multiple cores, pipelines, branch prediction, etc, it becomes more and more sorcery to create fast code by hand. Less instructions do no longer mean quicker execution. I had cases where just changing the order of instructions meant a difference of ~30% in speed (!).

lardman 2009-02-22 23:37

Re: Learn Programming - asm on arm
 
Learn C, the execution-speed:writing-speed ratio is very good, only very occasionally will you need to resort to raw ASM. I'd skip Python completely if you want speed (plus C is a useful thing to know).

ASM is a pita to use basically, and I only resort to it if I really have to (not very often thankfully :)). To learn it, I scoured the web, mainly looking at existing ARM ASM code (the ARM Linux site has some useful info too: http://www.arm.linux.org.uk/developer/) and also eventually bought a book (ARM Assembly Language - an introduction by J.R. Gibson), however I've not done much ASM since then, and therefore haven't really read the book, so can't actually recommend it in any way other than saying that it's the one that looked best to me at the time :)

Bundyo 2009-02-22 23:45

Re: Learn Programming - asm on arm
 
You can try Vala for speed - it is similar to Python and C#, but translates to C and compiles to native, so the execution speed is much better.

CVBruce 2009-02-23 01:05

Re: Learn Programming - asm on arm
 
Well this is really pretty easy. Let's see. First you need to stop off at the company that makes the CPU. You should be able to down load a PDF spec that will outline all of the instructions that your particular variant of the ARM processor can execute. Then you need to determine which assembler you are going to use. Probably something from GNU, so you need to get the manual for that. That manual will have all of the directives and formats used by the assemble to translate assembler into machine language. Next you will need to read the man pages for maemo. basically section 2 and 3. That is about it.

As to a book, all that would be in the book would be the machine instructions, addressing formats, etc.; all of which is in the spec sheet from the cpu manufacturer. Assembler directives, etc. are from your assembler vendor. OS callable routines are in the maemo man pages. The book would add little except sample programs.

The previous comment about growing a big head is right on. In assemble you must keep in your mind the contents of all registers and status flags, and know how each op code will effect them.

Me, I would follow Atilla77's suggestion of python, with a few optimized routines. I read a report a number of years ago that said it takes about 350 lines of assembler to do the same job as about 150 lines of C. Python wasn't mentioned, but I'm pretty sure that it would be well below 100.

I've done assembler programming as a job. I've been programming since 1969. My shortest assembler program was a CICS transaction that was 3 lines of code. It was used for a number of years by my employer. Avoid assembler programming!

CVBruce 2009-02-23 01:10

Re: Learn Programming - asm on arm
 
I also agree with lardman. C is a very good compromise between speed of development and speed of execution.

Matan 2009-02-23 05:06

Re: Learn Programming - asm on arm
 
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.

pycage 2009-02-23 07:22

Re: Learn Programming - asm on arm
 
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.
I'd also suggest to skip C++ and learn Java instead. C++ is (or should be) a dead language (although many people don't want to believe so) and not a good choice for object-oriented programming. In other words, C++ is a mess and mostly incompatible with itself.
Python OTOH is a really nice and comfortable object-oriented language.
C is tiny, easy to learn, but it's not really comfortable for writing big programs.

benohit 2009-02-23 08:57

Re: Learn Programming - asm on arm
 
Quote:

Originally Posted by CVBruce (Post 266376)
I've done assembler programming as a job. I've been programming since 1969. My shortest assembler program was a CICS transaction that was 3 lines of code. It was used for a number of years by my employer. Avoid assembler programming!

Don't worry !
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.

I know and think that 80% of programmers today don't think about optimisating their code. I'm one of them in PHP.
So before reading a book that mentioned "garbage collector", i didn't had any idea about flushing caches for example.

I'm just, again, looking for a guide af ARM assembler, with exercices for example, that i could do on my n810.

Because i think that it will be obsolete in 4 years, and that a 1998's powerbook g3 laptop isn't yet, thanks to linux.

So why not learn java indeed. But in this order :
ASM => C => Perl => java => UML 2 => XML => PHP5

C++ will be necessary to understand linux code. Not to create, but to understand in debug.
Learning these languages will make me code in different manners. And optimize algorithms.

I ordered a book to learn object oriented programmation.

jethro.itt 2009-02-23 09:01

Re: Learn Programming - asm on arm
 
Quote:

Originally Posted by Matan (Post 266432)
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.

And here it is: The ARM Architecture Reference Manual. It's not a tutorial but a comprehensive overview of the "ideal" ARM architecture. Real ARM CPUs amend this text with their own specifications. See http://www.arm.com for details.

Learning ARM assembly on Linux is very time consuming. The OS is stepping on your fingers at every opportunity. You would make better use of your time to learn ARM assembly on a simple ARM7TDMI-based development board, such as this one (33 euros, also see prices for other boards). They cost only tens of dollars and run your program without the burden of an operating system. After you get the hang of assembly programming, you'll see better where the extra effort is beneficial. Most any user-facing software can be written in mixed Python/C/Asm these days.

EDIT: Here's a real-world scenario I'm currently working on. Maybe this will illustrate how relevant assembly code is on modern CPU architectures:
  • NXP LPC2103 ARM7TDMI-based microcontroller
  • About 60 MHz (58.9824 MHz actually)
  • 32 kB Flash memory
  • 8 kB RAM
  • Monochrome 240x64 graphical user interface
  • USB and serial port for communication with automation systems
  • Several time-sensitive peripherals to monitor and control
  • Requirement: Sub-millisecond response time to fault conditions
  • Requirement: Sub-microsecond response time to external pulses
  • About 13000 lines of code
  • ... of which about 500 lines is written in assembly code, rest is in C.

So even in a deeply embedded time-critical application such as this one, assembly code accounts for less than 4% of total lines of code. A desktop- or pocket-class machine has even less use for assembly optimization.

benohit 2009-02-23 10:16

Re: Learn Programming - asm on arm
 
Thanks to all of you !

I also found this :
http://linux.onarm.com/

But i still don't know which tools to install on my n810 to write/run ASM and C code...

lardman 2009-02-23 12:36

Re: Learn Programming - asm on arm
 
You need to install GCC - there's a thread somewhere on the board about on-board development, follow those instructions.

twaelti 2009-02-23 15:56

Re: Learn Programming - asm on arm
 
No one around of the old C64 scene? I vaguely remember some ASM from back then, for Scrolltexts, Music and Sprite-Animations...
Why anyone would like to start with ASM is way beyond me, however :-)

jolouis 2009-02-23 15:57

Re: Learn Programming - asm on arm
 
One final vote for C, coming from somebody's who's been along a similar learning path. I gleaned most of my programming (at least the modern useful stuff) from PHP, but started getting into doing embedded device development and found that PHP had all the capabilities, but was WAY too slow and resource-intensive. Started looking into C, and found it amazingly easy to learn because the syntax and concepts are almost exactly the same. (to the point where half of my PHP code could have almost been copied and pasted, compiled and it ran in C sort of thing). The real trick to learning C from a PHP point of view is just to get the whole memory management thing figured out, which really isn't as hard as people make it sound... you just need to make sure you plan and pay a lot of attention when you create variables that you remember to free them later, that's all. If you start getting into UIs and things it can be a little more complex, but for back-end/daemon type stuff it's not hard at all.

lcuk 2009-02-23 16:40

Re: Learn Programming - asm on arm
 
let me backup lardman's assertion about c.
I use it every day onboard the device and writing in it gives me 2 very important things after compilation:

(1) very close to asm performance
(2) code reuse, the same things I write in c are recompilable on arm and x86

that simply is not possible with asm.

Also, if whilst learning all about c you NEED an algorithm coding in asm (just like pascal) you can do inline asm directly with your c file and GCC will magically make it for you!


You should be well past your "why" things work, just translate your pascal thinking slightly and you end up with c code.


by the way, am I the only one who can smell something?

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:53.

vBulletin® Version 3.8.8