gas-intel-howto(7) MirOS Tutorial gas-intel-howto(7)
gas-intel-howto - How to write Intel syntax assembly code with the GNU assembler
Did you always wonder how this new Intel mode of as(1) could be used? Did you wonder why the GNU Texinfo documentation is wrong? This is the answer. First off, how would you start an assembly language pro- gramme? This is a real-life example: /* copyright ... */ #include <machine/asm.h> .intel_syntax noprefix .text Now, you can use all the well-known ops and pseudo-ops from the gas and intel world. You just need to keep track, which one to use. Did you know you can concatenate assembly lines with a semi- colon (';')? Now, how do you issue comments? It's easy. Using gcc -c -o fnord.o fnord.S automatically uses the C Preprocessor, cpp(1), on the file first. That's why the C-style comment in the above example could be used. PSEUDO-OPS All these pseudo-ops, and more, are supported on ELF: .text Denotes a code segment. .data Denotes the data segment. .bss Denotes reserved space. .code32 Generate code for a 32-bit segment (default). .code16 Generate code for a 16-bit segment. .globl symbol This defines a global symbol. For ELF you apparently also need: MirOS BSD #10-current January 26th, 2004 1 gas-intel-howto(7) MirOS Tutorial gas-intel-howto(7) .type symbol, @function This denotes the ELF symbol type. You'd better use the ENTRY(symbol) macro though. .byte .word .long Define bytes (etc.), akin the db command in TASM. .ascii "foo" Define a string, also the same as the db command. .asciz "foo" Define a zero-terminated string. There needs not be extra .byte 0x0A commands for control characters; rather use C escapes like this: .data foo: .asciz "Hello, World!\n" .text bar: mov eax,offset foo push eax call printf pop eax ret
This example also shows the basic command usage. Some com- mands are different from both Intel common and the gas intel_mode texinfo documentation. lret Used exactly as the retf command. mov byte ptr [bx],0x80 The byte ptr is a must. jmp 0xF000,0xFFF0 This is the way long jumps (jmp far) are defined. The manual states wrongly that one has to use jmpl or ljmp. . = 0x40 + _start The org directive refined. Better than in NASM. It also is a good way to check code size boundaries. rep movsd Just write them one after the other. fs mov eax, This is a segment prefix usage. Note, here is no dword ptr needed.
It's not difficult to write intel code in GNU as, once you have learned about the differences. In fact, it is even more MirOS BSD #10-current January 26th, 2004 2 gas-intel-howto(7) MirOS Tutorial gas-intel-howto(7) consistent than for example NASM, which insists on calling pushf pushfw, and issues a pushfd when writing pushf in 32- bit mode.
Copyright (c) 2004 Thorsten Glaser. All rights reserved. Credits go to Intel, AMD, Microsoft, Borland, the NASM and YASM projects and the Free Software Foundation.
Probably some typos and omissions. Also, my nroff isn't the best. Should convert to mdoc. Suggestions to <firstname.lastname@example.org> please. MirOS BSD #10-current January 26th, 2004 3
Generated on 2014-07-04 21:17:45 by $MirOS: src/scripts/roff2htm,v 1.79 2014/02/10 00:36:11 tg Exp $
These manual pages and other documentation are copyrighted by their respective writers;
their source is available at our CVSweb,
AnonCVS, and other mirrors. The rest is Copyright © 2002‒2014 The MirOS Project, Germany.
This product includes material provided by Thorsten Glaser.
This manual page’s HTML representation is supposed to be valid XHTML/1.1; if not, please send a bug report – diffs preferred.