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.
989
questions
0
votes
0
answers
10
views
GNU assembler: what is -c option?
I see that GNU assembler supports -c option:
$ as -c t1.S
However, I cannot find -c option in man as:
$ man as | grep -P '\-c\s+'
gcc -c -g -O -Wa,-alh,-L file.c
A simple question: ...
0
votes
0
answers
17
views
Assembling armv8-a neon with gnu assembler
I am trying to assemble aarch64 neon instructions with the gnu assembler. The example is from the neon programming quick reference
.text
.align 4
.global add_float_neon2
.type ...
1
vote
1
answer
45
views
x86_64 assembly mmap syscall [duplicate]
I try to make very simple memory allocator, but it gives me error on output, additionally the print_sys_error doesn't work properly. It works if I call it by this code:
_start:
sub $16, %rsp # ...
0
votes
1
answer
41
views
Consuming the output of `llc` with an assembler
LLVM's llc utility can compile an LLVM bitfile into an assembly file:
$ llc-15 -march=avr -mcpu=atmega32u4 foo.ll -filetype=asm -o foo.ll.s
However, the resulting .s file can't be assembled as-is ...
2
votes
0
answers
58
views
Assembly Code Behaves Funny / Unexpected - ASM x86-64 Bit (AT&T, GAS)
My setup
OS: ------------------ Linux
Architecture: ------ x86-64
Syntax: ------------ AT&T
Compiler: --------- GAS
My code
(explanation below)
.section .text
.globl _start
print:
movq $1, %...
2
votes
1
answer
66
views
Why do I get a strangely long opcode when attempting a RIP-relative direct jump with `*...(%rip)` in AT&T assembly?
The thing is that I cannot force gnu as interpret jmp as short or near, it constantly interprets it as far.
For instance, the following code causes segfault:
int main() {
asm volatile (
// &...
4
votes
0
answers
39
views
How does $$ and $ in nasm translate to Gnu Assembler?
In NASM I can write jmp $ and use ($-$$), but what is the equivalent in GNU Assembler (GAS).
1
vote
1
answer
28
views
equivalent of NASM's "dd" in Gnu Assembler
I'm trying to translate dd from NASM (or MASM) to GAS.
I can't find it anywhere in the manual.
5
votes
1
answer
87
views
Is there a way to use NASM syntax for inline assembly?
I really dislike the GNU Assembler syntax and I some existing code written with NASM syntax that would be quite painful and time consuming to port.
Is it possible to make the global_asm!() macro use ...
2
votes
0
answers
40
views
gas not honoring short jump suffix .d8
I want to force gas to emit a relative conditional jump in a short opcode, but it always uses rel32 encoding. Here is my code:
.text
.org 0x123450
.globl test
test:
je.d8 0x123450
Which emits, when ...
5
votes
1
answer
54
views
How to correctly use the "write" syscall on MacOS to print to stdout?
I have looked at similar questions, but cannot seem to find what is wrong with my code.
I am attempting to make the "write" syscall on MacOS to print a string to standard output.
I am able ...
0
votes
0
answers
57
views
GAS GNU Assembly. Segmentation Fault calling printf. Jonathan-Bartlett book listing p98 (without comments): printf-example.s
This is the code (rid of most comments '#' for readability. "..._nude.s" in example namefile refers to this):
1 #PURPOSE: This program is to demonstrate how to call printf
2
3 ....
-1
votes
1
answer
52
views
Cannot open disk file using assembler syscalls on aarch64 device
I am a Hobby programmer here now trying to get into assembler for an android phone. I cannot open a disk file.
I would dearly like to get past this hurdle if anybody with a knowledge of gnu assemblers ...
1
vote
1
answer
37
views
Global assembly in Rust/LLVM: "jmp %rax" is not allowed but the syntax is fine in GAS (mnemonic without a size suffix) [duplicate]
I noticed that, unlike GNU as (GAS), the LLVM-internal assembler, which is used by Rust, doesn't allow using jmp %rax. The compiler errors with "mnemonic without a size suffix". If I try ...
1
vote
1
answer
44
views
Will it be OK to access data through a data segment register after I disturb gdt table?
I had set the gdt table using this data
uint16_t gdt_table[][4] = {
{ 0, 0, 0, 0 },
{ 0xFFFF, 0x0000, 0x9a00, 0x00cf },
{ 0xFFFF, 0x0000, 0x9200, ...
0
votes
0
answers
29
views
What's the syntax mean retf $12 in GAS? [duplicate]
In a syscall_handler, I found the code
syscall_handler:
push %ds
pusha
mov $KERNEL_DATA_SEGMENT, %ax
mov %ax,%ds
mov %esp, %ebp
push 13*4(%ebp)
push 12*4(%ebp)
push ...
3
votes
0
answers
82
views
GAS .rept does not receive a label?
In NASM, I can easily do it using label like this
times 510-($-$$) db 0
db 0x55, 0xaa
However, I can not use label in a GAS .rept command, It is invalid
current:
.rept 510-current-...
0
votes
1
answer
30
views
.quad $label in AT&T syntax: undefined reference to [label-name]
I learn assembler(AT&T). I tried to write program to find the length of the biggest string in record.
During linking with command
ld person-data-with-names-pointer.o find-longest-name.o -o longest
...
3
votes
1
answer
98
views
why does mov %ax, %ds assemble+disassemble as mov %eax,%ds, inconsistent with the original?
test.S
.text
.global _start
_start:
xor %ax, %ax
mov %ax, %ds
mov %ax, %ss
mov %ax, %es
mov %ax, %fs
mov %ax, %gs
I got the disassembly code file ...
0
votes
1
answer
62
views
Align assembly to end of 4K block
I have some assembly. I'd like it to be at the end of a 4K block. Currently the section is being put at 0x1000003C0, I'd like it to be located at 0x100003F80.
I tried using p2align but it seems it ...
0
votes
2
answers
86
views
Assembling ARM instructions on x86_64
I have a file, foo.S, which contains ARM thumb instructions, on an Ubuntu 22.04 x86_64 machine. Is it possible to convert this into an ARM object file using as from binutils or do I need to create a ...
2
votes
1
answer
74
views
What's the difference between .code16 and .code32
I am learning to program a system core of i386 by watching some videos. I've known some procedures about entering protected mode:
In a .code16 file, first I need to open A20 Address Line and changed ...
0
votes
1
answer
51
views
How can I expand the macro in ARM assembly?
.macro f x,y
...
.endm
....
f x10,x11
How can I expand the usage of macro f x10,x11? gcc -E doesn't seem to help, FWIW.
0
votes
0
answers
50
views
How do I compile assembly?
The problem is that I have a filesystem in documents/assembly that goes like this:
test.s:
.global _start
.text
_start:
mov $60, %rax # exit
mov $0, %rdi # return code 0
syscall
...
0
votes
0
answers
33
views
How to perform logical shift(PSLLDQ) within 128 bit SSE Registers in GAS Assembly?
I want to perform PSLLDQ instruction in GAS Assembly to shift arbitrary bytes within 128 bit SSE registers.
pslldq $13, %xmm14 # performs shift left by 13 bytes within xmm14
Now, this ...
0
votes
0
answers
16
views
PCMPESTRM is not working when explicit length is 1
I want to compare a string with length (max = 15) to check characters are in Range 'A' to 'Z' in assembly language. I am using PCMPESTRM instruction to perform this operation. My implementation(GAS) ...
1
vote
1
answer
23
views
Overflow in constants (specifically in .byte) assembler directives (especially gas and clang)
Is there a way to have the assembler (gas or clang) output an error, not a warning, if the operand to a .byte directive overflows?
I'm specifically thinking of constructs such as this on ARM:
tbb [...
0
votes
0
answers
23
views
How can I get this .c file to read a .s file and run in VS code?
I have two files, one being main.c and the other prog2.s that contains assembly code. The commands I am running are:
gcc -Wall -g -m32 -c main.c
gcc -Wall -g -m32 -c prog2.s
gcc -Wall -g -m32 -o xtest ...
3
votes
2
answers
166
views
What is the problem with this jump instruction?
I was given the following instructions:
Make the first instruction in your code a jmp
Make that jmp a relative jump to 0x51 bytes from its current position
At 0x51 write the following code:
Place the ...
0
votes
1
answer
24
views
`ld` adds code to `0x1000` instead of `0x0`
I've the following files:
boot.s
.section code_section
code:
jmp code
.section boot_magic_section
boot_magic:
.word 0xaa55
linker_script.ld
SECTIONS {
beginning : {
boot.o(...
0
votes
0
answers
18
views
`as` + objdump skips custom section when assembling + disassembling
I have the following file:
test.s
.section a_random_section
label_number1:
jmp label_number1
and after executing as -o test.o test.s && objdump -d test.o I'm getting the following output:...
0
votes
0
answers
21
views
What does the "b 1b" mean this arm64 assembly code? [duplicate]
.section ".text.boot" // Make sure the linker puts this at the start of the kernel image
.global _start // Execution starts here
_start:
// Check processor ID is zero (executing on ...
0
votes
0
answers
41
views
Why am I getting this error: "frameCount.c:(.text+0x15): undefined reference to `getFP'"? [duplicate]
I am writing a program to count the amount of stack frames their are on the stack at the time frameCount is called. Its an assignment for school I have to use getFP.s to return the contents of the %...
0
votes
1
answer
104
views
(x86-64) GNU Assembly macro
I just started learning about assembly but I got confused with the .macro function. I have been able to find examples which are used to add some numbers in a range but none with strings. If I wanted ...
1
vote
0
answers
68
views
undefined reference to `WinMain@16' - Assembler
I wrote a sort function in C and then compiled it into assembler code (with help of the -S flag in GCC). When I try to compile this assembly code, GCC gives an error undefined reference to `WinMain@16'...
0
votes
2
answers
102
views
What is GNU AS equivalent of NASM's db (define bytes)?
Currently trying to convert this line
db 0x7F, "ELF", 1, 1, 1, 0
to GNU AS. I'm not sure what I should use.
-2
votes
1
answer
90
views
Correct LDR Rd,=constant_expression usage in GCC / GAS?
I'm migrating from Ride7 to Eclipse CDT with GNU arm-none-eabi toolchain.
In my project, I have a hardware register description library using .equ directive in a way like:
.equ BIT_31, 1 << 31
....
0
votes
0
answers
57
views
la Instruction Returning Weird Memory Addresses on .asciz Symbols (gas / ld / RISCV / Devterm R-01)
EDIT: I've added the contents of objdump -dr to the bottom of this question.
EDI: I was asked to provide the value for $gp, and the addresses of .text and .data; they are at the bottom of this ...
0
votes
0
answers
131
views
Assembly error message: bad register name
I have the following assembly code:
.data
.globl shellcode
shellcode:
jmp over_string
string_addr:
.ascii "/bin/shNAAAAAAAABBBBBBBB"
over_string:
leaq string_addr(%rip), %rdi
xorl %eax, %eax
...
1
vote
1
answer
138
views
gnu GAS use stdio.h in asm and compile 32 bit on 64 bit host
I want to compile the following asm.S file
#include <stdio.h>
.global _start
.text
message_text:
call program
str: .string "hello world"
.equ len, (. - str)
_start:
jmp ...
1
vote
1
answer
55
views
.S assembly code Macro to apply another macro to multiple registers in .S
In .S assembly code, I want to write a macro that takes as "argument" another macro, that is then applied to multiple registers. A minimal example would be:
.macro add_macro reg1 reg2
...
1
vote
1
answer
115
views
ARM inline assembly: Move function address to register
I wanted to load the address of function to a register. I have written the following inline assembly. The inline assembler returns the error "Error: undefined symbol x0 used as an immediate value&...
0
votes
0
answers
480
views
ARM assembly: What is the difference between DCD and .word?
Here is an explanation of DCD:
https://developer.arm.com/documentation/dui0473/m/directives-reference/dcd-and-dcdu
To me the usage seems very similar with .word. What is the difference between these ...
0
votes
1
answer
65
views
GNU i386-Assembler: arch/i386/boot.S: Error: junk `GDT39' after expression
I try to follow the tutorial from wiki.osdev.org about the setup of a GDT. I tried to convert the example code from NASM to GAS Syntax but the tool intel2gas couldn't convert some lines which I then ...
0
votes
1
answer
141
views
assembly weak symbol not working as (I) expected
I am cross compiling with riscv-corev32-elf-gcc.
In a first file 'generic.S'
I have the following code:
.section .text.handlers
.weak u_sw_irq_handler
.weak __no_irq_handler
.section .vectors, "...
1
vote
1
answer
66
views
How do I create a macro with conditional assembly
How do I create a macro where you can leave out a parameter? When left out it should remove a piece of code.
1
vote
0
answers
256
views
Absolute indirect far jump syntax in GAS x86_64 asm
I'm reading https://www.felixcloutier.com/x86/jmp and I'm a little confused about the usage of the last row, Jump far, absolute indirect, address given in m16:64. and how it compares to the rest.
I ...
1
vote
0
answers
34
views
Symbol defined after statment its used on, so it's assumed to be an external symbol
I am converting some code from Intel Syntax to AT&T syntax.
I have the folowing code, that loads a GDT, and does a far jump using the loaded GDT, defined in the .rodata section.
.global start
....
4
votes
0
answers
103
views
GNU assembler override size of immediate operand
I am trying to match a specific sequence of bytes with GNU assembler. Objdump disassembles these bytes as:
81 e2 66 00 00 00 and edx,0x66
However, GAS "helpfully" assembles this ...
0
votes
0
answers
97
views
"undefined" label references in AS assembler
I have been trying to use a collection of various resources recently (mostly https://wiki.osdev.org and https://www.osdever.net). And currently I am trying to initialize a GDT in my assembly file boot....