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
20
votes
4 answers

How to link a gas assembly program that uses the C standard library with ld without using gcc?

As an exercise to learn more precisely how c programs work and what minimum level of content must exist for a program to be able to use libc, I've taken it upon myself to attempt to program primarily in x86 assembly using gas and ld. As a fun little…
Cyro
  • 203
  • 1
  • 2
  • 4
20
votes
3 answers

Error "no such instruction" while assembling project on Mac OS X

I used homebrew to install GCC 4.7.0 and my project's make is failing at assembly-time. I can successfully take code from .c -> .s, but .s -> .o fails. To view the brew formula used to install GCC, please look at:…
xrl
  • 2,155
  • 5
  • 26
  • 40
19
votes
3 answers

Is there a symbol that represents the current address in GNU GAS assembly?

I am curious to know is there any special GAS syntax to achieve the same like in NASM example: SECTION .data msg: db "Hello World",10,0 ; the 0-terminated string. len: equ $-msg ; "$" means current…
orustammanapov
  • 1,792
  • 5
  • 25
  • 44
19
votes
4 answers

Invalid instruction suffix for push when assembling with gas

When assembling a file with GNU assembler I get the following error: hello.s:6: Error: invalid instruction suffix for `push' Here's the file that I'm trying to assemble: .text LC0: .ascii "Hello, world!\12\0" .globl _main _main: …
vitaut
  • 49,672
  • 25
  • 199
  • 336
18
votes
5 answers

x86_64 Assembly Linux System Call Confusion

I am currently learning Assembly language on Linux. I have been using the book 'Programming From the Ground Up' and all the examples are 32-bit. My OS is 64-bit and I have been trying to do all the examples in 64-bit. I am having trouble…
Hudson Worden
  • 2,263
  • 8
  • 30
  • 45
18
votes
4 answers

What is the use of .byte assembler directive in gnu assembly?

While going through some C code having inline assembly I came across the .byte (with a Dot at the beginning) directive. On checking the assembly reference on web I found that it is used to reserve a byte in memory. But in the code there was no label…
vjain27
  • 3,514
  • 9
  • 41
  • 60
18
votes
2 answers

1b and 1f in GNU assembly

I am analyzing a linux exception code. By the way I can't understand gnu assembly syntax. svc_preempt: mov r8, lr 1: bl preempt_schedule_irq @ irq en/disable is done inside ldr r0, [tsk, #TI_FLAGS] @ get new tasks…
user3247643
  • 283
  • 1
  • 4
  • 7
18
votes
3 answers

internal relocation not fixed up

i recently started assembler programming for arm cores. My first little demos, only with the .text section, ran without any problems. As a logical extension i wanted to structure the assembler code into the usual sections: .text, .data, .bss . So i…
user1146332
  • 2,630
  • 1
  • 15
  • 19
17
votes
1 answer

How do RIP-relative variable references like "[RIP + _a]" in x86-64 GAS Intel-syntax work?

Consider the following variable reference in x64 Intel assembly, where the variable a is declared in the .data section: mov eax, dword ptr [rip + _a] I have trouble understanding how this variable reference works. Since a is a symbol corresponding…
Shuzheng
  • 11,288
  • 20
  • 88
  • 186
16
votes
4 answers

How to call C functions from ARM Assembly?

I'm writing code targeting ARM Cortex-A on Android devices (using GNU assembler and compiler), and I'm trying to interface between Assembly and C. In particular, I'm interested in calling functions written in C from Assembly. I tried many things,…
Phonon
  • 12,549
  • 13
  • 64
  • 114
16
votes
1 answer

x86 assembler: floating point compare

As part of a compiler project I have to write GNU assembler code for x86 to compare floating point values. I have tried to find resources on how to do this online and from what I understand it works like this: Assuming the two values I want to…
JustMaximumPower
  • 1,257
  • 3
  • 11
  • 22
15
votes
2 answers

What does .comm mean?

I just translated this program, #include int dam[1000][1000]; int main (int argc, const char * argv[]) { // insert code here... printf("Hello, World!\n"); return 0; } to assembly using gcc producing, .cstring LC0: …
Pedro Henriques
  • 1,708
  • 1
  • 14
  • 18
15
votes
5 answers

How to install and use GAS (GNU Compiler) on Linux?

I'm using Ubuntu, and I was looking for an assembler compiler for Linux, and I found GAS. I'm trying to install it and run it, but I can't.
rogcg
  • 10,451
  • 20
  • 91
  • 133
15
votes
1 answer

How to produce a minimal BIOS hello world boot sector with GCC that works from a USB stick on real hardware?

I have managed to produce a minimal boot sector that works with QEMU 2.0.0 Ubuntu 14.04: .code16 .global _start _start: cli mov $msg, %si mov $0x0e, %ah loop: lodsb or %al, %al jz halt int $0x10 jmp loop halt: …
Ciro Santilli OurBigBook.com
  • 347,512
  • 102
  • 1,199
  • 985
14
votes
3 answers

Commenting syntax for x86 AT&T syntax assembly

The Intel syntax has comments using the semicolon. When I switched to AT&T, it actually tried to interpret the comments. What is the comment syntax for AT&T assembly?
ihsoy ih
  • 1,008
  • 2
  • 10
  • 20
1
2
3
68 69