x86-64

When is it better for an assembler to use sign extended relocation like R_X86_64_32S instead of zero extension like R_X86_64_32?

久未见 提交于 2019-12-12 17:14:47
问题 As a concrete example, on GAS 2.24, moving the address: mov $s, %eax s: After: as --64 -o a.o a.S objdump -Sr a.o Uses zero extension: 0000000000000000 <s-0x5>: 0: b8 00 00 00 00 mov $0x0,%eax 1: R_X86_64_32 .text+0x5 But memory access: mov s, %eax s: Compiles to sign extension: 0000000000000000 <s-0x7>: 0: 8b 04 25 00 00 00 00 mov 0x0,%eax 3: R_X86_64_32S .text+0x7 Is there a rationale to using either in this specific case, or in general? I don't understand how the assembler could to any

NASM x86_64 scanf segmentation fault

梦想与她 提交于 2019-12-12 17:12:27
问题 I am new to nasm and I really want to learn how to store a number with user input. I can't get rid of getting segmentation fault when using scanf. I have searched the web, but havent found any solution to this problem. I tried this code but it doesn't work for me. Can someone explain me what am I doing wrong? global main extern printf, scanf section .data msg: db "Enter a number: ",10,0 format:db "%d",0 section .bss number resb 4 section .text main: mov rdi, msg mov al, 0 call printf push

Incorrect NASM indirect addressing assembly on macOS

一笑奈何 提交于 2019-12-12 17:07:52
问题 Assembling the following code on macOS: global start default rel section .text start: lea rdx, [buffer + 0] lea rdx, [buffer + 1] lea rdx, [buffer + 2] lea rdx, [buffer + 3] lea rdx, [buffer + 4] lea rdx, [buffer + 5] lea rdx, [buffer + 6] lea rdx, [buffer + 7] lea rdx, [buffer + 8] section .data buffer: db 0,0,0 using the command nasm -fmacho64 -w+all test.asm -o test.o , yields: (with gobjdump -d test.o ) 0000000000000000 <start>: 0: 48 8d 15 38 00 00 00 lea 0x38(%rip),%rdx # 3f <buffer> 7:

Are there C functions or macros specifically designed to compile 1 to 1 with assembly instructions for bit manipulations in a cross-platform manner?

被刻印的时光 ゝ 提交于 2019-12-12 16:24:45
问题 I've got a project involving emulation (If you look at my post history, you'll see how far I've come!) and I'm looking to do pseudo-binary-translation using C and playing with the optimizers and/or compilers to use C code that compiles my switch statement contents to a single assembly instruction, primarily for very standard instructions such as mov s, add , SR and other simple bit manipulations and arithmetic instructions. I'm hoping to do this for ARM and x86-64 at the same time, writing as

NASM on Virtual Machine Ubuntu: Cannot execute binary file exec format error

≯℡__Kan透↙ 提交于 2019-12-12 13:22:27
问题 I am getting an error after assembling a simple 64 bit hello world program. I am using the following commands: nasm -f elf64 hello.asm -o hello.o successfull ld -o hello.o hello -m elf_x86_64 successfull ./hello error: Cannot execute binary file exec format error I am executing this in a 64 bit Ubuntu Virtual Machine. I appreciate your help! 回答1: The error: error: Cannot execute binary file exec format error Suggests your system can't understand the executable you are trying to run. In my

Loading small numbers into 64 bit x86 registers

北慕城南 提交于 2019-12-12 13:16:16
问题 Under 64 bit x86 CPU normally we load number -1 in to register like: mov rdx, -1 // 48BAFFFFFFFFFFFFFFFF ... this opcode takes 10 bytes. Another way is: xor rdx, rdx // 4831D2 dec rdx // 48FFCA ... this opcode takes only 6 bytes. EDIT : As Jens Björnhager say (I have tested) xor edx, edx opcode should clear whole rdx register: xor edx, edx // 31D2 dec rdx // 48FFCA ... this opcode takes only 5 bytes. EDIT: Alex find another solution: mov rdx, -1 // 48C7C2FFFFFFFF ... this opcode takes only 7

Cycle Through and Print argv[] in x64 ASM

▼魔方 西西 提交于 2019-12-12 13:00:56
问题 I have been working on essentially a while loop to go through all CLI arguments. While working on solution to only print 1 element I noticed a few things; this was the thought process that led me to here. I noticed that if I did lea 16(%rsp), %someRegisterToWrite , I was able to get/print argv[1]. Next I tried lea 24(%rsp), %someRTW and this gave me access to argv[2]. I kept going up to see if it would continue to work and it did. My thought was to keep adding 8 to %someRTW and increment a

How to abandon (invalidate without saving) a cache line on x86_64?

安稳与你 提交于 2019-12-12 12:19:17
问题 As I understand, _mm_clflush() / _mm_clflushopt() invalidates a cache line while saving it to memory if it has been changed. Is there a way to simply abandon a cache line, without saving to memory any changes made to it? A use case is before freeing memory: I don't need cache lines or their values anymore. 来源: https://stackoverflow.com/questions/45987746/how-to-abandon-invalidate-without-saving-a-cache-line-on-x86-64

What EXACTLY is the difference between intel's and amd's ISA, if any?

ぐ巨炮叔叔 提交于 2019-12-12 12:03:04
问题 I know people have asked similar questions like this before, however there is so much conflicting information that I really want to try and clear it up once and for all. I will attempt to do so by clearly distinguishing between instruction set architecture (ISA) and actual hardware implementation. First my attempted clarifications: 1.) Currently there are intel64 and amd64 CPU's out there (among others but these are the focus) 2.) Given that an ISA is the binary representation of 1 or more

"relocation R_X86_64_32S against `.bss' can not be used when making a shared object”

笑着哭i 提交于 2019-12-12 11:37:42
问题 I'm absolutely green in this but during classes, teacher gave us file he wrote just for us to run it and it worked fine then, but when I try to do it at home (I use Linux on VirtualBox) and use: nasm -f elf64 hello.asm -o hello.o gcc hello.o -o hello I get an error "relocation R_X86_64_32S against `.bss' can not be used when making a shared object; recompile with -fPIC”. Can someone please explain what to do to make it work? global main extern printf section .data napis: db ' Hello world! -