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
13
votes
1 answer

What is the difference between .global and .globl?

For example, I've seen _start as .global _start and .globl _start. It seems like I can just use them interchangeably. Is there any difference between the two?
Al Smith
  • 203
  • 2
  • 8
12
votes
3 answers

Understanding Base Pointer and Stack Pointers: In Context with gcc Output

I have the following C program: int main() { int c[10] = {0, 0, 0, 0, 0, 0, 0, 0, 1, 2}; return c[0]; } and when compiled using the -S directive with gcc I get the following assembly: .file "array.c" .text .globl main .type …
Matthew Hoggan
  • 7,402
  • 16
  • 75
  • 140
12
votes
4 answers

What does the bracket in `movl (%eax), %eax` mean?

I have googled enough but could not figure out what the bracket () means. Also, I see some syntax as movl 8(%ebp), %eax Could some someone suggest me some good reference? I have not been able to find any in the top 20 results from Google.
Lord Loh.
  • 2,437
  • 7
  • 39
  • 64
12
votes
2 answers

Why is GNU as syntax different between x86 and ARM?

I've just started learning ARM assembly and I don't understand why the GNU as syntax is not the same than for x86*. As the directives are the same, I would have expected everything to be like x86* except the instructions themselves, but instead, I'm…
Benoît
  • 3,355
  • 2
  • 29
  • 34
11
votes
1 answer

How can I mitigate the impact of the Intel jcc erratum on gcc?

If I have a chip that is subject to the Intel jcc erratum, how I can enable the mitigation in gcc (which adjusts branch locations to avoid the problematic alignment), and which gcc versions support it?
BeeOnRope
  • 60,350
  • 16
  • 207
  • 386
11
votes
1 answer

Using ".intel_syntax noprefix" how can I get memory address of a label?

I'm learning how to create real mode programs assembled and linked with: GCC Assembler version 2.25 Binutils version 2.25 GCC version 5.2.0 I use Intel syntax without prefixes specified with .intel_syntax noprefix I want to load the address of a…
TheDome
  • 343
  • 3
  • 10
11
votes
1 answer

What's the difference between the .asciz and the .string assembler directives?

I know that the .ascii directive doesn't put a null character at the end of the string, as the .asciz directive is used for that purpose. However, I don't know whether the .string directive puts a null character at the end of the string. If it does…
Aadit M Shah
  • 72,912
  • 30
  • 168
  • 299
11
votes
1 answer

Why does switching from AT&T to Intel syntax make this tutorial segfault using GAS?

I'm working through some of the tutorials on http://www.ibm.com/developerworks/linux/library/l-gas-nasm/index.html to familiarize myself with x86/x64. This tutorial code compiles and runs without a hiccup using the provided code, which uses AT&T…
Alex
  • 599
  • 1
  • 4
  • 16
11
votes
3 answers

How to make the GNU Assembler use a slash / for comments?

This is indeed a stupid idiosyncrasy of mine, but I can't stand the way GNU AS uses to insert a comment. I am too accustomed to the Sun way (the same used in most UNIX assemblers), that uses a simple slash "/" to comment out the code till the end…
mghis
  • 517
  • 1
  • 5
  • 14
11
votes
6 answers

gas vs. nasm: which assembler produces the best code?

Both tools translate assembly instructions directly into machine code, but is it possible to determine which one produces the fastest and cleanest code?
user157000
11
votes
2 answers

Why does GCC emit "lea" instead of "sub" for subtraction?

I am looking at some assembly that was generated by disassembling some C programs and I am confused by a single optimization that I see repeated frequently. When I have no optimizations on the GCC compiler uses the subl instruction for subtraction,…
Hunter McMillen
  • 59,865
  • 24
  • 119
  • 170
10
votes
2 answers

How to link a C object file with a Assembly Language object file?

I am having trouble linking 2 object files one of which was generated from an Assembly Language Source File and another that was generated from a C Source file. C source code: //main2.c extern int strlength(char *); int main(){ char * test =…
Hudson Worden
  • 2,263
  • 8
  • 30
  • 45
10
votes
3 answers

what is the difference between a label and a function in assembly

have been following an assembly tutorial on youtube here through AT&T syntax. I have just learned about declaring(if that's the correct term here) a function with the .type directive, such as: .type MyFunction, @function Now I can define my…
user3118363
  • 337
  • 4
  • 13
10
votes
2 answers

What do the instructions mov %edi and mov %rsi do?

I've written a basic C program that defines an integer variable x, sets it to zero and returns the value of that variable: #include int main(int argc, char **argv) { int x; x = 0; return x; } When I dump the object code using…
user4099632
10
votes
5 answers

GCC Assembly Optimizations - Why are these equivalent?

I am trying to learn how assembly works at an elementary level and so I have been playing with the -S output of gcc compilations. I wrote a simple program that defines two bytes and returns their sum. The entire program follows: int main(void) { …
Kin3TiX
  • 708
  • 1
  • 5
  • 18
1 2
3
68 69