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
hltas -c program.s -o program.o
ld program.o -o programBSS 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
movl $0xbad1dea5, foo
movq $foo, -0x8(%rsp)
mov $0xd15ab1ed, bar
mov $bar, %raxDATA 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
mov $foo, %rdi
mov $bar, %esiMacro
.macro foo
nop
.endm
.macro bar, from=0, to:req
nop
.if \to-\from
bar "(\from+1)",\to
.endif
.endm
foo
bar ,5