assembly

NASM x86_64 assembly in 32-bit mode: Why does this instruction produce RIP-Relative Addressing code?

孤街浪徒 提交于 2020-07-29 06:59:12
问题 [bits 32] global _start section .data str_hello db "HelloWorld", 0xa str_hello_length db $-str_hello section .text _start: mov ebx, 1 ; stdout file descriptor mov ecx, str_hello ; pointer to string of characters that will be displayed mov edx, [str_hello_length] ; count outputs Relative addressing mov eax, 4 ; sys_write int 0x80 ; linux kernel system call mov ebx, 0 ; exit status zero mov eax, 1 ; sys_exit int 0x80 ; linux kernel system call The fundamental thing here is that I need to have

Why is ONE basic arithmetic operation in for loop body executed SLOWER THAN TWO arithmetic operations?

落花浮王杯 提交于 2020-07-28 06:25:11
问题 While I experimented with measuring time of execution of arithmetic operations, I came across very strange behavior. A code block containing a for loop with one arithmetic operation in the loop body was always executed slower than an identical code block, but with two arithmetic operations in the for loop body. Here is the code I ended up testing: #include <iostream> #include <chrono> #define NUM_ITERATIONS 100000000 int main() { // Block 1: one operation in loop body { int64_t x = 0, y = 0;

Do x86 instructions require their own encoding as well as all of their arguments to be present in memory at the same time?

妖精的绣舞 提交于 2020-07-27 09:26:37
问题 I am trying to figure out whether it is possible to run a Linux VM whose RAM is only backed by a single physical page. To simulate this, I modified the nested page fault handler in KVM to remove the present bit from all nested page table (NPT) entries, except the one corresponding to the currently processed page fault. While trying to start a Linux guest, I observed that assembly instructions that use memory operands, like add [rbp+0x820DDA], ebp lead to a page fault loop until I restore the

Do x86 instructions require their own encoding as well as all of their arguments to be present in memory at the same time?

丶灬走出姿态 提交于 2020-07-27 09:26:27
问题 I am trying to figure out whether it is possible to run a Linux VM whose RAM is only backed by a single physical page. To simulate this, I modified the nested page fault handler in KVM to remove the present bit from all nested page table (NPT) entries, except the one corresponding to the currently processed page fault. While trying to start a Linux guest, I observed that assembly instructions that use memory operands, like add [rbp+0x820DDA], ebp lead to a page fault loop until I restore the

Do x86 instructions require their own encoding as well as all of their arguments to be present in memory at the same time?

有些话、适合烂在心里 提交于 2020-07-27 09:26:08
问题 I am trying to figure out whether it is possible to run a Linux VM whose RAM is only backed by a single physical page. To simulate this, I modified the nested page fault handler in KVM to remove the present bit from all nested page table (NPT) entries, except the one corresponding to the currently processed page fault. While trying to start a Linux guest, I observed that assembly instructions that use memory operands, like add [rbp+0x820DDA], ebp lead to a page fault loop until I restore the

Why does GCC allocate more space than necessary on the stack, beyond what's needed for alignment?

浪尽此生 提交于 2020-07-25 06:16:08
问题 I'm reading a textbook which shows assembly code based on C code: C code: void echo() { char buf[8]; otherFunction(buf); } assembly code: echo: subq $24, %rsp //Allocate 24 bytes on stack, but why allocate 24 instead of 8 bytes? movq %rsp, %rdi //Compute buf as %rsp call otherFunction I don't understand why stack pointer %rsp is decremented by 24 bytes. I only assign 8 bytes' buffer as char buf[8]; , and there no callee saved registers to push on stack, shouldn't the instruction be subq $8,

Why does GCC allocate more space than necessary on the stack, beyond what's needed for alignment?

我们两清 提交于 2020-07-25 06:15:39
问题 I'm reading a textbook which shows assembly code based on C code: C code: void echo() { char buf[8]; otherFunction(buf); } assembly code: echo: subq $24, %rsp //Allocate 24 bytes on stack, but why allocate 24 instead of 8 bytes? movq %rsp, %rdi //Compute buf as %rsp call otherFunction I don't understand why stack pointer %rsp is decremented by 24 bytes. I only assign 8 bytes' buffer as char buf[8]; , and there no callee saved registers to push on stack, shouldn't the instruction be subq $8,

How many bytes are there in one address? [duplicate]

匆匆过客 提交于 2020-07-23 06:55:03
问题 This question already has answers here : Does a memory address point to a byte of information? (2 answers) Closed last year . On a 64bit machine, we know that an address is 8 bytes. However, I am not entirely clear how many bytes of information is in one address. Does every byte in virtual memory have an address? Or does every 64 bits in memory have an address? Or does it depend on the architecture? If it depends on the architecture, then how should I find out? 回答1: Your question is related

How many bytes are there in one address? [duplicate]

痴心易碎 提交于 2020-07-23 06:53:22
问题 This question already has answers here : Does a memory address point to a byte of information? (2 answers) Closed last year . On a 64bit machine, we know that an address is 8 bytes. However, I am not entirely clear how many bytes of information is in one address. Does every byte in virtual memory have an address? Or does every 64 bits in memory have an address? Or does it depend on the architecture? If it depends on the architecture, then how should I find out? 回答1: Your question is related

How many bytes are there in one address? [duplicate]

痞子三分冷 提交于 2020-07-23 06:52:30
问题 This question already has answers here : Does a memory address point to a byte of information? (2 answers) Closed last year . On a 64bit machine, we know that an address is 8 bytes. However, I am not entirely clear how many bytes of information is in one address. Does every byte in virtual memory have an address? Or does every 64 bits in memory have an address? Or does it depend on the architecture? If it depends on the architecture, then how should I find out? 回答1: Your question is related