x86-64

x64 instruction encoding and the ModRM byte

若如初见. 提交于 2019-12-17 16:48:11
问题 The encoding of call qword ptr [rax] call qword ptr [rcx] is FF 10 FF 11 I can see where the last digit (0/1) comes from (the register number), but I'm trying to figure out where the second last digit (1) comes from. According to AMD64 Architecture Programmer’s Manual Volume 3: General-Purpose and System Instructions page 56, "/digit - Indicates that the ModRM byte specifies only one register or memory (r/m) operand. The digit is specified by the ModRM reg field and is used as an instruction

How to add x64 (or Any CPU) as a build option in Visual Studio 2010 (from console application to class library)

狂风中的少年 提交于 2019-12-17 16:35:11
问题 Initially, I created a console application using Mass Transit as my service bus. Recently, I switched to NServiceBus, which doesn't require you to make a console application, but a class library instead. In the project properties, I simply switched the setting that changes it from a console application to a library, but the constraint that you can only build it for x86 is still in effect. I can't change the build type to Any CPU now that it is a console application, which should now be valid.

Qt5.1/Qt5.2 + Mac OS 10.9 (Mavericks) + XCode 5.0.2, Undefined symbols for architecture x86_64

北战南征 提交于 2019-12-17 15:45:08
问题 Environment : Mac OS 10.9 + Qt5.1/Qt5.2 + OpenCV2.4.7 + XCode(5.0.2) I can compile the following program via terminal g++ -L/usr/local/lib -lopencv_core -lopencv_highgui \ -I/usr/local/include main.cpp The program a.out runs normally. However, when using Qt 5.1/5.2 to run this OpenCV program, I got "Undefined symbols for architecture x86_64". However, Qt5 works normally for a simple HelloWorld c++ program. What is going on ? Here is the code. #include <iostream> #include "opencv2/highgui

CPUID implementations in C++

偶尔善良 提交于 2019-12-17 15:28:53
问题 I would like to know if somebody around here has some good examples of a C++ CPUID implementation that can be referenced from any of the managed .net languages. Also, should this not be the case, should I be aware of certain implementation differences between X86 and X64? I would like to use CPUID to get info on the machine my software is running on (crashreporting etc...) and I want to keep everything as widely compatible as possible. Primary reason I ask is because I am a total noob when it

Converting 32-bit Application Into 64-bit Application in C

♀尐吖头ヾ 提交于 2019-12-17 15:25:56
问题 I am presently working on converting a 32bits application into a 64bits application in C. This application is currently working on x86 architecture (Windows, osx, Unix, Linux). So, before starting coding, I wanted to know what do I need to consider while converting the application. 回答1: Find out who wrote it. Are they an idiot? Are they you from a few years ago? Can you ask them questions? Are they familiar with the existence of multiple platforms and systems? Knowing the mind-set of the

What is the purpose of the RBP register in x86_64 assembler?

瘦欲@ 提交于 2019-12-17 15:16:32
问题 So I'm trying to learn a little bit of assembly, because I need it for Computer Architecture class. I wrote a few programs, like printing the Fibonacci sequence. I recognized that whenever I write a function I use those 3 lines (as I learned from comparing assembly code generated from gcc to its C equivalent): pushq %rbp movq %rsp, %rbp subq $16, %rsp I have 2 questions about it: First of all, why do I need to use %rbp ? Isn't it simpler to use %rsp , as its contents are moved to %rbp on the

What kind of C11 data type is an array according to the AMD64 ABI

烂漫一生 提交于 2019-12-17 14:58:09
问题 I was researching the calling convention of x86_64 that's used on OSX and was reading the section called "Aggregates and Unions" in the System V x86-64 ABI standard). It mention arrays and I figured that was like a fixed length c array, e.g. int[5] . I went down to "3.2.3 Parameter Passing" to read about how arrays were passed and if I'm understanding correctly, something like uint8_t[3] should be passed in registers as it's smaller than the four eightbyte limit imposed by rule 1 of the

Unoptimized clang++ code generates unneeded “movl $0, -4(%rbp)” in a trivial main()

拟墨画扇 提交于 2019-12-17 14:56:50
问题 I created a minimal C++ program: int main() { return 1234; } and compiled it with clang++5.0 with optimization disabled (the default -O0 ). The resulting assembly code is: pushq %rbp movq %rsp, %rbp movl $1234, %eax # imm = 0x4D2 movl $0, -4(%rbp) popq %rbp retq I understand most of the lines, but I do not understand the "movl $0, -4(%rbp)". It seems the program initializes some local variable to 0. Why? What compiler-internal detail leads to this store that doesn't correspond to anything in

How do RIP-relative variable references like “[RIP + _a]” in x86-64 GAS Intel-syntax work?

感情迁移 提交于 2019-12-17 14:53:22
问题 Consider the following variable reference in x64 Intel assembly, where the variable a is declared in the .data section: mov eax, dword ptr [rip + _a] I have trouble understanding how this variable reference works. Since a is a symbol corresponding to the runtime address of the variable (with relocation), how can [rip + _a] dereference the correct memory location of a ? Indeed, rip holds the address of the current instruction, which is a large positive integer, so the addition results in an

How do RIP-relative variable references like “[RIP + _a]” in x86-64 GAS Intel-syntax work?

陌路散爱 提交于 2019-12-17 14:53:08
问题 Consider the following variable reference in x64 Intel assembly, where the variable a is declared in the .data section: mov eax, dword ptr [rip + _a] I have trouble understanding how this variable reference works. Since a is a symbol corresponding to the runtime address of the variable (with relocation), how can [rip + _a] dereference the correct memory location of a ? Indeed, rip holds the address of the current instruction, which is a large positive integer, so the addition results in an