gas-intel-howto man page on MirBSD

Man page or keyword search:  
man Server   6113 pages
apropos Keyword Search (all sections)
Output format
MirBSD logo
[printable version]



gas-intel-howto(7)	 MirOS Tutorial	       gas-intel-howto(7)

NAME
     gas-intel-howto - How to write Intel syntax assembly code
     with the GNU assembler

TUTORIAL
     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

OPERATIONS
     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,[0]
	This is a segment prefix usage. Note, here is no dword
	ptr needed.

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

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

BUGS
     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

[top]

List of man pages available for MirBSD

Copyright (c) for man pages and the logo by the respective OS vendor.

For those who want to learn more, the polarhome community provides shell access and support.

[legal] [privacy] [GNU] [policy] [cookies] [netiquette] [sponsors] [FAQ]
Tweet
Polarhome, production since 1999.
Member of Polarhome portal.
Based on Fawad Halim's script.
....................................................................
Vote for polarhome
Free Shell Accounts :: the biggest list on the net