Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

x86 Assembly: movsd instruction issue

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?

like image 604
Bình Nguyên Avatar asked Nov 27 '22 17:11

Bình Nguyên


1 Answers

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.

like image 67
GJ. Avatar answered Dec 05 '22 06:12

GJ.