Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Moving 64-bit constant to memory in x86 Assembly

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.

The code I'm using is:

%define two 0x4000000000000000 

section .text

foo:

push rbp
mov rbp, rsp

mov QWORD [rdi], two

pop rbp
ret

Compiling this throws

warning: signed dword immediate exceeds bounds.

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
like image 338
Martin Ventura Avatar asked Sep 24 '17 22:09

Martin Ventura


1 Answers

There is no instruction

    mov r/m64, imm64

You could use

    mov dword [rdi], 0
    mov dword [rdi+4], 0x40000000

or

    and qword [rdi], 0
    mov byte [rdi+7], 0x40

which is only 8 bytes (if that matters).

like image 152
prl Avatar answered Oct 26 '22 05:10

prl