ASM | Assembly Language

Please download to get full document.

View again

of 45
All materials on our website are shared by users. If you have any questions about copyright issues, please report us to resolve them. We are always happy to assist you.
Information Report
Category:

Instruction manuals

Published:

Views: 2 | Pages: 45

Extension: PDF | Download: 0

Share
Related documents
Description
Assembly language
Transcript
  Linux Assembly HOWTO Konstantin Boldyshev Linux Assemblykonst@linuxassembly.org Francois−Rene Rideau Tunes projectfare@tunes.orgCopyright © 1999−2002 by Konstantin BoldyshevCopyright © 1996−1999 by Francois−Rene Rideau$Date: 2002/08/17 08:35:59 $This is the Linux Assembly HOWTO, version 0.6f. This document describes how to program in assemblylanguage using free programming tools, focusing on development for or from the Linux Operating System,mostly on IA−32 (i386) platform. Included material may or may not be applicable to other hardware and/orsoftware platforms.Permission is granted to copy, distribute and/or modify this document under the terms of the GNU FreeDocumentation License, Version 1.1; with no Invariant Sections, with no Front−Cover Texts, and noBack−Cover texts.  Table of Contents Chapter 1. Introduction......................................................................................................................................1Chapter 2. Do you need assembly?....................................................................................................................3 2.1. Pros and Cons...................................................................................................................................32.1.1. The advantages of Assembly...................................................................................................32.1.2. The disadvantages of Assembly..............................................................................................32.1.3. Assessment..............................................................................................................................42.2. How to NOT use Assembly..............................................................................................................42.2.1. General procedure to achieve efficient code...........................................................................42.2.2. Languages with optimizing compilers....................................................................................52.2.3. General procedure to speed your code up...............................................................................52.2.4. Inspecting compiler−generated code.......................................................................................52.3. Linux and assembly..........................................................................................................................6 Chapter 3. Assemblers........................................................................................................................................7 3.1. GCC Inline Assembly.......................................................................................................................73.1.1. Where tofind GCC..................................................................................................................73.1.2. Where to find docs for GCC Inline Asm.................................................................................73.1.3. InvokingGCC to build proper inline assembly code..............................................................83.1.4. Macro support..........................................................................................................................93.2. GAS..................................................................................................................................................93.2.1. Where tofind it........................................................................................................................93.2.2. What is this AT&T syntax.......................................................................................................93.2.3. Intel syntax............................................................................................................................103.2.4. 16−bit mode...........................................................................................................................103.2.5. Macro support........................................................................................................................103.3. NASM.............................................................................................................................................113.3.1. Where tofind NASM............................................................................................................113.3.2. What it does...........................................................................................................................113.4. AS86...............................................................................................................................................113.4.1. Where to get AS86................................................................................................................113.4.2. Where tofind docs................................................................................................................123.4.3. Using AS86 with BCC..........................................................................................................123.5. Other Assemblers............................................................................................................................123.5.1. YASM...................................................................................................................................123.5.2. FASM....................................................................................................................................123.5.3. OSIMPA(SHASM)..............................................................................................................133.5.4. TDASM.................................................................................................................................133.5.5. HLA.......................................................................................................................................133.5.6. TALC.....................................................................................................................................133.5.7. Free Pascal.............................................................................................................................133.5.8. Win32Forth assembler..........................................................................................................143.5.9. Terse......................................................................................................................................143.5.10. Non−free and/or Non−32bit x86 assemblers......................................................................14 Chapter 4. Metaprogramming.........................................................................................................................16 4.1. External filters.................................................................................................................................164.1.1. CPP........................................................................................................................................16 Linux Assembly HOWTOi  Table of Contents Chapter 4. Metaprogramming 4.1.2. M4...................................................................................................................................164.1.3. Macroprocessing with your own filter..................................................................................174.2. Metaprogramming...........................................................................................................................174.2.1. Backends from compilers......................................................................................................174.2.2. The New−Jersey Machine−Code Toolkit.............................................................................174.2.3. TUNES..................................................................................................................................17 Chapter 5. Calling conventions........................................................................................................................18 5.1. Linux...............................................................................................................................................185.1.1. Linking toGCC.....................................................................................................................185.1.2. ELF vs a.out problems...........................................................................................................185.1.3. DirectLinux syscalls.............................................................................................................185.1.4. Hardware I/O under Linux....................................................................................................205.1.5. Accessing 16−bit drivers from Linux/i386...........................................................................215.2. DOS and Windows.........................................................................................................................215.3. Your own OS..................................................................................................................................22 Chapter 6. Quick start......................................................................................................................................23 6.1. Introduction.....................................................................................................................................236.1.1. Tools youneed......................................................................................................................236.2. Hello, world!...................................................................................................................................236.2.1. Program layout......................................................................................................................236.2.2. NASM (hello.asm)................................................................................................................236.2.3. GAS (hello.S)........................................................................................................................246.3. Building an executable....................................................................................................................246.3.1. Producing object code...........................................................................................................246.3.2. Producing executable............................................................................................................25 Chapter 7. Resources........................................................................................................................................26Chapter 8. Frequently Asked Questions.........................................................................................................27Appendix A. History.........................................................................................................................................33Appendix B. Acknowledgements.....................................................................................................................36Appendix C. Endorsements..............................................................................................................................37Appendix D. GNU Free Documentation License...........................................................................................38 Linux Assembly HOWTOii  Chapter 1. Introduction You can skip this chapter if you are familiar with HOWTOs, or just hate to read all thisassembly−unrelated crap. 1.1. Legal Blurb Permission is granted to copy, distribute and/or modify this document under the terms of the GNUFreeDocumentation LicenseVersion 1.1; with no Invariant Sections, with no Front−CoverTexts, and noBack−Cover texts. A copy of the license is included in theGNU Free Documentation Licenseappendix.The most recent official version of this document is available from theLinux AssemblyandLDPsites. If you are reading a few−months−old copy, consider checking the above URLs for a new version. 1.2. Foreword This document aims answering questions of those who program or want to program 32−bit x86 assemblyusing free software , particularly under the Linux operating system. At many places Universal ResourceLocators (URL) are given for some software or documentation repository. This document also points to otherdocuments about non−free, non−x86, or non−32−bit assemblers, although this is not its primary goal. Alsonote that there are FAQs and docs about programming on your favorite platform (whatever it is), which youshould consult for platform−specific issues, not related directly to assembly programming.Because the main interest of assembly programming is to build the guts of operating systems, interpreters,compilers, and games, where C compiler fails to provide the needed expressiveness (performance is more and more seldom as issue), we are focusing on development of such kind of software.If you don't know what free software is, please do read carefully the GNUGeneral Public License(GPL orcopyleft), which is used in a lot of free software, and is the model for most of their licenses. It generallycomes in a file named COPYING (or COPYING.LIB ). Literature from theFree Software Foundation(FSF)might help you too. Particularly, the interesting feature of free software is that it comes with source codewhich you can consult and correct, or sometimes even borrow from. Read your particular license carefully anddo comply to it. 1.3. Contributions This is an interactively evolving document: you are especially invited to ask questions, to answer questions, tocorrect given answers, to give pointers to new software, to point the current maintainer to bugs or deficienciesin the pages. In one word, contribute!To contribute, please contactthe maintainer. At the time of writing, it isKonstantin Boldyshevand no moreFrancois−Rene Rideau(since version 0.5). I (Fare) had been looking for some time for a serious hacker to replace me as maintainer of thisdocument, and am pleased to announceKonstantinas my worthy successor. Chapter 1. Introduction1
We Need Your Support
Thank you for visiting our website and your interest in our free products and services. We are nonprofit website to share and download documents. To the running of this website, we need your help to support us.

Thanks to everyone for your continued support.

No, Thanks