![]() |
Fließkomma-Rückgabewert über Assembler
Hi!
Ich habe eine kleine DLL geschrieben mit diversen Rechenoperationen. Diese werden dann vom eigentlichen Programm aufgerufen, was über Assembler erfolgt. Die Übergabe der Parameter und der Aufruf der Funktion klappt soweit über Assembler, jedoch hab ich bei Fileßkommazahlen Probleme den Rückgabewert zu ermitteln. Wenn ich als Rückgabewert Integer habe, so finde ich das Ergebnis im EAX-Register, bzw. bei Int64 noch zusätzlich im EDX, soweit kein Problem. Bei Single und Double bekomme ich allerdings absurde Werte wie $16 oder $3 ins EAX-Register reingeschrieben, also fallen diese auch als Zeiger auf Fließkommawerte weg.
Delphi-Quellcode:
Weiß einer ne Lösung? ^^ Oder hat einer Verbesserungsvorschläge?
//Beispielfunktionen aus der DLL:
function add_2i64(a, b: Int64): Int64; stdcall; // Parameterübergabe klappt, Rückgabe klappt begin Result:=a+b; end; function add_2f(a, b: Single): Single; stdcall; // Parameterübergabe klappt, Rückgabe schlägt fehl begin Result:=a+b; end; //Aufruf der Funktion(Ausschnitt) { p, prc: Pointer; x, n: Integer; Rslt: array[0..1]of Cardinal; Result --> Pointer } n:=Params.Count-1; //Parameterübergabe if(n>-1)then begin x:=n; repeat p:=Params[x]; asm PUSH p end; Dec(x); until(x=-1); end; n:=Params.Count*4; asm CALL prc //Aufruf der Funktion ADD ESP, n //Säubern des Stacks MOV DWORD PTR [Rslt], EAX //Kopieren des EAX-Registers end; Result:=@Rslt; |
Re: Fließkomma-Rückgabewert über Assembler
Zitat:
|
Re: Fließkomma-Rückgabewert über Assembler
Zitat:
|
Re: Fließkomma-Rückgabewert über Assembler
Zitat:
für single fstp dword ptr [Rslt] für double fstp qword ptr [Rslt] für extended fstp tbyte ptr [Rslt] aus Intels instruction set reference : FST m32fp Copy ST(0) to m32fp FST m64fp Copy ST(0) to m64fp FST ST(i) Copy ST(0) to ST(i) FSTP m32fp Copy ST(0) to m32fp and pop register stack FSTP m64fp Copy ST(0) to m64fp and pop register stack FSTP m80fp Copy ST(0) to m80fp and pop register stack FSTP ST(i) Copy ST(0) to ST(i) and pop register stack Description The FST instruction copies the value in the ST(0) register to the destination operand, which can be a memory location or another register in the FPU register stack. When storing the value in memory, the value is converted to single-precision or double-precision floating-point format. The FSTP instruction performs the same operation as the FST instruction and then pops the register stack. To pop the register stack, the processor marks the ST(0) register as empty and increments the stack pointer (TOP) by 1. The FSTP instruction can also store values in memory in double extended-precision floating-point format. If the destination operand is a memory location, the operand specifies the address where the first byte of the destination value is to be stored. If the destination operand is a register, the operand specifies a register in the register stack relative to the top of the stack. If the destination size is single-precision or double-precision, the significand of the value being stored is rounded to the width of the destination (according to rounding mode specified by the RC field of the FPU control word), and the exponent is converted to the width and bias of the destination format. If the value being stored is too large for the destination format, a numeric overflow exception (#O) is generated and, if the exception is unmasked, no value is stored in the destination operand. If the value being stored is a denormal value, the denormal exception (#D) is not generated. This condition is simply signaled as a numeric underflow exception (#U) condition. If the value being stored is ±0, ±∞, or a NaN, the least-significant bits of the significand and the exponent are truncated to fit the destination format. This operation preserves the value’s identity as a 0, ∞, or NaN. If the destination operand is a non-empty register, the invalid-operation exception is not generated. |
Re: Fließkomma-Rückgabewert über Assembler
Danke, läuft richtig geschmeidig :-D .
|
Alle Zeitangaben in WEZ +1. Es ist jetzt 01:12 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz