x86-64

Injecting code into executable at runtime

。_饼干妹妹 提交于 2019-12-18 11:27:50
问题 I'm working on application (written in C++), which generate some machine code at runtime (Linux, x86-64 now, but I plan to migrate on ARM). Next it store generated code in memory and execute it by jumping to memory location. For a long time I had a problem with allocating executable memory, but I finally solved it using: uint8_t *memory = mmap (NULL, length, PROT_READ | PROT_WRITE | PROT_EXEC, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); So far it works, but I'm not sure if it's elegant way to do

How to get c code to execute hex bytecode?

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-18 11:19:13
问题 I want a simple C method to be able to run hex bytecode on a Linux 64 bit machine. Here's the C program that I have: char code[] = "\x48\x31\xc0"; #include <stdio.h> int main(int argc, char **argv) { int (*func) (); func = (int (*)()) code; (int)(*func)(); printf("%s\n","DONE"); } The code that I am trying to run ( "\x48\x31\xc0" ) I obtained by writting this simple assembly program (it's not supposed to really do anything) .text .globl _start _start: xorq %rax, %rax and then compiling and

How can objdump emit intel syntax

放肆的年华 提交于 2019-12-18 10:32:24
问题 How can I tell objdump to emit assembly in Intel Syntax rather than the default AT&T syntax? 回答1: What you're looking for is -M intel . Use it as follows. objdump -M intel -d program_name 回答2: If you want Intel mnemonic codes as well (instead of AT&T mnemonic codes), you can use: objdump -M intel intel-mnemonic -D <program's-object-file> 来源: https://stackoverflow.com/questions/10362630/how-can-objdump-emit-intel-syntax

How can objdump emit intel syntax

一曲冷凌霜 提交于 2019-12-18 10:32:03
问题 How can I tell objdump to emit assembly in Intel Syntax rather than the default AT&T syntax? 回答1: What you're looking for is -M intel . Use it as follows. objdump -M intel -d program_name 回答2: If you want Intel mnemonic codes as well (instead of AT&T mnemonic codes), you can use: objdump -M intel intel-mnemonic -D <program's-object-file> 来源: https://stackoverflow.com/questions/10362630/how-can-objdump-emit-intel-syntax

How to use bits in a byte to set dwords in ymm register without AVX2? (Inverse of vmovmskps)

不羁的心 提交于 2019-12-18 09:12:57
问题 What I'm trying to achieve is based on each bit in a byte, set to all ones in each dword in a ymm register (or memory location) e.g. al = 0110 0001 ymm0 = 0x00000000 FFFFFFFF FFFFFFFF 00000000 00000000 00000000 00000000 FFFFFFFF i.e. an inverse of vmovmskps eax, ymm0 / _mm256_movemask_ps , turning a bitmap into a vector mask. I'm thinking there are a handful of sse/avx instructions that can do this relatively simply but I haven't been able to work it out. Preferably sandy bridge compatible so

How to get this simple assembly to run?

我的未来我决定 提交于 2019-12-18 09:04:12
问题 This is my first ever attempt at programming with assembly. I'm using a 64 bit Mac OS. I'm also using NASM. I've done a lot of looking around for a solution, but I can't find anything that works for my machine. Can anyone help me solve this problem? Here is the code and error, thanks! hello.asm global start section .text start: mov rax, 1 mov rdi, 1 mov rsi, message mov rdx, 13 syscall mov eax, 60 xor rdi, rdi syscall message: db "Hello, World", 10 my attempt at executing: nasm -f macho64

How many clock cycles does cost AVX/SSE exponentiation on modern x86_64 CPU?

不想你离开。 提交于 2019-12-18 08:26:48
问题 How many clock cycles does cost AVX/SSE exponentiation on modern x86_64 CPU? I am about: pow(x, y) = exp(y*log(x)) I.e. do both exp() and log() AVX x86_64 instructions require certain known number of cycles? exp(): _mm256_exp_ps() log(): _mm256_log_ps() Or the number of cycles may vary depending on the exponential degree, is there the maximum number of cycles can cost exponentiation? 回答1: The x86 SIMD instruction set (i.e. not x87), at least up to AVX2, does not include SIMD exp , log , or

clang (LLVM) inline assembly - multiple constraints with useless spills / reloads

大兔子大兔子 提交于 2019-12-18 07:35:17
问题 clang / gcc : Some inline assembly operands can be satisfied with multiple constraints, e.g., "rm" , when an operand can be satisfied with a register or memory location. As an example, the 64 x 64 = 128 bit multiply: __asm__ ("mulq %q3" : "=a" (rl), "=d" (rh) : "%0" (x), "rm" (y) : "cc") The generated code appears to choose a memory constraint for argument 3 , which would be fine if we were register starved, to avoid a spill. Obviously there's less register pressure on x86-64 than on IA32.

Why MOV AH,1 is not supported in 64 bit mode of intel microprocessor?

◇◆丶佛笑我妖孽 提交于 2019-12-18 07:08:31
问题 In the book "THE INTEL MICROPROCESSORS" of Barry B. Brey, it is written that MOV AH, 1 is not allowed in 64 bit mode, but allowed in 32 bit or 16 bit mode. If MOV AL, 1 can be allowed in 64 bit mode, what is the problem with MOV AH, 1 ? 回答1: There is no problem with mov ah,1 . It runs just fine in X64 mode. The opcode for it is b4 01 . The only time when mov ah is not allowed is when the mov has a REX prefix. from: http://www.felixcloutier.com/x86/MOV.html ***In 64-bit mode, r/m8 can not be

Why can't I move directly a byte to a 64 bit register?

僤鯓⒐⒋嵵緔 提交于 2019-12-18 06:57:00
问题 Why can't I directly move a byte from memory to a 64-bit register in Intel x86-64 assembly? For instance, this code: extern printf global main segment .text main: enter 2, 0 mov byte [rbp - 1], 'A' mov byte [rbp - 2], 'B' mov r12, [rbp - 1] mov r13, [rbp - 2] xor rax, rax mov rdi, Format mov rsi, r12 mov rdx, r13 call printf leave ret segment .data Format: db "%d %d", 10, 0 prints: 65 16706 I need to change the move byte to registers r12 and r13 to this in order to make the code work properly