x86-64

What is the difference between assembly language of x86 and x64 architecture?

六月ゝ 毕业季﹏ 提交于 2019-12-22 10:38:27
问题 I am studying this book here . Now it says repeatedly to use a x86 processor cause its source code's are based on x86. But My laptop is of type amd64 . So I want to know how much is the difference. Can I continue reading the book and understand? 回答1: Actual 64 bit programs use a different instruction set (though it has a strong family resemblance). But that doesn't need to concern you, as it's backwards compatible: 32 bit code runs just fine, if you don't attempt to compile it as 64 bit code.

Get a signal on each page fault

爷,独闯天下 提交于 2019-12-22 09:31:54
问题 I want to set a signal handler in my application, so that the kernel sends a signal whenever it handles a page fault trap. Ofcourse I can use the SIGSEGV signal handler, but what I'm really interested in is to catch the page faults which occur on copy-on-write. For example after a fork (not followed by exec), the original process will get a page fault if it tries to write to some page. I want to get notified on such page faults. How can I achieve this? 回答1: page faults are interrupts handled

How do i write Simple inline asm instruction from C on Linux 64 bit?

偶尔善良 提交于 2019-12-22 09:08:00
问题 i am writing a simple c program and my requirement is to print RIP(Instruction Pointer) from some function of the program. i dont want to use ptrace. the one thing i tried with inline asm is: asm("movl %%rip, %0;" : "=r"(val) ) this should copy my rip register value to variable val, but i am getting compilation error. if i use ebp/esp which are base pointer and stack pointers for 32 bit machine, i dont get any compilation error and my val has some hexadecimal number assigned. i have few

How cmp assembly instruction sets flags (X86_64 GNU Linux)

若如初见. 提交于 2019-12-22 08:29:41
问题 Here is a simple C program: void main() { unsigned char number1 = 4; unsigned char number2 = 5; if (number1 < number2) { number1 = 0; } } So here we are comparing two numbers. In assembly it will be done using cmp. cmp works by subtracting one operand from other. Now how cmp is subtracting operands? Is it subtracting 1st operand from 2nd or vice versa? In any case, this should go like this: case # 1: 4 - 5 = (0000 0100 - 0000 0101) = (0000 0100 + 1111 1010 + 1) = (0000 0100 + 1111 1011) =

GCC Assembly Optimizations - Why are these equivalent?

拥有回忆 提交于 2019-12-22 03:58:43
问题 I am trying to learn how assembly works at an elementary level and so I have been playing with the -S output of gcc compilations. I wrote a simple program that defines two bytes and returns their sum. The entire program follows: int main(void) { char A = 5; char B = 10; return A + B; } When I compile this with no optimizations using: gcc -O0 -S -c test.c I get test.s that looks like the following: .file "test.c" .def ___main; .scl 2; .type 32; .endef .text .globl _main .def _main; .scl 2;

Perf startup overhead: Why does a simple static executable which performs MOV + SYS_exit have so many stalled cycles (and instructions)?

馋奶兔 提交于 2019-12-22 03:35:23
问题 I'm trying to understand how to measure performance and decided to write the very simple program: section .text global _start _start: mov rax, 60 syscall And I ran the program with perf stat ./bin The thing I was surprised by is the stalled-cycles-frontend was too high. 0.038132 task-clock (msec) # 0.148 CPUs utilized 0 context-switches # 0.000 K/sec 0 cpu-migrations # 0.000 K/sec 2 page-faults # 0.052 M/sec 107,386 cycles # 2.816 GHz 81,229 stalled-cycles-frontend # 75.64% frontend cycles

Why the number of x86 int registers is 8?

一曲冷凌霜 提交于 2019-12-21 20:47:10
问题 Recently I started to learn x86 assembly language and CPU architecture. I noticed that total number of int registers is 8, but for x86-64 it is 16. Why? There must be some explanation. 回答1: The x86 architecture has evolved from its earliest incarnation as an 8008 back in the early 1970s. At the time, memory bytes and therefore opcode space was extremely precious; only 3 bits were set aside for the (at the time) A, B, C, D, E, F, (and IIRC) H and L registers, all 8 bits. (I remember how

How to ensure that RDTSC is accurate?

人盡茶涼 提交于 2019-12-21 20:19:30
问题 I've read that RDTSC can gives false readings and should not be relied upon. Is this true and if so what can be done about it? 回答1: Very old CPU's have a RDTSC that is accurate. The problem However newer CPU's have a problem. Engineers decided that RDTSC would be great for telling time. However if a CPU throttles the frequency RDTSC is useless for telling time. The aforementioned braindead engineers then decided to 'fix' this problem by having the TSC always run at the same frequency, even if

Can rip be used with another register with RIP-relative addressing?

纵饮孤独 提交于 2019-12-21 17:42:52
问题 I'm familiar with memory references of this form: XXX ptr [base + index * size + displacement] where XXX is some size (byte/word/dword/etc), both base and index are registers, size is a small power of two, and displacement is a signed value. amd64 introduced rip-relative addressing. As I understand it, I should be able to use rip as a base register. However, when I try this with clang-900.0.39.2: mov r8b, byte ptr [rip + rdi * 1 + Lsomething] I get: error: invalid base+index expression mov

Is tooling available to 'assemble' WebAssembly to x86-64 native code?

廉价感情. 提交于 2019-12-21 17:15:36
问题 I am guessing that a Wasm binary is usually JIT-compiled to native code, but given a Wasm source, is there a tool to see the actual generated x86-64 machine code? Or asked in a different way, is there a tool that consumes Wasm and outputs native code? 回答1: The online WasmExplorer compiles C code to both WebAssembly and FireFox x86, using the SpiderMonkey compiler. Given the following simple function: int testFunction(int* input, int length) { int sum = 0; for (int i = 0; i < length; ++i) {