MirOS Manual: gas-intel-howto(7)

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
     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

     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.

     All these pseudo-ops, and more, are supported on ELF:

        Denotes a code segment.

        Denotes the data segment.

        Denotes reserved space.

        Generate code for a 32-bit segment (default).

        Generate code for a 16-bit segment.

     .globl symbol
        This defines a global symbol. For ELF you apparently also

MirOS BSD #10-current  January 26th, 2004                       1


     .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:
        foo: .asciz  "Hello, World!\n"
        bar: mov     eax,offset foo
             push    eax
             call    printf
             pop     eax


     This example also shows the basic command usage. Some com-
     mands are different from both Intel common and the gas
     intel_mode texinfo documentation.

        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,[0]
        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


     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 <miros-discuss@mirbsd.org> please.

MirOS BSD #10-current  January 26th, 2004                       3


This product includes material provided by Thorsten Glaser.
