将 double dq 从汇编语言转换为 C

Convert double dq from assembly to C

我有以下汇编代码。表示一个双精度类型的 8 字节变量:

L10004CAE:
dq  3FA999999999999Ah

我如何理解它应该是哪个数字?

double x= ??? ;

是否有任何应用程序或在线计算器可以计算这些数字?

如果你有c编译器,就是这样:

#include<stdio.h>

int
main ()
{
  unsigned long long a = 0x3FA999999999999A;

  printf ("%f\n", *(double *)&a); /* 0.050000 */

  return 0;
}

一个非常古老的双精度计算器,输出和可选地输入一个十六进制四字作为输入值(使用前导 x 作为十六进制值)。

/*------------------------------------------------------*/
/*      dcalc   double precision calculator             */
/*------------------------------------------------------*/
#define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>
#include <string.h>
#include <math.h>

typedef int word;                       /* set up types */
typedef unsigned char uchar;
typedef unsigned int  uword;
typedef unsigned long ulong;
typedef unsigned long long ULL;

static double expr(void);
static double value(void);
static int conrs(void);

static uchar bfr[80];                   /* console input bfr */
static uchar *ptxt, *pend;
static uchar numbfr[80];

int main()
{
register int d0;
double d1;
double f2;
ULL u3;

    bfr[0] = 78;                        /* init bfr */
    printf("dcalc 1.0\n");
    printf("Enter expressions to be evalated\n");
    printf("For example: 543*(123+456)\n");
    printf("Null entry exits program");

    while(1){
        printf("\n");
        if(0 == (d0 = conrs()))
            return(0);
        ptxt = &bfr[2];
        pend = ptxt+d0;
        d1 = expr();
        f2 = d1;
        u3 = *(ULL *)(&f2);
        printf("\n= %22.16Le %Lf %lld %llx", d1, d1, u3, u3);}
    return(0);
}

static double expr()
{
register uchar c0;
double d0;

    d0 = value();
    while(c0 = *ptxt){
        ptxt++;
        if(c0 == ' ')
            continue;
        if(c0 == '+'){                        /* check for add */
          d0 = d0 + value();
            continue;}
        if(c0 == '-'){                        /* check for subtract */
          d0 = d0 - value();
            continue;}
        if(c0 == '*'){                        /* check for mpy */
          d0 = d0 * value();
            continue;}
        if(c0 == '/'){                        /* check for div */
          d0 = d0 / value();
            continue;}
        if(c0 == '^'){
          d0 = pow(d0, value());
            continue;}
        if(c0 == ')'){
            break;}}
    return(d0);
}

static double value()
{
register uchar c0;
register int i;
register int d;
double f0;
double d0;

    d = 0;                                      /* hex / decimal flag */
    d0 = 0.;
    for(i = 0; c0 = *ptxt; ptxt++){
        if(c0 == ' ')
            continue;
        if(c0 == 'd' && d != 2){
            d = 1;
            continue;}
        if(c0 == 'x'){
            d = 2;
            continue;}
        if(c0 == '('){
            ptxt++;
            d0 = expr();
            break;}
        if(c0 < '0' && c0 != '.'){
            break;}
        if(c0 == '^')break;
        if(c0 <= '9' || (c0 >= 'a' && c0 <= 'f')){
            numbfr[i++] = c0;
            continue;}}
    numbfr[i] = 0;
    if(d == 0){
        sscanf(numbfr, "%Lf", &d0);}
    else if(d == 1){
        sscanf(numbfr, "%lld",  &f0);
        d0 = f0;}
    else if(d == 2){
        sscanf(numbfr, "%llx",  &f0);
        d0 = f0;}
    return(d0);
}

static int conrs()              /* get console response */
{
char * p;
    p = gets(&bfr[2]);
    if(p == NULL)
        return(0);
    return((int)strlen(p));
}