×

Loading...
Ad by
  • 最优利率和cashback可以申请特批,好信用好收入offer更好。请点链接扫码加微信咨询,Scotiabank -- Nick Zhang 6478812600。
Ad by
  • 最优利率和cashback可以申请特批,好信用好收入offer更好。请点链接扫码加微信咨询,Scotiabank -- Nick Zhang 6478812600。

一下为一个从地址为 0x7FF0 的 mem 中取出一个64位的double类型的数。请你看看 --------------------------------------------------------------------------------

1# double FetchDouble(void)
2# /*this function to is to fetch a double data from mem(0x07ff0 -0x07ff7)*/
3# {
4# double *doublepointer;
5# unsigned int address = 0x07FF0;
6# _asm
7# {
8# mov si,doublepointer
9# mov ax,ds:[address]
10# mov [si],ax;
11# mov ax,ds:[address+2]
12# mov [si+2],ax;
13# mov ax,ds:[address+4]
14# mov [si+4],ax;
15# mov ax,ds:[address+6]
16# mov [si+6],ax;
17# }
18# return (*doublepointer);
19# }

If I save 123456789.123456789 in the memory, the data I got is 123456789.1234357.
If I changed line 9 to:
mov ax,ds:0x07FF0
and the function works well.
I don't know the reason. Thanks for your help.
Report

Replies, comments and Discussions:

  • 工作学习 / IT技术讨论 / 请懂8088汇编及C的dx指点一下 。多谢
    我现在有一个double类型的数据要存在RAM 的一个固定地址里。机器是16位的。
    如果是int类型的数据,以下程序可以实现:
    void saveas (void)
    {
    int inttemp;
    _asm (存)
    {
    lea si,inttemp
    mov ax, [si]
    mov ds:07ff0h, ax
    }
    _asm (取)
    {
    lea si,inttemp
    mov ax,ds:07ff0h
    mov [si],ax;
    }

    }
    如果是double类型,就不行了:

    void error_adj(int n)
    {
    double inttemp=0;
    inttemp = 125.1234;
    _asm(存)
    {
    lea si,inttemp
    mov ax, [si]
    mov ds:07ff0h, ax
    inc si
    inc si
    mov ax, [si]
    mov ds:07ff2h,ax
    }
    }
    其中"lea si,inttemp " 编译就出错。
    • 比较急,请懂行的朋友支一下招吧。在C与汇编混合编程中,怎样才能将在C中定义的double变量存到固定的memory里呢?
      • just my 2-cent
        I have a small program which shows the memory bytes of different variable.

        For example, for int 123, it is saved as 0x00,00,00,7b

        for float 123.0, it is saved as 0x42,f6,00,00

        for double 123.0, when it is 8 bytes, it is saved as 0x40,5e,c0,00,00,00,00,00. The LSB will be filled when your double variable's value increases. For example, for double 123456789, it's memory is 0x41,9d,6f,34,54,00,00,00.

        there is an artical "What Every Computer Scientist Should Know About Floating-Point Arithmetic". You should be able to find it on the web.

        If you want the program or the article, just let me know, I can email them to you.

        HTH.
        • 问题是:我怎样才能将在C中定义的double 变量的地址传到汇编中去。如果是int 变量好办: lea si, 变量名 ; 就行了。但double变量不行?
          • 如果是这样的话, 试试直接把变量地址传给一个变量, 然后在汇编里用MOV SI, ADDRESS
            • 问题解决了。首先设一个指针指向这个变量,然后将指针mov到si里,方便以后的间接寻址。重要的是在我的16位系统里double变量是64位的(8byte)。多谢两位。多谢
            • 问题解决了,采用了你的方法。关键在我的16位系统里,double 是64位的,我以为是32位
        • 一下为一个从地址为 0x7FF0 的 mem 中取出一个64位的double类型的数。请你看看 --------------------------------------------------------------------------------
          1# double FetchDouble(void)
          2# /*this function to is to fetch a double data from mem(0x07ff0 -0x07ff7)*/
          3# {
          4# double *doublepointer;
          5# unsigned int address = 0x07FF0;
          6# _asm
          7# {
          8# mov si,doublepointer
          9# mov ax,ds:[address]
          10# mov [si],ax;
          11# mov ax,ds:[address+2]
          12# mov [si+2],ax;
          13# mov ax,ds:[address+4]
          14# mov [si+4],ax;
          15# mov ax,ds:[address+6]
          16# mov [si+6],ax;
          17# }
          18# return (*doublepointer);
          19# }

          If I save 123456789.123456789 in the memory, the data I got is 123456789.1234357.
          If I changed line 9 to:
          mov ax,ds:0x07FF0
          and the function works well.
          I don't know the reason. Thanks for your help.
    • 多年不用了. 把编译出错信息给出来看看.把你的变量地址打出来看看. 按丑小鸭给出的结构存取. 我的猜想:
      你的变量地址是32位, 而SI 是16位.
      • 一下为一个从地址为 0x7FF0 的 mem 中取出一个64位的double类型的数。请你看看
        1# double FetchDouble(void)
        2# /*this function to is to fetch a double data from mem(0x07ff0 -0x07ff7)*/
        3# {
        4# double *doublepointer;
        5# unsigned int address = 0x07FF0;
        6# _asm
        7# {
        8# mov si,doublepointer
        9# mov ax,ds:[address]
        10# mov [si],ax;
        11# mov ax,ds:[address+2]
        12# mov [si+2],ax;
        13# mov ax,ds:[address+4]
        14# mov [si+4],ax;
        15# mov ax,ds:[address+6]
        16# mov [si+6],ax;
        17# }
        18# return (*doublepointer);
        19# }

        If I save 123456789.123456789 in the memory, the data I got is 123456789.1234357.
        If I changed line 9 to:
        mov ax,ds:0x07FF0
        and the function works well.
        I don't know the reason. Thanks for your help.
        • 请进:
          原因不明, 但你的C语言里的指针没有初始化啊. 另外, 数据范围有没有超?试个小一点的?
      • 初始化以后,结果不变。问题是
        在两个不同的程序中, unsigned int address = 0x07FF0
        我用
        mov ax,ds:0x07FF0
        ..
        mov ax, ds:[address+2]
        就可以(结果正确)。而
        mov ax,ds:[address]
        ..
        mov ax, ds:[address+2]
        就不行!
        • 得, 麻爪了, 我的猜想:
          从你错误的结果看, 好象是浮点数超过表示范围以后,为了保持精度而进行的四舍五入. 我觉得其中的原因可能在于编译器, 你记得你上一个问题, 就是给它立即数就可以, 如果用LEA SI, 就不行. 编译器记住了或给了某些变量的类型, 并带到了汇编里.
          实在不知道原因, 只好瞎猜猜了. :P
          另外你用小一点的数据试了吗?结果如何?