Monday, November 3, 2014

 

CVTDQ2PD instruction

Convert Packed Dword Integers to Packed Double-Precision FP Values.

In this example, there are two integers data1(=35) and data2 (=67).
Using the CVTDQ2PD instruction, the two integers above will
be converted to Double Precision floating point values. The CVTDQ2PS
instruction is used if the integers are to be converted to Single Precision
floating point values.

Syntax:

CVTDQ2PD xmm1, m64 --> m64 is the memory location to 64 bits(2 dword integers) of data

[or]

CVTDQ2PD xmm1, xmm2 --> xmm2 contains two dword integers.


Program:
 section .data
data1   dd 35
data2   dd 67

section .text

global main

main:
nop
cvtdq2pd xmm7, [data1]

movq xmm3, [data1] ; move quadword into xmm3
cvtdq2pd xmm4, xmm3

mov eax, 1
mov ebx, 0
int 0x80

Notes:
 There are two forms of cvtdq2pd used above - The first one converts two dword integers from memory into two double precision floating point values. The second form performs the same operation with the source residing in xmm3 register. The value is moved into xmm3 from memory using the movq instruction.

To assemble and link:

 nasm -felf64 cvt.asm
  gcc -o cvt cvt.o

Using gdb:

3. gdb  cvt
     (gdb) break main
     (gdb) run
     (gdb) set disassembly-flavor intel
     (gdb) disassemble main

;Dump of assembler code for function main:
  0x00000000004004c0 <+0>:    nop
   0x00000000004004c1 <+1>:    cvtdq2pd xmm7,QWORD PTR ds:0x601018
   0x00000000004004ca <+10>:    movq   xmm3,QWORD PTR ds:0x601018
   0x00000000004004d3 <+19>:    cvtdq2pd xmm4,xmm3
=> 0x00000000004004d7 <+23>:    mov    eax,0x1
   0x00000000004004dc <+28>:    mov    ebx,0x0
   0x00000000004004e1 <+33>:    int    0x80

4. Set a  breakpoint on IP 0x4004c1 , then check the value of xmm7:

(gdb) p /x $xmm7
$1 = {v4_float = {0x0, 0x3, 0x0, 0x3}, v2_double = {0x23, 0x43}, v16_int8 = {0x0, 0x0, 0x0, 0x0, 0x0, 0x80, 0x41, 0x40, 0x0, 0x0, 0x0, 0x0, 0x0, 0xc0, 0x50, 0x40},
  v8_int16 = {0x0, 0x0, 0x8000, 0x4041, 0x0, 0x0, 0xc000, 0x4050}, v4_int32 = {0x0,   0x40418000, 0x0, 0x4050c000}, v2_int64 = {0x4041800000000000, 0x4050c00000000000},
  uint128 = 0x4050c000000000004041800000000000}


xmm7[63:0] has 0x4041800000000000 which is 35.0 represented in double precision format.

 xmm7[127:64] has 0x4050c00000000000 which is 67.0 represented in double precision format.




This page is powered by Blogger. Isn't yours?

Subscribe to Posts [Atom]