Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

A simple task

I'm using Watcom C++ and I'm trying to speed up my programs by using inline assembler. I have a very simple task: I have two float-variables, and I want to copy a value like this:
var1=var2;
From one book I have I got an impresson that it should be done this way in assembler:
fld var2
fst var1
But then I get a runtime error "domain error in sqrt". It's a bit strange, since it has nothing to do with squareroots, but that's what happens. Is my code missing something essential?

Comments

  • davimedradedavimedrade Member Posts: 105
    Hi. I want to talk to Watcom Programmers, then, please, download MSN Messenger and add davimedrade@hotmail.com to your contact list.

    In assembly, your problem should be solved by this code:

    PUSH EAX
    MOV EAX,var1
    MOV var2,EAX
    POP EAX

    It should be enough for Integer 32bit variables. to use 16 bit vars, use AX instead of EAX, and to use 8 bit variables, use AL or AH. But I recommend you dont change the PUSHs and POPs.

    davimedrade@hotmail.com
    Davi Medrade
    Brazil.
  • AsmGuru62AsmGuru62 Member Posts: 6,519
    : Hi. I want to talk to Watcom Programmers, then, please, download MSN Messenger and add davimedrade@hotmail.com to your contact list.
    :
    : In assembly, your problem should be solved by this code:
    :
    : PUSH EAX
    : MOV EAX,var1
    : MOV var2,EAX
    : POP EAX
    :
    : It should be enough for Integer 32bit variables. to use 16 bit vars, use AX instead of EAX, and to use 8 bit variables, use AL or AH. But I recommend you dont change the PUSHs and POPs.
    :
    : davimedrade@hotmail.com
    : Davi Medrade
    : Brazil.
    :
    [blue]Davi,
    The question was about the [b][italic]float[/italic][/b] values, not integer. The [b][italic]float[/italic][/b] usually takes more than 32 bit.[/blue]
  • davimedradedavimedrade Member Posts: 105
    [b][red]This message was edited by davimedrade at 2003-8-26 6:49:41[/red][/b][hr]
    64-bit:

    PUSH ESI
    PUSH EDI
    LEA DI,Var2
    LEA SI,Var1
    CLD
    MOVSW ;Moves 16-bits
    MOVSW ;Moves more 16-bits
    POP EDI
    POP ESI

    Note: ES must have the segment of the destination variable.
    Note: DS must have the segment of the source variable.

    You can add more MOVSW instructions above, in order to move the complete variable. The formula is:
    numMOVSWs=(Numbits/16)
    You must have numMOVSWs instrunctions MOVSW.


    Davi Medrade
    Master Programmer of Agnetron Software Ltda.
    davimedrade@hotmail.com
    So Paulo, Brazil



  • blipblip Member Posts: 756
    [b][red]This message was edited by blip at 2003-9-1 8:43:38[/red][/b][hr]
    If it's 64-bit, should it not move two doublewords rather than two words?!
    [code]
    push ds
    push es
    push ax
    push si
    push di
    mov ax,seg Var1
    mov si,offset Var1
    mov ds,ax
    mov ax,seg Var2
    mov di,offset Var2
    mov es,ax
    cld
    movsd
    movsd
    pop di
    pop si
    pop ax
    pop es
    pop ds
    ret
    [/code]

    numMOVSWs=(Numbits/16)
    2 != 64 / 16

    numMOVSDs=(Numbits/32)
    2 = 64 / 32
  • davimedradedavimedrade Member Posts: 105
    Yes. How I explained in the code,the number of MOVSWs is calculated according to my "formula". I used MOVSWs because the formula then applies from 16-bit values to any number of bits (if divisible by 16). And the velocity added by the MOVSDs, which reduced 2 instructions, doesn't make a big difference, since today the processors are 2 GHz (and doesn't make a big difference in my Pentium 133 too).


    Davi Medrade
    Master Programmer of Agnetron Software Ltda.
    davimedrade@hotmail.com
    So Paulo, Brazil

  • blipblip Member Posts: 756
    I was pointing out an error in your code:
    [code]
    ;64-bit:

    PUSH ESI
    PUSH EDI
    LEA DI,Var2
    LEA SI,Var1
    CLD
    MOVSW ;Moves 16-bits
    MOVSW ;Moves more 16-bits
    POP EDI
    POP ESI
    [/code]
    Two MOVSWs copy only 32-bits, not 64.
  • davimedradedavimedrade Member Posts: 105
    : I was pointing out an error in your code:
    : [code]
    : ;64-bit:
    :
    : PUSH ESI
    : PUSH EDI
    : LEA DI,Var2
    : LEA SI,Var1
    : CLD
    : MOVSW ;Moves 16-bits
    : MOVSW ;Moves more 16-bits
    : POP EDI
    : POP ESI
    : [/code]
    : Two MOVSWs copy only 32-bits, not 64.
    :

    Yes, but I said that the number of MOVSWs is calculated according to my formula. Using 64 in my formula will result in 4. That is the number of MOVSWs you will need to use to move 64 bits. (16*4=64)

    Davi Medrade
    Master Programmer of Agnetron Software Ltda.
    davimedrade@hotmail.com
    So Paulo, Brazil

Sign In or Register to comment.