将64位常量移动到x86 Assembly中的内存中 [英] Moving 64-bit constant to memory in x86 Assembly
问题描述
我正在使用Intel x64程序集,NASM编译器,试图将"0x4000000000000000"常量移至内存,在ieee 754标准中,常量应等于2.0.
I'm working with Intel x64 assembly, NASM compiler, trying to move the "0x4000000000000000" constant to memory, which in the ieee 754 standard double should be equal to 2.0.
我正在使用的代码是:
%define two 0x4000000000000000
section .text
foo:
push rbp
mov rbp, rsp
mov QWORD [rdi], two
pop rbp
ret
编译此引发
警告:带符号的双字立即超出范围.
warning: signed dword immediate exceeds bounds.
当我在C ++中打印值时,它显示为"0"而不是"2".
When i print the value in C++ it shows "0" instead of "2".
我已经找到一种获取正确值的方法,即:
I've already found a way of getting the right value, which is:
mov r9, 0x4000000000000000
mov [rdi], r9
但是我想知道是否有一种无需使用寄存器即可实现这一目标的方法.
But i would like to know if there is a way of achieving this without the use of a register.
顺便说一下,我使用以下脚本来编译代码:
by the way, im compiling the code with this script:
#!/bin/bash
nasm -f elf64 -g -F dwarf vvp_asm.asm -o vvp_asm.o
g++ -c -m64 -std=c++11 main.cpp -o main.o
g++ -o main -m64 vvp_asm.o main.o
推荐答案
没有说明
mov r/m64, imm64
您可以使用
mov dword [rdi], 0
mov dword [rdi+4], 0x40000000
或
and qword [rdi], 0
mov byte [rdi+7], 0x40
只有8个字节(如果有的话).
which is only 8 bytes (if that matters).
这篇关于将64位常量移动到x86 Assembly中的内存中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!