Autor |
Beitrag |
ScorpionKing
Beiträge: 1150
Win XP
|
Verfasst: Di 05.04.05 19:56
Hi Leute,
ich habe folgendes Problem: Ich will eine Berechnung (extended, also mit komma) in Assembler rechnen.
Wie bekomme ich zum Beispiel 1/6*a+4/2 in einen Asm-Code?
MfG, ScorpionKing! Moderiert von Christian S.: Topic aus Off Topic verschoben am Di 05.04.2005 um 20:06
_________________ Aus dem Urlaub zurück!
|
|
BenBE
Beiträge: 8721
Erhaltene Danke: 191
Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
|
Verfasst: Di 05.04.05 20:13
ScorpionKing hat folgendes geschrieben: | Hi Leute,
ich habe folgendes Problem: Ich will eine Berechnung (extended, also mit komma) in Assembler rechnen.
Wie bekomme ich zum Beispiel 1/6*a+4/2 in einen Asm-Code?
MfG, ScorpionKing! |
Eigentlich ganz einfach:
1. Umwandeln in RPN-Schreibweise:
Aus 1/6*a+4/2 wird 1 6 / a * 4 2 / +
2. Vereinfachen:
Quelltext
3. Schreiben der FPU-Befehle:
Delphi-Quelltext 1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25:
| FILD WORD PTR [@@Data_Int2] FILD WORD PTR [@@Data_Int6] FLD TBYTE PTR [a] FDIVP FADDP
JMP @@SkipData
@@Data_Int6: DW 6 @@Data_Int2: DW 2
@@SkipData: |
* TBYTE PTR kann entfallen, wenn Speichervariablen genutzt werden, bei Registern gibt es die Speichergröße und somit den Typ an. Für das Laden von Integern verwendet man FILD.
** Laden von Integern oder anderen Konstanten geht am einfachsten über DWord-Preallocations im Code-Segment. Für die Werte 0, 1 und Pi gibt es die Befehle FLDZ, FLD1 und FLDPI (sowie noch weitere Konstanten, die man häufiger braucht).
*** Bei FDIV und FSUB ist ST0 immer Zielregister. und der erste Operand. Die Reverse-Operationen vertauschen die Quelloperanden:
FDIV ST(0), ST(i) ST(0) := ST(0) / ST(i)
FDIVR ST(0), ST(i) ST(0) := ST(i) / ST(0)
Das P hinter dem Befehl sagt nur, dass der Zweite Operand vom Floating Point Stack entfernt werden soll.
Die Kurzformen FDIVP und FDIVRP haben die Impliziten Argumente ST(0), ST(1).
That's it ^^
_________________ Anyone who is capable of being elected president should on no account be allowed to do the job.
Ich code EdgeMonkey - In dubio pro Setting.
|
|
tommie-lie
Beiträge: 4373
Ubuntu 7.10 "Gutsy Gibbon"
|
Verfasst: Di 05.04.05 20:27
_________________ Your computer is designed to become slower and more unreliable over time, so you have to upgrade. But if you'd like some false hope, I can tell you how to defragment your disk. - Dilbert
|
|
ScorpionKing
Beiträge: 1150
Win XP
|
Verfasst: Di 05.04.05 20:27
und wie sieht das in delphi aus?
_________________ Aus dem Urlaub zurück!
|
|
tommie-lie
Beiträge: 4373
Ubuntu 7.10 "Gutsy Gibbon"
|
Verfasst: Di 05.04.05 20:29
_________________ Your computer is designed to become slower and more unreliable over time, so you have to upgrade. But if you'd like some false hope, I can tell you how to defragment your disk. - Dilbert
|
|
BenBE
Beiträge: 8721
Erhaltene Danke: 191
Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
|
Verfasst: Di 05.04.05 21:05
_________________ Anyone who is capable of being elected president should on no account be allowed to do the job.
Ich code EdgeMonkey - In dubio pro Setting.
|
|
tommie-lie
Beiträge: 4373
Ubuntu 7.10 "Gutsy Gibbon"
|
Verfasst: Di 05.04.05 21:21
_________________ Your computer is designed to become slower and more unreliable over time, so you have to upgrade. But if you'd like some false hope, I can tell you how to defragment your disk. - Dilbert
Zuletzt bearbeitet von tommie-lie am Di 05.04.05 21:23, insgesamt 1-mal bearbeitet
|
|
Moritz M.
Beiträge: 1672
|
Verfasst: Di 05.04.05 21:22
Nochmal kurze Frage an BenBE (Wohl die gleiche wie tommie-lie)
Wenn ich 1/6*a+4/2 vereinfache, komm ich auf a/6 + 2
In RPN wäre das doch a 6 / 2 +, oder?
Wie kommst du auf 2 6 a / +?
|
|
tommie-lie
Beiträge: 4373
Ubuntu 7.10 "Gutsy Gibbon"
|
Verfasst: Di 05.04.05 21:32
Moritz M. hat folgendes geschrieben: | In RPN wäre das doch a 6 / 2 +, oder? |
Unvereinfacht ja.
Moritz M. hat folgendes geschrieben: | Wie kommst du auf 2 6 a / +? |
Nein, das ist nicht meine Frage.
Vorrausgesetzt Bens Term stimmt, wäre 6 a / 2 + umgestellt (nicht vereinfacht im Sinne, daß es einfacher ist ) 2 6 a / +. Siehe Bens Anhängsel:
BenBE hat folgendes geschrieben: | Wenn man aber die Ausgangsgleichung noch etwas vereinfacht, kann man durch anwenden des Distributiv-Gesetzes die Argumente der Addition vertauschen und so alle Zahlen hintereinander bekommen:((2) (6 a) /) + |
Vorraussetzung natürlich, der Parser beachtet die Regel "Punkt- vor Strich-Rechnung" kann man dann die Klammern weg lassen und man erhält Bens Term:
Ich schiebe 2 auf den Stack. Ich schiebe 6 auf den Stack. Ich schiebe a auf den Stack. Ich dividiere die obersten beiden Elemente des Stacks (und hier liegt bei mir die Verwirrung, ich Teile 6/a, dabei ist 1/6*a aber a/6) und schiebe das Ergebnis wieder auf den Stack. Dann addiere ich die obersten beiden Elemente des Stacks (2 und das Ergebnis der Division). Fertig.
_________________ Your computer is designed to become slower and more unreliable over time, so you have to upgrade. But if you'd like some false hope, I can tell you how to defragment your disk. - Dilbert
|
|
delfiphan
Beiträge: 2684
Erhaltene Danke: 32
|
Verfasst: Di 05.04.05 22:09
Siehe mein Parser / Runtime Compiler für mathematische Ausdrücke. Der compiliert einen String mit einer Formel in eine asm-Funktion.
|
|
ScorpionKing
Beiträge: 1150
Win XP
|
Verfasst: Mi 06.04.05 12:34
ja, den schau ich mir mal an! danke!
MfG, Scorpion!
_________________ Aus dem Urlaub zurück!
|
|
|