Questions tagged [gnu-assembler]

The GNU Assembler (GAS). Use for GAS macros, machine dependent syntax, linkage and file format issues. Do use for generic assembler questions about how the machine works; the CPU tags are meant for this.

'gas' or the GNU assembler is used by GCC to process assembler files. It is included in the binutils suite of tools.

Relevant topics include gas macros, machine dependent GAS syntax, linkage and output formats (usually ELF sections). There isn't any need to tag generic assembler question just because 'gas' is being used. Use the CPU tag such as , , , etc. instead.

(For x86, is the syntax used by default by GAS, GCC, and other GNU tools. Its operands are in reverse order from Intel's documentation.)

A manual is hosted online at sourceware.org as well as a possible locally installed version matching the GAS in use.


This tag was formerly called [gas], renamed because lots of Google Apps Script questions were getting mistagged as gas.

1024 questions
136
votes
4 answers

What are CFI directives in Gnu Assembler (GAS) used for?

There seem to be a .CFI directive after every line and also there are wide varieties of these ex.,.cfi_startproc , .cfi_endproc etc.. more here. .file "temp.c" .text .globl main .type main, @function main: .LFB0: .cfi_startproc …
claws
  • 52,236
  • 58
  • 146
  • 195
73
votes
2 answers

GAS: Explanation of .cfi_def_cfa_offset

I would like an explanation for the values used with the .cfi_def_cfa_offset directives in assembly generated by GCC. I know vaguely that the .cfi directives are involved in call frames and stack unwinding, but I would like a more detailed…
void-pointer
  • 14,247
  • 11
  • 43
  • 61
62
votes
3 answers

What is register %eiz?

In the following assembly code that I dumped out using objdump: lea 0x0(%esi,%eiz,1),%esi What is register %eiz? What does the preceding code mean?
Summer_More_More_Tea
  • 12,740
  • 12
  • 51
  • 83
59
votes
5 answers

NASM Vs GAS (Practical differences)

I'm not trying to prompt an Intel vs AT&T war (moot point anyway, now that they both support Intel syntax) or ask which one is "better" per se, I just want to know the practical differences in choosing one or the other. Basically, when I was picking…
Elliott
  • 1,127
  • 1
  • 9
  • 16
57
votes
5 answers

GCC's assembly output of an empty program on x86, win32

I write empty programs to annoy the hell out of stackoverflow coders, NOT. I am just exploring the gnu toolchain. Now the following might be too deep for me, but to continuie the empty program saga I have started to examine the output of the C…
George
  • 15,241
  • 22
  • 66
  • 83
46
votes
7 answers

Is it possible to create threads without system calls in Linux x86 GAS assembly?

Whilst learning the "assembler language" (in linux on a x86 architecture using the GNU as assembler), one of the aha moments was the possibility of using system calls. These system calls come in very handy and are sometimes even necessary as your…
sven
  • 18,198
  • 10
  • 51
  • 62
37
votes
4 answers

What does cltq do in assembly?

0x0000000000400553 : mov -0x4(%rbp),%eax 0x0000000000400556 : cltq 0x0000000000400558 : shl $0x3,%rax 0x000000000040055c : mov %rax,%rdx In fact my programe is as simple as : 5 int main(int…
R__
  • 1,441
  • 5
  • 16
  • 22
35
votes
1 answer

How to use RIP Relative Addressing in a 64-bit assembly program?

How do I use RIP Relative Addressing in a Linux assembly program for the AMD64 archtitecture? I am looking for a simple example (a Hello world program) that uses the AMD64 RIP relative adressing mode. For example the following 64-bit assembly…
Erik
  • 4,268
  • 5
  • 33
  • 49
26
votes
2 answers

How to generate plain binaries like nasm -f bin with the GNU GAS assembler?

I have some NASM files that generally have the structure: [BITS 64] [ORG 0x0000000000200000] start: ... ret I'm assembling them like so: nasm -f bin abc.asm I'd like to write some of these using GAS instead. Two…
dharmatech
  • 8,979
  • 8
  • 42
  • 88
26
votes
4 answers

calling assembly functions from c

I'm trying to use a function in assembly, invoked from a C project. This function is supposed to call a libc function let's say printf(), but I keep getting a segmentation fault. In the .c file I have the declaration of the function let's say int…
user173973
26
votes
3 answers

How to generate a nasm compilable assembly code from c source code on Linux?

Test platform is 32 bit Linux. Basically, I know gcc can be used to generate both Intel and At&T style assembly code, but it seems that you can not directly use nasm/tasm to compile the Intel style assembly code gcc generated. I am conducting a…
lllllllllllll
  • 8,519
  • 9
  • 45
  • 80
24
votes
4 answers

GCC: Prohibit use of some registers

This is a strange request but I have a feeling that it could be possible. What I would like is to insert some pragmas or directives into areas of my code (written in C) so that GCC's register allocator will not use them. I understand that I can do…
hayesti
  • 2,993
  • 2
  • 23
  • 34
24
votes
4 answers

MOV src, dest (or) MOV dest, src?

MOV is probably the first instruction everyone learns while learning ASM. Just now I encountered a book Assembly Language Programming in GNU/Linux for IA32 Architectures By Rajat Moona which says: (broken link removed) But I learnt that it is MOV…
claws
  • 52,236
  • 58
  • 146
  • 195
22
votes
3 answers

When are GAS ELF the directives .type, .thumb, .size and .section needed?

I'm working on an assembly program for an ARM Cortex-M3 based microcontroller (Thumb 2 instruction set), using GNU as. In some example code I find directives like .size, .section and .type which I understand are ELF directives. As an example: …
user1481860
20
votes
2 answers

Calling printf in x86_64 using GNU assembler

I've written a program using AT&T syntax for use with GNU assembler: .data format: .ascii "%d\n" .text .global main main: mov $format, %rbx mov (%rbx), %rdi mov …
L's World
  • 423
  • 1
  • 5
  • 13
1
2 3
68 69