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 09-29-2011, 09:10 PM   #1
mreff555
Member
 
Registered: Sep 2011
Location: Philly
Distribution: Gentoo
Posts: 473

Rep: Reputation: Disabled
Assembly


I've been toying with the idea of actually picking up assembly. I've been reading what I can find on the internet and playing with it a little, but I really haven't found anything beyond very basic training. Does anyone know a good free or non-free manual for Linux assembly using the nasm assembler.
 
Old 09-29-2011, 09:15 PM   #2
johnsfine
LQ Guru
 
Registered: Dec 2007
Distribution: Centos
Posts: 5,286

Rep: Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197
There are several decent tutorials for 32 bit x86 assembler using NASM on Linux. Those can be found easily with Google.

I think you are better off learning the syntax of AS rather than the syntax of NASM.

If you have a 64 bit Linux, I think you are better off learning x86_64 assembler rather than 32 bit x86.

That info is quite a bit harder to find on the web than 32-bit, but it is enough more useful to learn that it is worth it.

In my opinion, the people who write asm tutorials waste so much time on obscurities needed for I/O and to be a stand alone program that most people never get to the more important parts of asm. Writing stand alone programs in asm is nearly worthless, even as a learning exercise. A much better learning exercise is writing functions in asm meant to be called via C interface from any language (such as C++) that can call C interface.

gcc is a great tool for learning how to write asm functions callable via C interface. Write a simple function in C and compile it to asm code rather than to a .o and look at the result. You can find a few threads at LQ where someone (sometimes me) has explained a gcc generated .s file, telling you which parts are extra decoration you don't really need in your own .s files and what the important parts mean.

You also need an instruction set reference manual for the architecture (x86 or x86_64). I downloaded that as a few pdf files from the AMD website long ago. I don't have a URL handy, but I expect AMD still gives away those pdf files.

For x86_64, the ABI (calling standard) is also important. Last time I looked, that pdf was free both from AMD and from some independent x86_64 standards group.

Last edited by johnsfine; 09-29-2011 at 09:26 PM.
 
Old 09-29-2011, 09:17 PM   #3
jefro
Moderator
 
Registered: Mar 2008
Posts: 21,982

Rep: Reputation: 3626Reputation: 3626Reputation: 3626Reputation: 3626Reputation: 3626Reputation: 3626Reputation: 3626Reputation: 3626Reputation: 3626Reputation: 3626Reputation: 3626
Check out the MenuetOS site for some of their links.
 
Old 09-29-2011, 09:40 PM   #4
johnsfine
LQ Guru
 
Registered: Dec 2007
Distribution: Centos
Posts: 5,286

Rep: Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197
One of the benefits of learning asm can also be another training aid toward learning asm:

Some of the hardest bugs in programs in other languages are practical to debug only by using asm knowledge and using the debugger in asm mode.

I really hate direct use of gdb. I don't think it is practical for this purpose. But if you strongly prefer command line to GUI you might be OK with direct use of gdb.

I mainly do asm debugging of C++ programs on Windows. When I last did a lot of it on Linux, it was with Insight, which was a lot better than direct use of gdb but had quite a few problems. IIUC, Insight is barely supported at all. I think similar GUI asm debugging is available with CodeBlocks and other tools, but I'm not sure.

Anyway, if you have a usable asm mode debugger, step through some C code you understand, but in asm mode and learn some asm that way. Now try compiling optimized but with debug info and try to step through and understand. That might get a bit frustrating, but it is a powerful learning exercise.
 
Old 09-30-2011, 06:47 AM   #5
mreff555
Member
 
Registered: Sep 2011
Location: Philly
Distribution: Gentoo
Posts: 473

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by johnsfine View Post
Anyway, if you have a usable asm mode debugger, step through some C code you understand, but in asm mode and learn some asm that way. Now try compiling optimized but with debug info and try to step through and understand. That might get a bit frustrating, but it is a powerful learning exercise.
I like this idea, I think I'll give it a try.
 
  


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
assembly and c tokernizer Programming 8 04-16-2006 11:40 AM
assembly ? blackzone Programming 3 10-15-2004 02:36 AM
Assembly jinksys Programming 3 09-14-2003 04:33 PM
I need help for Assembly skb Programming 10 08-01-2003 04:51 PM
assembly genghis Programming 2 06-12-2003 07:46 AM

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

All times are GMT -5. The time now is 05:47 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