Questions tagged [x86-64]
x86-64 is a 64 bit extension to the Intel x86 architecture
6,506
questions
1
vote
0
answers
21
views
Interleaved LEA and CALLQ instructions [duplicate]
I've disassembled a function and I'm certain that I know what the function is doing - it's two nested loops that generates multiplication tables. However, there's a section of the assembly that doesn'...
0
votes
0
answers
38
views
printf returning a segmentation fault in ASM
I'm trying to learn how to change the heap section so I wrote the following code:
.section .data
str1: .string "ESTE EH UM TESTE\n"
str2: .string "%d\n"
str3: ...
0
votes
1
answer
40
views
Why do I get segmentation fault for this minimal assembly?
I am a beginner at amd64 x86_64 assembly.
I am trying to allocate a static region of memory and then use it.
I try to move a pointer to the memory into registers with
movq .end_data_stack(%rip),%rdx ...
2
votes
0
answers
67
views
ASM: Optimization of Pass-by-value vs Pass-by-reference in leading-edge compilers?
(This question is about compiler optimization assembly, not about the use of pointers in code.)
I'm trying to determine if I can take advantage of optimizations built into Clang or GCC in regards to ...
2
votes
1
answer
36
views
BadWindow (invalid Window parameter) when trying to close a Display in X11
I am writing in x86-64 NASM assembly and I wrote a function to close a window using X11 on Ubuntu via WSL
I keep getting this error:
X Error of failed request: BadWindow (invalid Window parameter)
...
1
vote
1
answer
65
views
How does popa and pusha actually works?
I am attempting to write a simple OS from scrath, but I have stumbled into a problem.
I wrote a simple procedure that runs through a string and prints it on the screen.
print_string:
pusha
cmp ...
0
votes
0
answers
24
views
Why do I get memory access error while programming with NASM-Assembler? [duplicate]
Introduction:
Hello everyone, I want to let you know that this is my first question on this website.
I am pretty new to programming in NASM-Assembly and programming in Assembly in general, so I hope ...
0
votes
0
answers
34
views
Difference between `CMPXCHG8B m64` and `CMPXCHG r/m64, r64`?
According to https://www.agner.org/optimize/instruction_tables.pdf
They are different in zen4
LOCK CMPXCHG, Ops=5, Latency=9
LOCK CMPXCHG8B, Ops=15, Latency=10
instruction reference: // can't see ...
0
votes
0
answers
26
views
Does the AMD Ryzen 9 7900x CPU support AVX-512 VBMI? [closed]
I want to compute an arbitrary permutation of 64 bytes. This can be done efficiently with the VPERMB instruction on an x86-64 CPU, if the CPU supports AVX-512 VBMI.
I know that the AMD Ryzen 9 7900x (...
3
votes
1
answer
32
views
don't understand the ia32e 4-level paging
I have recently studied the IA32e paging, and though I know how that works, when I came across a real example, I can't understand what the value in each entry presents.
I have read the manual, which ...
0
votes
0
answers
61
views
SSE instruction to interleave top 16-bits of packed 32-bit blocks of two XMM registers?
I can't seem to find any SSE instruction that does exactly this
r[15:0] = a[31:16]
r[31:16] = a[63:48]
r[47:32] = a[95:80]
r[63:48] = a[127:112]
r[79:64] = b[31:16]
r[95:80] = b[...
0
votes
0
answers
21
views
Segfaukt in assembly [duplicate]
I coded the following function in assembly:
.global my_pow
.type my_pow, @function
.data
format:
.asciz "%d\n"
.text
my_pow:
// Variable
pushq %rbp # ...
1
vote
1
answer
39
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 # ...
1
vote
0
answers
38
views
Make out-of-order CPU run instructions in-order
Consider the loop:
for (int i = 0; i < n; i++) {
sum += a[i];
}
An out-of-order CPU can execute many instructions in advance, it can e.g. have 20 parallel pending loads of a[i] from 20 ...
0
votes
1
answer
42
views
Prevent a CPU core from using the LL cache
I have a following problem: I have a low-latency application running on core 0, and a regular application running on core 1. I want to make sure that core 0 app gets as much cache as possible, ...
3
votes
0
answers
52
views
How to get Rust compiler to emit BZHI instruction without resorting to platform-specific code?
The Rust compiler & LLVM are sometimes so smart. I used x = x & (x - 1) to clear the lowest significant set bit. It recognized this expression and translated it to the blsr intrinsic and gave ...
0
votes
2
answers
120
views
SIMD code for transforming one-letter amino acid code into integer between 0 and 22
Trying to code the following transformation in SIMD C++, any ideas ?
Code is from https://github.com/soedinglab/hh-suite/blob/master/src/hhutil-inl.h#L45-L83
const int ANY=20; //number ...
0
votes
0
answers
30
views
Confuse with parity bit finding in Assembly x86-64 question
I have been trying to figure out the whole shifting process and it just doesn't make sense to me. How does it count the number of bits there were set and the right shift just throws away whatever ...
1
vote
1
answer
90
views
Is this a missed optimization in GCC, loading an 16-bit integer value from .rodata instead of an immediate store?
Looking for this code:
#include <stdint.h>
extern struct __attribute__((packed))
{
uint8_t size;
uint8_t pad;
uint16_t sec_num;
uint16_t offset;
uint16_t segment;
...
2
votes
1
answer
67
views
why using 8 byte register to carry 8 byte type but not using 4 byte register for 4 byte type [duplicate]
This is the code snippet that i am looking
#include <cstdint>
int main() {
unsigned int i = 0x11111111;
unsigned int j = 0xFFFFFFFF;
uint64_t k = 0xFFFFFFFF11111111;
}
...
0
votes
1
answer
73
views
C++/Assembly pushing arguments onto the stack for function call
i have a special case where i need to push arguments onto the stack one at a time and then call a function which takes a callable as an argument and pass those arguments that were pushed to the stack ...
0
votes
0
answers
42
views
How works Stack and Bias and how avoid error "Segmentation Fault" GNU Assembler?
In-first I wanna Apoligize about Non-English comments in code-examples
I do not quite understand how the stack works and how the stack alignment limit is calculated and HOW to align it.
For example, ...
0
votes
0
answers
24
views
SDE ERROR: cet_linux_mode != CET_LINUX_MODE_UNKNOWN
It seems that Intel SDE, when running with CET turned on,
$ cat hello_world.c
#include <stdio.h>
int main() {
puts("miaou");
}
$ gcc -static -Wall -fcf-protection=branch hello_world....
1
vote
0
answers
42
views
ARM cross compile for x86 error: relocation truncated to fit: R_x86_64_32 against '.rodata", how do I fix this?
I'm trying to cross compile a custom OS for x86 hardware on an ARM based system (Debian VM on M1 Mac). To compile I'm using "x86_64-linux-gnu-gcc" and for a linker I'm using "...
0
votes
1
answer
45
views
What is the target of the je instruction in assembly? [duplicate]
I have this question in a practice quesiton from my school and it completely boggles my mind.
In the following excerpts from a disassembled binary, some of the information has been replaced by Xs. ...
1
vote
1
answer
35
views
How to use ptrace in 64 bit process to modify registers in a 32-bit process and make it do a system-call?
I'm working on a program that needs to make a 32 bit process invoke a syscall.
I wish to keep my program architecture independent, but the target will always be 32 bit.
To set the registers I'm using ...
2
votes
2
answers
72
views
Input Operand `"m"(var)` and Output Operand `"=m"(var)` in GNU C inline asm? Used with no instructions as barriers?
I wonder what input operand "m"(var) and output operand "=m"(var) in asm do:
asm volatile("" : "=m"(blk) : :);
asm volatile("" : : "m"(...
0
votes
0
answers
41
views
getting an opcode? To perform jmp [duplicate]
I specify:
E9 00 89 9F E8 90
But actually the transition to another address, I found a formula, but I don't understand how it works.
"FROM - TO - 5 bytes.
Let's say the OT is 0057A3FF.
And BC is ...
0
votes
0
answers
19
views
Nasm X86 64 Push two variables to the stack and sum them [duplicate]
I'm working on writing a language that will compile to assembly and am in the process of handling variables. I'm setting the variable x to 1 and y to 2 and then trying to sum them with the resulting ...
1
vote
2
answers
89
views
Can the LEA instruction mimic every MOV instruction?
Recently came across the M/o/Vfuscator
A complete single-instruction C compiler which compiles programs into
"mov" instructions, and only "mov" instructions. Arithmetic,
...
5
votes
1
answer
109
views
C++17 std::byte produces less optimized code with the standard algorithms in GCC
I really like std::byte as a distinct type that implements the concept of byte as specified in the C++ language definition. What I don't like is the fact that modern C++ compilers will produce less ...
0
votes
0
answers
106
views
How to remove NULL bytes from C generated shellcode?
For fun, I'm trying to rewrite this NASM Windows/x64 - Dynamic Null-Free WinExec PopCalc Shellcode (205 Bytes) using Windows MSVC x86-64 as shown here:
// Windows x86-64 - Dynamic WinExec Calc.exe ...
2
votes
0
answers
32
views
What does `a+y(%reg)` do in AT&T syntax
I am translating musl's x86_64 sigsetjmp into intel syntax but cannot figure out what the following two lines of assembly are doing:
mov %rbx,72+8(%rdi)
...
mov 72+8(%rbx),%rbx
My guess is it is ...
5
votes
1
answer
105
views
GCC won't use its own optimization trick without -fwrapv
Consider this C++ code:
#include <cstdint>
// returns a if less than b or if b is INT32_MIN
int32_t special_min(int32_t a, int32_t b)
{
return a < b || b == INT32_MIN ? a : b;
}
GCC ...
3
votes
1
answer
81
views
How is a critical path formed when there is a data dependency between a loop iterations while a CPU executing instructions?
In the Computer Systems From A Programmer's Perspective book there is the following assembly code for a loop:
L3:
1. movq %rax, (%rsi)
2. movq (%rdi), %rax
3. addq $1, %rax
4. subq $1, %rdx
5. ...
0
votes
1
answer
41
views
Apache module error on M1 chip - file, but is an incompatible architecture have 'arm64', need > 'x86_64'
I am on the Apple M1 arm64 chip arm64.
uname -m
arm64
I am trying to install the PHP 8.2 module for Apache, e.g.
LoadModule php8_module /opt/homebrew/Cellar/php/8.2.1/lib/httpd/modules/libphp.so
......
0
votes
0
answers
73
views
Why does my OS not boot when I try to access 0xE0000000?
To implement a linear framebuffer, I wanted to use the pre-registered VBE LFB, at address 0xE0000000. Note that I am using Bochs 2.7, Assembly using NASM, and C using GCC.
I am using a regular char ...
1
vote
0
answers
35
views
printf in Windows x86-64 shellcode, strings on stack, and alignment
From x64 shellcode on Windows 10, I want to call printf("String: %s\n", "Hello World") with the string "Hello World" defined on the stack. I ran into problems that I’ve ...
1
vote
0
answers
50
views
Windows thread local storage bug
In Windows, a segment error occurs when an executable file accesses a thread local variable in the dynamic library in extern mode.This problem occurs when clang is used, but not when gcc is used.
// ...
2
votes
1
answer
55
views
How do you get around the ABA problem when using mwaitx?
AMD's mwaitx instruction allows you to wait for an address to change, and it has a limited duration. There's no way to tell if it woke up because the value changed or because of an interrupt.
You can ...
0
votes
1
answer
45
views
Contradictory behavior of JNE x86 assembly instruction [duplicate]
Assume the following example:
test %eax, %eax
jne Label
I know that the JNE assembly instruction does the same thing as the JNZ instruction. It takes the jump if the Zero Flag ZF is equal to 0. ...
0
votes
1
answer
45
views
Segmentation fault NASM Assembly 64-Bit [duplicate]
I am currently studying Computer Architecture and one core topic is assembler. For some reason the prof's example code doesn't work on my computer. I am using a 64-Bit Linux-Subsystem for Windows to ...
1
vote
0
answers
49
views
Different behavior of movq and leaq x86 assembly instructions [duplicate]
I am new to x86 assembly and I have a question regarding the movq and leaq instruction. In particular, I would like to know the difference between the following:
1. movq (%rax), %rcx
2. movq %rax, %...
-3
votes
0
answers
30
views
What is hex encoding for mov rax, 0xFFFF0820CADBA78D [duplicate]
I'm working on a little endian Intel 64 bit platform. I'm playing around with assembly, converting it to hex encode. What would be the opcode (hex encoding) for the following assembly ?
mov rax, ...
0
votes
0
answers
40
views
Calling VROUNDSS using Rust intrinsics
From what I see here:
I can call "roundss" (SSE 4.2) by using the Rust intrinsic: core::arch::x86_64::_mm_round_ss.
but I'm unable to find an equivalent for "vroundss" (AVX?). Is ...
0
votes
0
answers
36
views
Unclear Correspondence Between C and Assembly [duplicate]
I am reading about x64 Assembly through this online textbook. It takes the following C function:
int adder2(int a) {
return a + 2;
}
And shows how it is compiled into x64 Assembly:
push %rbp
mov %...
1
vote
0
answers
28
views
Disassembling Code inside of a C++ program
objdump -D file.o will output something like
2b: 47 rex.RXB
2c: 43 rex.XB
2d: 43 3a 20 rex.XB cmp (%r8),%spl
In my program I have ...
2
votes
0
answers
57
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, %...
-1
votes
1
answer
42
views
Conditions under which EFLAGS flags are set in x86/x64 [duplicate]
I would like to know what are the conditions under which the basic EFLAGS flags (CF, ZF, OF, SF...) are set. I have looked into the Intel x86 instruction manual, and this website that is well done, ...
1
vote
1
answer
108
views
why int& as function parameter uses QWORD(8 byte) memory but int parameter uses DWORD [duplicate]
In the code below,
int firstFunction(int& refParam)
{
std::cout << "Type of refParam is: " << typeid(refParam).name() << '\n';
return refParam;
}
int ...