1,090 questions
Advice
0
votes
5
replies
96
views
Why does `tcc` compile local variables onto the stack?
I have the following C code (an MWE):
#include<time.h>
void fun() {
asm("arg1:");
struct timespec const a = { .tv_sec = 10, .tv_nsec = 0 };
asm("call_nanosleep:");
...
-1
votes
0
answers
20
views
Wrong string address when converting nasm bootloader to gas (error : relocation truncated to fit) [duplicate]
I am trying to imitate a simple bootloader written in nasm I want to try a gas version
Here is the code with nasm:
[org 0x7c00]
mov ah, 0x0e
mov al, [var]
int 0x10
jmp $
var:
db "Hello",...
2
votes
1
answer
75
views
Assembly code fail when I add a jump before rept
I have the following assembled but when ever I uncomment the jmp or je it fail with 11: Error: bad or irreducible absolute expression
_start:
mov $0x0e, %ah
mov $'a', %al
_loop:
int $...
1
vote
0
answers
106
views
How to compare a register and the effective address of a variable in GAS with intel_syntax
I am following an assembly tutorial where they use NASM. They manage to compare a register to a variable's address with cmp rcx, digitSpace, but how can I do the same with GAS?
As you know this ...
3
votes
1
answer
87
views
Can I somehow tell GAS to change direction of operands?
I have the binary image of a bootloader which was written with some ancient assembler.
I want to port the assembly code to GNU assembler (GAS). We speak about the X86/16-bit
(real mode) world.
This ...
-2
votes
1
answer
172
views
Local variable in .c file overwrites memory address previously aquired in ARM GNU assembly file [duplicate]
I have implemented a basic FIFO data structure with its related functions/subroutines in a FIFO.s file and want to use them in the main function inside a main.c file;
// FIFO.s
.syntax unified
.cpu ...
2
votes
2
answers
131
views
Trying to build golang package ending up with GCC compilation segfault on as --gdwarf-5
After some package upgrade on my Ubuntu 24.04 I stumbled upon inability to build/install/work with almost any of golang packages.
So, I'm trying to install staticcheck and get the following error:
$ ...
1
vote
0
answers
51
views
Is it possible to reuse label names in ARM GNU Assembly? [duplicate]
I want to use the same label name in different parts of my Assembly code instead of using a new, never-before-used label name; Is such a thing possible?
For example:
.
.
.
Factorial: // A subroutine ...
4
votes
1
answer
104
views
Is it possible to undo the effect of the .req directive in ARM GNU Assembly?
I want to rename (more like add an alias to) one or more registers for a specific part of my Assembly code using the .req directive and later on undo the renaming of said register(s) so that those ...
1
vote
0
answers
46
views
gnu assembler x64, how to push big unsigned value [duplicate]
I have
pushl $2147487744
this is 0x80001000 gnu as gives
mycc_cpp.s:27: Error: invalid instruction suffix for `push'
I have tried
pushq
pushing hex
no luck
1
vote
1
answer
65
views
GAS creates a PLT relocation entry for call to an extern symbol?
I assembled the following file with GAS, the GNU assembler:
.extern foo
.global bar
.section .text
bar:
call foo
ret
In the object file it produced there is a relocation entry of type ...
1
vote
0
answers
85
views
Debugging GDT in assembly/D lang
I've been dabbling with writing a small OS in D lang but I'm crashing on boot. I've been debugging my main file and think that the issue is with gdt_flush which is called in gdt.d and defined in gdt.s....
3
votes
0
answers
63
views
Can the GNU Assembler perform all macro expansions in a file and then output compilable code without macros?
Is there a way to have the GNU assembly process a source file that contains macros, expand them, and then output the expanded equivalent code in a form that could be assembled by as? Basically, I'm ...
4
votes
1
answer
100
views
GNU as recursive/loop macro expected output
In this assembly file below, the macro jump_table should automagically create ... a jump table to consecutively numbered labels like jump_0, jump_1, ... jump_<n>.
It seems there is no loop ...
1
vote
1
answer
105
views
What does this mean: .size _start, . - _start in assembler?
What do the symbols mean in this assembly language statement:
.size _start, . - _start
I've searched and found quite a few identical examples and several variations but none explain what the ...
3
votes
0
answers
83
views
Why is this .section directive terminated with ._start?
I'm trying to understand this assembly from a bare-metal project I've cloned from GitHub.
.section .text._start
_start:
// Infinitely wait for events (aka "park the core").
....
3
votes
0
answers
742
views
How can I correctly cast the variable type in GDB when using set command to change its value?
In a simple/trivial GNU Assembly (GAS/as) program (see interaction and source, after explanation), opened for debug with GDB.
Having trouble to set the value of a variable through its symbol (name).
(...
0
votes
0
answers
43
views
confused about how the dynamic memory allocation works in assembly (brk) [duplicate]
According to my understanding, the brk syscall allows you to set the memory available to the process, and I assume that the process cannot access any memory after the break point.
Well, the code below ...
3
votes
1
answer
80
views
Should the box at the bottom be %rax instead of %rbx in Fig 6-1 of Jonathan Barlett's book?
I've been reading a book called "Learn to Program with Assembly, Jonathan Barlett". In which , I didn't understand the Figure 6-1.
Context: The author is explaining register-indirect mode, ...
0
votes
0
answers
33
views
Can an immediate value be moved into to a memory location without loading it into a register first? [duplicate]
I've been learning x64 assembly lately from a book (Learn to program in Assembly, Jonathan Bartlett). The book claims, "In order to manipulate the data, we have to move it into registers first.&...
3
votes
1
answer
46
views
GNU Assembly Printing Formatted Error Messages - macro substitution into quoted string for .print
I have a setup like this:
.set ERRORS, 1
.macro ERROR_SUMMARY, COUNT
.print "\e[1;92mZ#\e[1;31m Compilation Failed with \\COUNT Error(s)\e[0m!"
.endm
ERROR_SUMMARY ERRORS
This should ...
3
votes
0
answers
82
views
replaced C function with assembly, now segfaulting after main exits [duplicate]
Working on an assignment, the premise is essentially implementing provided C functions in assembly and preserving behavior.
The program reads "records" from stdin (char* last_name, char* ...
0
votes
1
answer
64
views
How to use shifter operands in GNU arm assembly syntax?
I know in arm assembly we can use shifter operands like bellow:
mov r0, r1, lsl #2
I use gcc to compile, therefore I have to adapt syntax.
I already tried this:
mov w0, w1, lsl 2
It didn't work: ...
1
vote
0
answers
29
views
How to get CLI arguments in Assembly language without libc? [duplicate]
I wanted to print out first command line argument in x86_64 Assembly on Linux, but I have had hard time getting value of it. For clarification: commands I use to compile this are as -o args.o args.s -...
2
votes
0
answers
119
views
How to get label address on GNU Assembler
This must be something really stupid; I'm trying to get the address for a label and store it into a .word on GNU Assembler, but for some weird reason, it's not working as I expect it to work.
Take the ...
1
vote
0
answers
98
views
Unexpected behavior of the mov instruction in GAS when using Intel syntax [duplicate]
Consider this code:
.intel_syntax noprefix
.data
l: .long 0
.text
.global main
main:
mov DWORD PTR l, 0x11111111
mov eax, ...
1
vote
0
answers
55
views
GAS assembler: What are the uses of .type? (A set of questions)
When can I use this directive?
Are there any other types besides function, tls_objrct, object, and common?
Are there examples of using each type from the .type?
Can I create my own type and mark it ...
0
votes
0
answers
90
views
Segmentation fault (core dumped) in GNU Assembly x86
I am writing power function in GNU Assembly x86 on Linux principal-neanderthal 6.8.0-41-generic x86_x64. When i launch i get "segmetantion fault (core dumped)" error.
.code32
.section .data
...
1
vote
1
answer
96
views
How to specify the linker file to use with AS?
I am trying to build an application made of a single assembly file. I wrote a linker file targeting my chip which consists of a RISC-V CPU, a ROM and a RAM.
I don't know how to tell the AS program to ...
0
votes
2
answers
505
views
RISC V : I don't understand what the GNU assembler does with labels in the .data segment
I am making my own risc V core as a personal project using the RV32I ISA, I am using a Harvard memory architecture meaning I have a program memory that starts at address 0x0 and a separate data memory ...
1
vote
0
answers
116
views
Assembling with gcc gives error operand type mismatch for `cmp' for some integers, not others
This is a weird one. I'm using gcc to assemble a program and I want to know if the value in register rsi fits in 32 bits, so I use this instruction:
cmpq $0xffffffff, %rsi
I get back an error that ...
2
votes
0
answers
129
views
Ways to perform bitwise operations with symbols inside Assembly constants?
I am working on learning to write ARM firmware and am trying to create a Vector Table. I am using the GNU toolchain.
I have assembly code like the following:
MY_VECTOR_TABLE:
.long 0 ...
0
votes
1
answer
64
views
Why LI becomes LBU opcode after MIPS assembler
I'm trying to assemble code for MIPS R2000 (MIPS I ISA).
I'm using LI pseudo instruction to initiate a register. After running the assembler on the following code:
li $v1, 1
The binary .text ends up ...
3
votes
2
answers
692
views
AVR instructions LDS and STS 16 bit versions with GNU assembler
the AVR 8bit core instruction set includes the more efficient 16bit versions of the "load data from memory" (LDS) and "store data to memory" (STS) instructions, as opposed to the ...
2
votes
1
answer
203
views
GNU as: when to use '$'
After a long time I have to use the GNU assembler again. Ever since I had trouble with the '$'.
The manual just says:
3.6.2.1 Integers
A decimal integer starts with a non-zero digit followed by zero ...
1
vote
1
answer
64
views
If-Else in assembly doesn't seem to work or I'm doing smth wrong
.section .note.GNU-stack,"",@progbits
.section .data
cf_msg:
.string "CF = %d\n"
of_msg:
.string "OF = %d\n"
sf_msg:
.string "SF = %d\n"
less_msg:
.string &...
1
vote
1
answer
69
views
How to change a single bit of an address at assemble time?
Arch is SuperH. I have some variables specified like this:
buffer_address: .long buffer
buffer: .zero 1024
However, for certain buffer reads, I need to read as cache-through. The way to do that on ...
1
vote
0
answers
80
views
GAS with AT&T syntax - creating a label by concatenating a variable of a macro
I have an assembly code that generates ISR (interrupt service routine) stubs. I want to automate this process, and for each of the interrupts (there are 256) generate it's own unique stub. This is ...
3
votes
1
answer
220
views
Data Integrity Issue with Custom .rawdata Section in Linker Script
I'm working on an embedded project using an ARM Cortex-M4 processor (specifically, an STM32F4 microcontroller) and I've encountered a peculiar issue related to memory sections defined in my linker ...
2
votes
1
answer
116
views
GNU Assembler identifier concatenation inside macro
I want to append a string to a macro argument in gcc assembler. Here is what I have currently:
The following macro to embed a file in my code which works just fine:
.macro add_resource resource_name, ...
0
votes
1
answer
244
views
Is there a way to determine buffer's length?
Lets say I have a buffer I declared like this:
.section .bss
.lcomm buffer, 33
I pushed it to the stack and passed it as an argument to another function that expects a 44-byte length buffer.
Is there ...
2
votes
0
answers
60
views
Fastest "shift and duplicate" operation
Arch is SuperH, specifically SH-2. I don't know the name of this operation, but I have been calling it "shift and duplicate". Effectively what I am looking for is:
0x0000AB12 -> ...
1
vote
1
answer
149
views
How to determine which x86 memory operand width and type is used from an asm listing?
There are several versions of the same instruction: IDIV M32, IDIV R32, IDIV M64, IDIV R64 (https://www.felixcloutier.com/x86/idiv)
How to understand which one is used? Let's say
vdiv(std::vector<...
0
votes
1
answer
98
views
cannot find entry symbol _start when trying to link c main with assembly function
Can read assembly but trying to learn to write small functions in it, but I can't seem to link a main written in C that calls an extern function written with gas. The target is linux x64.
Here is main....
1
vote
0
answers
48
views
x86_64 - Using GDB on a code assembled with GAS causing strage error
I have this code written in Assembly x86_64:
.section .data
.equ SYS_CALL, $0x80
.set filename, "a.txt"
.section .text
.section .bss
.lcomm buffer, 20
.globl _start
_start:
mov $1,%rbx ...
0
votes
1
answer
29
views
GNU AS ASM to bytecode dump
Some time ago I created this function to dump a bytecode given an ASM instruction:
show_bytecode(){ echo "$@" | as -o temp.o && ld --oformat binary -o temp.bin temp.o 2>/dev/null &...
2
votes
1
answer
138
views
How can I insert machine code into assembly language?
I'm currently working on a riscv prj with custom opcode. I wanna write some asm test cases (like riscv isa test) . A piece of work has been shown below
RVTEST_CODE_BEGIN
#---------------------------...
1
vote
0
answers
59
views
x86 Assembly: handling exponent 1 in power calculation
I have this code I wrote in x86. The code does a power of the first number I'm pushing to the queue by the second one.
Now all cases work as expected except one case that's when the second number ...
1
vote
0
answers
34
views
Assembly x86 - status code not shown as defined [duplicate]
I have this code I've written in Assembly x86:
.section .data
list: .long 1, 2, 3, 4, 5, 0
.section .text
.globl _start
_start:
movl $0,%eax # eax will save our current location
movl list(,%eax,...
1
vote
1
answer
425
views
"Cannot find bounds of current function" error in GDB while debugging bootloader code
I'm currently learning bootloader development and debugging with GDB to observe memory changes when the A20 line is disabled in real mode. Since QEMU automatically enables the A20 line, I'm attempting ...