Question

This is my problem:
I trying to use scanf (in msvcrt.dll) to input a single floating point value in flat assembler then I write a simple "scanf program" like this (in C):

#include <stdio.h>

int main() {
    float a;

    scanf("%f", &a);
    printf("Just input: %f", a);
    return 0;
}

then using cl.exe to compile with /FA parameter to generate assembly file like this:

    lea eax, DWORD PTR _a$[ebp]
    push    eax
    push    OFFSET $SG2935
    call    _scanf
    add esp, 8
; Line 8
    cvtss2sd xmm0, DWORD PTR _a$[ebp]
    sub esp, 8
    movsd   QWORD PTR [esp], xmm0
    push    OFFSET $SG2936
    call    _printf
    add esp, 12                 ; 0000000cH

What I missunderstand is movsd instruction. According here: http://faydoc.tripod.com/cpu/movsb.htm it Move doubleword at address DS:(E)SI to address ES:(E)DI but I don't see any setting esi, edi up here and the movsd in generated source file have two parameters but in document in the link is it should not. Can someone explain me here?

Was it helpful?

Solution 2

I suspect that web page is presenting less than the full picture.

It talks about the A5 opcode but there are other variants such as F2 0F which allow movement between XMM registers and more arbitrary memory locations.

See here for more detail.

OTHER TIPS

There are two x86 instructions with the same name!

  1. MOVS/MOVSB/MOVSW/MOVSD/MOVSQ—Move Data from String to String
  2. MOVSD—Move Scalar Double-Precision Floating-Point Value

Check intel datasheet.

This is the other MOVSD instruction, which is part of the SSE instructions. Here it is moving the double precision float value from xmm0, into memory.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top