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
10
votes
2 answers

How to concatenate GNU GAS macro arguments with other tokens to make single label?

I would like to dynamically create a set of labels in an assembly function using a gas macro. I would like to do something like this: .macro set_up_jumptab_entry prefix, from=0, to=10 .quad \prefix_\item .if \to-\from …
pgod
  • 583
  • 4
  • 10
10
votes
5 answers

What does 0x4 do in "movl $0x2d, 0x4(%esp)"?

I am looking into assembly code generated by GCC. But I don't understand: movl $0x2d, 0x4(%esp) In the second operand, what does 0x4 stands for? offset address? And what the use of register EAX?
martin
  • 643
  • 1
  • 10
  • 19
10
votes
4 answers

What does the ".align" x86 Assembler directive do exactly?

I will list exactly what I do not understand, and show you the parts I can not understand as well. First off, The .Align Directive .align integer, pad. The .align directive causes the next data generated to be aligned modulo integer bytes 1.~ ?…
Sinister Clock
  • 169
  • 1
  • 2
  • 4
10
votes
2 answers

How to get the size of a C function from inside a C program or with inline assembly?

Suppose I have a function like below: # cat 003.c int foo(int a, int b) { return a+b; } And compile it like this: gcc -S 003.c The gets the following assembly result: .file "003.c" .text .globl foo .type foo, @function …
yang wen
  • 427
  • 4
  • 15
9
votes
4 answers

Generating assembly code from C# code?

Is there any way to generate assembly code from C# code? I know that it is possible with C code with GAS, but does anybody know if it's possible with C#?
dsta
  • 253
  • 1
  • 6
  • 15
9
votes
1 answer

In assembly, how do you deal with C struct?

For example, how to prepare parameters for this syscall sys_wait4: asmlinkage long sys_wait4(pid_t pid,unsigned int __user *stat_addr, int options, struct rusage __user *ru) 1120 { How to deal with struct rusage in assembly? A hello world example…
R__
  • 1,441
  • 5
  • 16
  • 22
9
votes
2 answers

Macro substituting a constant number in GAS

What't wrong with that macro on X86 GNU Assembly? It says the symbol S is undefined during linking. .macro S size=40 \size .endm I'm using it like mov %eax, S
Michael Pankov
  • 3,581
  • 2
  • 23
  • 31
9
votes
1 answer

Distinguishing memory from constant in GNU as .intel_syntax

I have an instruction written in Intel syntax (using gas as my assembler) that looks like this: mov rdx, msg_size ... msg: .ascii "Hello, world!\n" .set msg_size, . - msg but that mov instruction is being assembled to mov 0xe,%rdx, rather than…
Alex Reinking
  • 16,724
  • 5
  • 52
  • 86
8
votes
3 answers

How to compile an assembly file to a raw binary (like DOS .com) format with GNU assembler (as)?

I want to compile this source code in Windows (It just an example): start: NOP NOP When I compile it with NASM or FASM, output file length is 2 bytes. But when I compile it with GNU assembler (as) the output file length is 292 bytes! How to…
Amir Saniyan
  • 13,014
  • 20
  • 92
  • 137
8
votes
1 answer

documentation of gnu assembler directives

I'm trying to learn mips assembly at the moment. To that end, I wrote a very simple c program... int main(){} ...and compiled it on a mips machine with the -S option to gcc to generate assembly code. Here is what the beginning of the main function…
Kim Stebel
  • 41,826
  • 12
  • 125
  • 142
8
votes
1 answer

jonesforth segmentation fault

System I'm on: /tmp/jonesforth $ cat /etc/issue Ubuntu 16.04.1 LTS \n \l This is a 32-bit system. Clone from the annexia repository: git clone git://git.annexia.org/git/jonesforth.git The build goes OK: cd jonesforth /tmp/jonesforth $ make gcc…
dharmatech
  • 8,979
  • 8
  • 42
  • 88
8
votes
1 answer

What's a good way to deal with or remember backwards arguments to cmp in the GNU assembler?

Here is some assembly code in Intel syntax: // Jump to done if rsi >= rax. cmp rsi, rax jae done This makes sense to my brain: you jump if rsi is "above or equal to" rax, matching the order of arguments in the cmp instruction. Compare this to…
jacobsa
  • 5,719
  • 1
  • 28
  • 60
8
votes
1 answer

What does the ljmp instruction do in the linux kernel fork system call?

I am studying linux kernel source (old version 0.11v). When I checked about fork system call, there is some asm code for context switching like this: /* * switch_to(n) should switch tasks to task nr n, first * checking that n isn't the current…
bongsu
  • 185
  • 2
  • 9
8
votes
3 answers

Range of immediate values in ARMv8 A64 assembly

My understanding is that immediate parameters in ARMv8 A64 assembly can be 12 bits long. If that is the case, why does this line of assembly code: AND X12, X10, 0xFEF Produce this error (when compiled with gcc) Error: immediate out of range at…
Zack
  • 6,232
  • 8
  • 38
  • 68
8
votes
1 answer

Move quadword between xmm and general-purpose register in ml64?

In a simple program written for Microsoft's x64 assembler, I want to move a 64-bit value between an SSE register (say xmm0) and a general-purpose register (say rcx), as in : mov xmm0, rcx ... mov rcx, xmm0 These two lines…
0xbe5077ed
  • 4,565
  • 6
  • 35
  • 77