Gnu Assembler


The GNU Assembler, commonly known as gas or as, is the assembler developed by the GNU Project. It is the default back-end of GCC, and is part of the GNU Binutils package. The default syntax for as is AT&T, but it can be used with Intel syntax by using the .intel_syntax directive.

Program

.global _start

.text
    _start:
        xor     %rbp, %rbp
        sub     $0x20, %sp
        
        add     $0x20, %sp

        xor     %edi, %edi
        mov     $231, %ax
        syscall
        hlt
as -c program.s
ld program.o

BSS Segment

The BSS segment contains uninitialized static data, both variables and constants, i.e. global variables and local static variables that are initialized to zero or do not have explicit initialization in source code.

.bss
    .comm foo, 8
    .lcomm bar, 8

DATA Segment

The data segment contains initialized static variables, that is, global variables and static local variables. The data segment is read/write, since the values of variables can be altered at run time.

.data
    foo: .ascii "BAD1DEA5"
    bar: .octa 0xbad1dea5