x86-64

NASM: How to create/handle basic bmp file using intel 64 bit assembly?

前提是你 提交于 2021-01-07 10:40:17
问题 How do I create/handle simple bmp file filling it with one color only using intel 64 bit assembly and nasm assembler? 回答1: The steps that include such operation are: Create bmp file header with fixed values (explanation of specific fields below) Create buffer which contains enough space - three bytes per pixel (one color = red + green + blue) Open/create file Fill the buffer Write header to file Write buffer to file Close file Exit program Ad. 2: This is a bit more tricky - if the number of

Image base comes out wrong in manually-generated PE headers for a 64-bit executable

谁都会走 提交于 2021-01-05 07:43:38
问题 I want to build Custom Portable executable using NASM. After getting executable using command nasm -f bin program.asm -o program.exe it crashes and gives error similar to this Below you can see the code. bits 64 %define BASE 400000h ALIGNMENT equ 512 %define SECTALIGN 8192 STD_OUTPUT_HANDLE equ -11 NULL equ 0 %define ROUND(v, a) (((v + a - 1) / a) * a) %define ALIGNED(v) (ROUND(v, ALIGNMENT)) %define RVA(obj) (obj - BASE) section header progbits start=0 vstart=BASE mz_hdr: dw "MZ" ; DOS magic

Image base comes out wrong in manually-generated PE headers for a 64-bit executable

家住魔仙堡 提交于 2021-01-05 07:40:51
问题 I want to build Custom Portable executable using NASM. After getting executable using command nasm -f bin program.asm -o program.exe it crashes and gives error similar to this Below you can see the code. bits 64 %define BASE 400000h ALIGNMENT equ 512 %define SECTALIGN 8192 STD_OUTPUT_HANDLE equ -11 NULL equ 0 %define ROUND(v, a) (((v + a - 1) / a) * a) %define ALIGNED(v) (ROUND(v, ALIGNMENT)) %define RVA(obj) (obj - BASE) section header progbits start=0 vstart=BASE mz_hdr: dw "MZ" ; DOS magic

GCC Inline-Assembly Error: “Operand size mismatch for 'int'”

丶灬走出姿态 提交于 2021-01-04 05:59:52
问题 first, if somebody knows a function of the Standard C Library, that prints a string without looking for a binary zero, but requires the number of characters to draw, please tell me! Otherwise, I have this problem: void printStringWithLength(char *str_ptr, int n_chars){ asm("mov 4, %rax");//Function number (write) asm("mov 1, %rbx");//File descriptor (stdout) asm("mov $str_ptr, %rcx"); asm("mov $n_chars, %rdx"); asm("int 0x80"); return; } GCC tells the following error to the "int" instruction:

GCC Inline-Assembly Error: “Operand size mismatch for 'int'”

萝らか妹 提交于 2021-01-04 05:59:11
问题 first, if somebody knows a function of the Standard C Library, that prints a string without looking for a binary zero, but requires the number of characters to draw, please tell me! Otherwise, I have this problem: void printStringWithLength(char *str_ptr, int n_chars){ asm("mov 4, %rax");//Function number (write) asm("mov 1, %rbx");//File descriptor (stdout) asm("mov $str_ptr, %rcx"); asm("mov $n_chars, %rdx"); asm("int 0x80"); return; } GCC tells the following error to the "int" instruction:

Calling C function from masm 64

余生长醉 提交于 2021-01-01 06:36:39
问题 I have a problem with my assembly code (64 bit masm in Visual 2013 on win8 64). When I'm calling C function (printf), it throwing exception from ntdll.dll. What I'm doing wrong? How I can read and write data from console in 64 bit masm? Where I can find good tutorial for masm 64 bit? extrn printf : proc .data format byte "Arg1: %d", 10, 0 .code printData proc mov rbx, 100 push rbx lea rax, format; format address push rax call printf; throw unhandled exception ntdll.dll - Access violation

Is the transformation of fetch_add(0, memory_order_relaxed/release) to mfence + mov legal?

老子叫甜甜 提交于 2020-12-30 06:32:27
问题 The paper N4455 No Sane Compiler Would Optimize Atomics talks about various optimizations compilers can apply to atomics. Under the section Optimization Around Atomics, for the seqlock example, it mentions a transformation implemented in LLVM, where a fetch_add(0, std::memory_order_release) is turned into a mfence followed by a plain load, rather than the usual lock add or xadd . The idea is that this avoids taking exclusive access of the cacheline, and is relatively cheaper. The mfence is

Is the transformation of fetch_add(0, memory_order_relaxed/release) to mfence + mov legal?

笑着哭i 提交于 2020-12-30 06:31:41
问题 The paper N4455 No Sane Compiler Would Optimize Atomics talks about various optimizations compilers can apply to atomics. Under the section Optimization Around Atomics, for the seqlock example, it mentions a transformation implemented in LLVM, where a fetch_add(0, std::memory_order_release) is turned into a mfence followed by a plain load, rather than the usual lock add or xadd . The idea is that this avoids taking exclusive access of the cacheline, and is relatively cheaper. The mfence is

how to set control register 0 (cr0) bits in x86-64 using gcc assembly on linux

做~自己de王妃 提交于 2020-12-29 04:01:45
问题 I am using the following code to set the cr0 bit to disable cache. When I compile this #include <stdio.h> int main() { __asm__("pushl %eax\n\t" "mov %cr0,%eax;\n\t" "orl $(1 << 30),%eax;\n\t" "mov %eax,%cr0;\n\t" "wbinvd\n\t" "popl %eax" ); return 0; } I am getting error saying that the operands are invalid for mov. Can anyone please point me to a good gcc x86-64 guide for doing these kinds of things? Also what exactly is wrong with the above code? 回答1: Ok, so finally I wrote the following

how to set control register 0 (cr0) bits in x86-64 using gcc assembly on linux

£可爱£侵袭症+ 提交于 2020-12-29 04:00:59
问题 I am using the following code to set the cr0 bit to disable cache. When I compile this #include <stdio.h> int main() { __asm__("pushl %eax\n\t" "mov %cr0,%eax;\n\t" "orl $(1 << 30),%eax;\n\t" "mov %eax,%cr0;\n\t" "wbinvd\n\t" "popl %eax" ); return 0; } I am getting error saying that the operands are invalid for mov. Can anyone please point me to a good gcc x86-64 guide for doing these kinds of things? Also what exactly is wrong with the above code? 回答1: Ok, so finally I wrote the following