x86-64

Move an int64_t to the high quadwords of an AVX2 __m256i vector

时间秒杀一切 提交于 2019-12-02 06:05:28
问题 This question is similar to [1]. However I didn't quite understand how it addressed inserting to high quadwords of a ymm using a GPR. Additionally I want the operation not use any intermediate memory accesses. Can it be done with AVX2 or below (I don't have AVX512)? [1] How to move double in %rax into particular qword position on %ymm or %zmm? (Kaby Lake or later) 回答1: My answer on the linked question didn't show a way to do that because it can't be done very efficiently without AVX512F for a

There is an assembly code written for Windows API, how to compile it on Linux and run with Wine

坚强是说给别人听的谎言 提交于 2019-12-02 05:47:59
There is an example code in this introduction , like below: ; Sample x64 Assembly Program ; Chris Lomont 2009 www.lomont.org extrn ExitProcess: PROC ; external functions in system libraries extrn MessageBoxA: PROC .data caption db '64-bit hello!', 0 message db 'Hello World!', 0 .code Start PROC sub rsp,28h ; shadow space, aligns stack mov rcx, 0 ; hWnd = HWND_DESKTOP lea rdx, message ; LPCSTR lpText lea r8, caption ; LPCSTR lpCaption mov r9d, 0 ; uType = MB_OK call MessageBoxA ; call MessageBox API function mov ecx, eax ; uExitCode = MessageBox(...) call ExitProcess Start ENDP End The above

printf float in nasm assembly 64-bit

牧云@^-^@ 提交于 2019-12-02 05:19:13
I want to print a float value with printf global main extern printf section .data string: db `%f\n`, 0 section .bss rs: resq 1 [...] movq xmm0, [rs] mov rdi, string mov rax, 0 call printf rs contains the floating value 1.6 (gdb) x/fg &rs 0x600ad8 <rs>: 1.6000000000000001 but the program prints [username@localhost folder]$ ./programname 0.000000 who can I get the program to print 1.6? what am I doing wrong? szx I suspect the problem has something to do with your code setting rax to 0 whereas it must be 1 because you pass a floating point argument (see here for details). Basically rax should

NASM 2 lines of db (initialized data) seemingly not working

北城余情 提交于 2019-12-02 04:56:50
I have the following x86-64 code, which I can run on OSX Yosemite: global _main extern _exit extern _puts DEFAULT REL section .data putsmsg: db 'Puts message...',0 another: db 0 section .text _main: push rbp mov rbp, rsp ; print a string using PUTS lea rdi, [putsmsg] call _puts ; call EXIT(0) c function mov rdi, 0 call _exit I compile, link, and run as follows (where the source is a.asm): nasm -f macho64 a.asm ; gcc a.o -o a.bin ;./a.bin It does not print the message 'Puts message...', whereas it does print the message if I simply comment out the line containing the label 'another'. What is

Learning assembly - echo program name

那年仲夏 提交于 2019-12-02 04:47:38
问题 I am trying to write a simple program in assembly that will write out the name of the program. Using gdb to debug, I've determined that the call to sys_write is returning -14 (EFAULT). I've also been able to verify that my strlen function is working correctly. It seems like there is some sort of memory access issue, but I don't understand what could be wrong given that strlen is accessing the same memory and working fine. What is going wrong? Thanks! The full code: section .text global _start

Declaring and indexing an integer array of qwords in assembly

久未见 提交于 2019-12-02 04:38:30
问题 I have a question regarding how to initialize an array in assembly. I tried: .bss #the array unsigned: .skip 10000 .data #these are the values that I want to put in the array par4: .quad 500 par5: .quad 10 par6: .quad 15 That's how I declared my string and the variables that I want to put it inside. This is how I tried to put them into the array: movq $0 , %r8 movq par4 , %rax movq %rax , unsigned(%r8) incq %r8 movq par5 , %rax movq %rax , unsigned(%r8) incq %r8 movq par6 , %rax movq %rax ,

Why doesn't this attempt at using sys_write do anything?

心已入冬 提交于 2019-12-02 04:26:17
Here it is: .SECTION .data msg: .string "AAAA" .SECTION .text .globl _start _start: mov $1, %rax mov $1, %rdi mov msg, %rsi mov $4, %rdx syscall Not only does this code not segfault, it also outputs nothing. According to what I've read, a program should call sys_exit, or it would segfault, but this does not happen. mov msg, %rsi This instruction will interpret the data at "msg" as 64-bit value and load that value into the register rsi . The instruction does NOT load the address of "msg" into register rsi . This could be done by (note the $ ): mov $msg, %rsi According to what I've read, a

Trying to implement strlen in x86 GAS

笑着哭i 提交于 2019-12-02 03:56:52
so I am very new (extremely new) to assembly programming and am trying to write a function that can calculate the length of a string. I feel I have some issue with clearing out values in registers, or with the incrementation of the pointer, because the value that is getting returned is always "4571 + length" for me. Basically, if I have string length 0, I get 4571 as the return value. If I have string length 6, I get 4577 as the return value, etc. Here's my code, any help will be appreciated: .globl my_strlen my_strlen: pushq %rbp movq %rsp, %rbp pushq %r12 pushq %r13 movq $0, %rax cmp $0, (

Declaring and indexing an integer array of qwords in assembly

青春壹個敷衍的年華 提交于 2019-12-02 03:40:54
I have a question regarding how to initialize an array in assembly. I tried: .bss #the array unsigned: .skip 10000 .data #these are the values that I want to put in the array par4: .quad 500 par5: .quad 10 par6: .quad 15 That's how I declared my string and the variables that I want to put it inside. This is how I tried to put them into the array: movq $0 , %r8 movq par4 , %rax movq %rax , unsigned(%r8) incq %r8 movq par5 , %rax movq %rax , unsigned(%r8) incq %r8 movq par6 , %rax movq %rax , unsigned(%r8) I tried printing the elements to check if everything is okay, and only the last one prints

Move an int64_t to the high quadwords of an AVX2 __m256i vector

与世无争的帅哥 提交于 2019-12-02 03:35:30
This question is similar to [1]. However I didn't quite understand how it addressed inserting to high quadwords of a ymm using a GPR. Additionally I want the operation not use any intermediate memory accesses. Can it be done with AVX2 or below (I don't have AVX512)? [1] How to move double in %rax into particular qword position on %ymm or %zmm? (Kaby Lake or later) My answer on the linked question didn't show a way to do that because it can't be done very efficiently without AVX512F for a masked broadcast ( vpbroadcastq zmm0{k1}, rax ). But it's actually not all that bad using a scratch