LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-21-2013, 10:23 AM   #16
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,399
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908

Quote:
What do you mean with "agnostic"?
Doesn't rely on any OS. For a given hardware architecture, it will run without a requirement for any particular OS. In retrospect, 'agnostic' is probably the wrong choice of word.
As far as using assembler to write C functions, I guess that may be useful, if only as an academic exercise. I can't say it is never done, but from where I see things, it is extremely uncommon. Using assembler to write low-level components of OSs like interrupt service routines seems to be a bit of a large bite for a newbie to chew on. It does have a practical aspect.
I am not advocating that the PC architecture is something one should learn, however that the use of assembler does go hand in hand with programming to bare metal. Any bare metal, and the concepts are largely transferable across architectures. Old PCs are well documented, widely understood, easily and cheaply acquired, relatively easy to use, and quite consistent in makeup. These things contribute to eligibility as a trainer platform. If the learner has the opportunity to poke around with a scope or other test gear, and accidentally releases the magic smoke, very little will be lost.

--- rod.

Last edited by theNbomr; 02-21-2013 at 10:25 AM.
 
1 members found this post helpful.
Old 02-21-2013, 10:41 AM   #17
johnsfine
LQ Guru
 
Registered: Dec 2007
Distribution: Centos
Posts: 5,286

Rep: Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197
Quote:
Originally Posted by theNbomr View Post
As far as using assembler to write C functions, I guess that may be useful, if only as an academic exercise. I can't say it is never done, but from where I see things, it is extremely uncommon.
Any non "academic exercise" use of asm is extremely uncommon.

I expect real professional (or serious open source) use of asm for C callable functions is currently written more often and by more software engineers than asm for OS's.

Professionally, I have written an entire OS in PDP11 asm, and a different entire OS in 16-bit x86 asm, and a different entire OS in mixed 32-bit x86 asm and C. I have written asm functions callable from high level code in a wide variety of architectures including all three bit sizes of X86.

My hobbyist use of asm has been far more widely varied.

My advice is based on having worked on asm in all the different forms that have been discussed. It is very much not the usual "this is how I did it, so I suggest others do the same". I did this every way, and I am sure about my suggestions of which way would be best for a beginner today.
 
Old 02-21-2013, 10:46 AM   #18
psionl0
Member
 
Registered: Jan 2011
Distribution: slackware_64 14.1
Posts: 722
Blog Entries: 2

Rep: Reputation: 124Reputation: 124
Quote:
Originally Posted by Sergei Steshenko View Post
Well, x86 segment registers are a source of genuine disgust. So I'd suggest some other architecture.
If you had read the rest of my post, you would realize that this response is totally superfluous. When you use the "tiny" model your program is totally contained within a 64 K space and the segment registers are not used.

With NASM you can compile straight to a binary file which is executable in DOS(Box).
 
Old 02-21-2013, 10:59 AM   #19
frieza
Senior Member
 
Registered: Feb 2002
Location: harvard, il
Distribution: Ubuntu 11.4,DD-WRT micro plus ssh,lfs-6.6,Fedora 15,Fedora 16
Posts: 3,233

Rep: Reputation: 406Reputation: 406Reputation: 406Reputation: 406Reputation: 406
Quote:
Originally Posted by Sergei Steshenko View Post
Well, I do not quite agree with that. For example, for an interrupt service routine one needs to save registers on stack (if we are talking about a stack machine), and then to restore the registers at the routine exit. High level languages do not have CPU register notion ("C" "register" keyword doesn't count - it's something different).

The amount of code which needs to be written in assembly is really tiny compared to the whole kernel, but still the code is necessary.
i agree with that, even the linux kernel has some bits of assembly code for each architecture with which it is compatible, in fact it's that assmebly code that in large part IS responsible for compatiblity with said architecture.
 
Old 02-21-2013, 11:27 AM   #20
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,399
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
Actually, I would retract my assertion about using assembler to write C callable (or any other language callable) functions, as I've actually done that many times. However, I have never done it in the context of a host capable of running a real OS (DOS isn't one of those, in this context), and I doubt that it has much place there.

For microcontroller class CPUs (16-bit and smaller), it is almost exclusively the method I favor, but the functions tend to get very close to the hardware in those cases. For bigger hardware, I cannot see any really practical use for assembler at the application programming level. I don't think the OP is likely to be doing OS-internal level programming as a beginner.
Clearly we have all used assembler for differnt purposes. I confess that seeing anything that I have not done may seem somewhat off-normal to me. mea culpa

The OP could probably help himself/herself by explaining what purpose is behind wanting to learn assembler.

--- rod.
 
Old 02-21-2013, 11:47 AM   #21
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Quote:
Originally Posted by psionl0 View Post
If you had read the rest of my post, you would realize that this response is totally superfluous. When you use the "tiny" model your program is totally contained within a 64 K space and the segment registers are not used.

With NASM you can compile straight to a binary file which is executable in DOS(Box).
The whole notion of tiny, and other (do I remember correctly that there are two more of them - large and huge ?) memory model is an unnecessary complication for a beginner.

And, of course, there is that nasty PAE extension on 32 bits ...
 
Old 02-21-2013, 11:59 AM   #22
psionl0
Member
 
Registered: Jan 2011
Distribution: slackware_64 14.1
Posts: 722
Blog Entries: 2

Rep: Reputation: 124Reputation: 124
NASM doesn't use those memory models. It's just a straight source to executable compilation without any other complications. The only time you use segment registers is when you want to access more than 64K addressable space (unlikely for a beginner). Nothing could be simpler.

Last edited by psionl0; 02-21-2013 at 12:08 PM.
 
Old 02-21-2013, 12:15 PM   #23
ejspeiro
Member
 
Registered: Feb 2011
Distribution: Ubuntu 14.04 LTS (Trusty Tahr)
Posts: 203

Rep: Reputation: 26
Quote:
Originally Posted by johnsfine View Post
Any non "academic exercise" use of asm is extremely uncommon...
What about micro/macro devices programming, as for example, sound effect pedals?

 
Old 02-24-2013, 06:32 AM   #24
Holering
Member
 
Registered: Feb 2010
Distribution: Slackware - Gentoo - Debian
Posts: 197

Original Poster
Rep: Reputation: 22
Wow so many responses thanks for all the help! It's great that some of you provided documentation sources which is really helpful.

I'm leaning against x86 assembly since it seems more standard and common in computers. Would like to write anything useful like a driver, audio decoder, porting software, or anything that may give me assembly know-how on x86 computers (and x86_64 assuming they're almost the same).

Based on reading and google searches many programmers refer to high level languages (python or something new for instance) so assembly guides aren't always convincing; only exception is: http://en.wikibooks.org/wiki/X86_Assembly . It'd be great to hear more on how some of you began assembly (especially x86) and got familiar with it.

Regards
 
Old 02-24-2013, 07:42 AM   #25
johnsfine
LQ Guru
 
Registered: Dec 2007
Distribution: Centos
Posts: 5,286

Rep: Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197
Quote:
Originally Posted by Holering View Post
assembly guides aren't always convincing; only exception is: http://en.wikibooks.org/wiki/X86_Assembly .
That has a lot of good content in it. But it also has a lot of distracting legacy content. I'm not sure a beginner would know which parts are useful.

Also, addressing modes are a very important topic in asm. The addressing modes section of that book is hard to find and nearly useless.

Some other sections of the book show both Intel syntax and gas syntax, and present the information either specific to 32-bit or general enough to infer most of the 16-bit, 32-bit and 64-bit possibilities. The addressing modes section is just 16-bit. But addressing modes is an area where there are maximum differences between 16-bit and 32-bit as well as significant differences between 32-bit and 64-bit.

I learned "real mode" 16-bit x86 when it wasn't called that because it was the only x86 asm that existed. As each new extension was added to the x86 family of CPU's, I learned that. But I am quite sure learning the obsolete stuff first is not a good path for a beginner today.

I already knew many different asm architectures before the 8086 was ever invented. So I never had any need for any book teaching any version or aspect of x86. Intel and AMD published reference manuals and for me those were sufficient for learning each kind of x86 asm.

The AMD reference manuals (free downloadable pdf files) are still the best source for information on x86-64. I think a smart enough beginner could learn using those as the primary resource and never need a book that teaches x86 asm. A good introductory book would be a great help if it exists, but I've only seen bad introductory books.

I don't have any stable URL's for those AMD reference manuals. But I just tried a google search for "support.amd.com/us/Processor_TechDocs/" which seems to give a list of pdf's you can get from that directory (the directory listing is password protected, so you can get files from there only if you know the file name). Most of those pdf files are specialized content mainly for BIOS writers.

One of the important pdf's for any x86-64 asm programmer is
http://support.amd.com/us/Processor_...594_APM_v3.pdf

Last time I posted info about AMD PDF files at LQ I said:
Quote:
Originally Posted by johnsfine View Post
Other useful pdf files in that set included 24592, 24593, 26568 and 26569.
Other things said in that same thread might also help you.

Last edited by johnsfine; 02-24-2013 at 07:53 AM.
 
1 members found this post helpful.
Old 02-24-2013, 02:33 PM   #26
ejspeiro
Member
 
Registered: Feb 2011
Distribution: Ubuntu 14.04 LTS (Trusty Tahr)
Posts: 203

Rep: Reputation: 26
Quote:
Originally Posted by Holering View Post
Wow so many responses thanks for all the help! It's great that some of you provided documentation sources which is really helpful.
Remember that it is considered courteous to click on reputation per useful post.
 
1 members found this post helpful.
Old 02-24-2013, 05:59 PM   #27
jefro
Moderator
 
Registered: Mar 2008
Posts: 21,998

Rep: Reputation: 3629Reputation: 3629Reputation: 3629Reputation: 3629Reputation: 3629Reputation: 3629Reputation: 3629Reputation: 3629Reputation: 3629Reputation: 3629Reputation: 3629
Don't forget to see MenuetOS. It is a great body of work which I'd like to see more of.

http://www.menuetos.net/
 
Old 02-24-2013, 06:07 PM   #28
jefro
Moderator
 
Registered: Mar 2008
Posts: 21,998

Rep: Reputation: 3629Reputation: 3629Reputation: 3629Reputation: 3629Reputation: 3629Reputation: 3629Reputation: 3629Reputation: 3629Reputation: 3629Reputation: 3629Reputation: 3629
Don't forget to see MenuetOS. It is a great body of work which I'd like to see more of.

http://www.menuetos.net/
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
what is a good distro for learning linux? mqazi Linux - Newbie 18 08-12-2005 07:44 AM
What Programs Have Good 'C' code for learning? DvChWi Programming 1 04-30-2005 08:27 PM
Good begginner Learning books Guitarist88 Linux - Newbie 4 06-02-2004 10:04 PM
learning risc assembler BaudRacer Programming 23 12-12-2003 09:30 AM
Learning MySQL. Know a good forum? cevjr Linux - Software 3 12-09-2003 02:17 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:19 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration