Howdy, Stranger!

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

Categories

square root assembly and c++

Hi
I'm new in assembly and was trying to get this program to work, it is supposed to calculate the square root of any integer but i don't know how to load the ax into the stack, get the square root and return the value to the c++ variable, that was the closest i could come up with and it doesn't work, it's really killing me this cuz i've looked absolutly everywhere and can't find the answer. the compiler i use is Borland C++ 3.1 and for some reason it doesn't accept assembly variables
plz help

void squareroot(int intA, float Result)
{
asm{
finit
mov ax,intA
fld ax
fsqrt //Compute sqrt(intA).
fstsw ax
mov Result,ax


}
cout<<"Square root of: "<<intA<<"="<<Result;
getch();
asm{
JMP End
}
End:

Comments

  • BellerofontBellerofont Member Posts: 2
    hi again

    i've found the way of doing it all by myself :D soz for bothering everyone the code looks like that

    void square_root(int intA, float Result)
    {

    asm {



    fild intA
    fsqrt
    fst Result

    jmp End
    }
    End:
    cout<<Result;
    getch();
    }
  • AsmGuru62AsmGuru62 Member Posts: 6,519
    : hi again
    :
    : i've found the way of doing it all by myself :D soz for bothering
    : everyone the code looks like that
    :
    : void square_root(int intA, float Result)
    : {
    :
    : asm {
    :
    :
    :
    : fild intA
    : fsqrt
    : fst Result
    :
    : jmp End
    : }
    : End:
    : cout<<Result;
    : getch();
    : }
    :
    [color=Blue]That "float Result" will not return any values to the caller, because it is not a pointer or reference.[/color]
  • anthrax11anthrax11 Member Posts: 511
    : [color=Blue]That "float Result" will not return any values to the
    : caller, because it is not a pointer or reference.[/color]

    [color=Green]I think the idea was to print out the number, not return it, hence the void return type. Or do you mean something else?[/color]
Sign In or Register to comment.