zatzen hat geschrieben:Na gut, weiss ich erstmal bescheid.
Nächste Frage wären Multiplikationen / Divisionen in DWORD Dimensionen.
Ich meine in nem anderen Thread wurde sowas schon angesprochen.
Aber trotzdem nochmal ein Beispiel:
Ich müsste in diesem Player sehr oft folgendes ausrechnen:
Notenfaktor * C3-Frequenz / Mixfrequenz.
Alle Werte können jeweils volle WORD-Größe sein.
Der Notenfaktor müsste eigentlich beim C-3 1 sein, aber
da ich mit Festkomma rechnen will mache ich ihn dort auf 1024.
Um es zu programmieren gibt es viele Möglichkeiten.
Am Ende sollte aber eigentlich immer versucht werden alles mit so wenig Speicherzugriffen wie möglich hinzubekommen.
Hat man noch Register frei die gerade nicht verwendet werden, dann sollte man dort ggf. Werte retten, anstelle den Wert in das RAM zu schreiben. Manchmal genügt es bei einer Routine die Benutzung der Register zu vertauschen, um wieder einen weiteren Speicherzugriff zu vermeiden und herauszunehmen. Je weniger Befehle wir für eine bestimmte Aufgabe benötigen, um so übersichtlicher wird unser Code und damit sinkt auch die Wahrscheinlichkeit das sich dort Fehler einschleichen. Am Anfang bei der Entwicklung einer Routine ist das aber nicht unbedingt so wichtig. Hierbei geht es schlicht nur darum es überhaupt einmal funktionstüchtig hin zu bekommen.
Nun brauchen wir noch ein paar Befehle für die Berechnungen.
Bei der vorzeichenlosen Division mit dem DIV-Befehl dürfen wir nicht vergessen, das DX, oder EDX zum Dividend bei einigen Varianten des Befehl mit dazu gehört.
http://courses.engr.illinois.edu/ece390 ... neral.html
B.4.134 SHL, SHR: Bitwise Logical Shifts
SHL r/m8,1 ; D0 /4 [8086]
SHL r/m8,CL ; D2 /4 [8086]
SHL r/m8,imm8 ; C0 /4 ib [186]
SHL r/m16,1 ; o16 D1 /4 [8086]
SHL r/m16,CL ; o16 D3 /4 [8086]
SHL r/m16,imm8 ; o16 C1 /4 ib [186]
SHL r/m32,1 ; o32 D1 /4 [386]
SHL r/m32,CL ; o32 D3 /4 [386]
SHL r/m32,imm8 ; o32 C1 /4 ib [386]
SHR r/m8,1 ; D0 /5 [8086]
SHR r/m8,CL ; D2 /5 [8086]
SHR r/m8,imm8 ; C0 /5 ib [186]
SHR r/m16,1 ; o16 D1 /5 [8086]
SHR r/m16,CL ; o16 D3 /5 [8086]
SHR r/m16,imm8 ; o16 C1 /5 ib [186]
SHR r/m32,1 ; o32 D1 /5 [386]
SHR r/m32,CL ; o32 D3 /5 [386]
SHR r/m32,imm8 ; o32 C1 /5 ib [386]
SHL and SHR perform a logical shift operation on the given source/destination (first) operand. The vacated bits are filled with zero.
A synonym for SHL is SAL (see Section B.4.127). NASM will assemble either one to the same code.
The number of bits to shift by is given by the second operand. Only the bottom five bits of the shift count are considered by processors above the 8086.
You can force the longer (286 and upwards, beginning with a C1 byte) form of SHL foo,1 by using a BYTE prefix: SHL foo,BYTE 1. Similarly with SHR.
B.4.105 MUL: Unsigned Integer Multiply
MUL r/m8 ; F6 /4 [8086]
MUL r/m16 ; o16 F7 /4 [8086]
MUL r/m32 ; o32 F7 /4 [386]
MUL performs unsigned integer multiplication. The other operand to the multiplication, and the destination operand, are implicit, in the following way:
* For MUL r/m8, AL is multiplied by the given operand; the product is stored in AX.
* For MUL r/m16, AX is multiplied by the given operand; the product is stored in DX:AX.
* For MUL r/m32, EAX is multiplied by the given operand; the product is stored in EDX:EAX.
B.4.76 IMUL: Signed Integer Multiply
IMUL r/m8 ; F6 /5 [8086]
IMUL r/m16 ; o16 F7 /5 [8086]
IMUL r/m32 ; o32 F7 /5 [386]
IMUL reg16,r/m16 ; o16 0F AF /r [386]
IMUL reg32,r/m32 ; o32 0F AF /r [386]
IMUL reg16,imm8 ; o16 6B /r ib [186]
IMUL reg16,imm16 ; o16 69 /r iw [186]
IMUL reg32,imm8 ; o32 6B /r ib [386]
IMUL reg32,imm32 ; o32 69 /r id [386]
IMUL reg16,r/m16,imm8 ; o16 6B /r ib [186]
IMUL reg16,r/m16,imm16 ; o16 69 /r iw [186]
IMUL reg32,r/m32,imm8 ; o32 6B /r ib [386]
IMUL reg32,r/m32,imm32 ; o32 69 /r id [386]
IMUL performs signed integer multiplication. For the single-operand form, the other operand and destination are implicit, in the following way:
* For IMUL r/m8, AL is multiplied by the given operand; the product is stored in AX.
* For IMUL r/m16, AX is multiplied by the given operand; the product is stored in DX:AX.
* For IMUL r/m32, EAX is multiplied by the given operand; the product is stored in EDX:EAX.
The two-operand form multiplies its two operands and stores the result in the destination (first) operand. The three-operand form multiplies its last two operands and stores the result in the first operand.
The two-operand form with an immediate second operand is in fact a shorthand for the three-operand form, as can be seen by examining the opcode descriptions: in the two-operand form, the code /r takes both its register and r/m parts from the same operand (the first one).
In the forms with an 8-bit immediate operand and another longer source operand, the immediate operand is considered to be signed, and is sign-extended to the length of the other source operand. In these cases, the BYTE qualifier is necessary to force NASM to generate this form of the instruction.
B.4.23 DIV: Unsigned Integer Divide
DIV r/m8 ; F6 /6 [8086]
DIV r/m16 ; o16 F7 /6 [8086]
DIV r/m32 ; o32 F7 /6 [386]
DIV performs unsigned integer division. The explicit operand provided is the divisor; the dividend and destination operands are implicit, in the following way:
* For DIV r/m8, AX is divided by the given operand; the quotient is stored in AL and the remainder in AH.
* For DIV r/m16, DX:AX is divided by the given operand; the quotient is stored in AX and the remainder in DX.
* For DIV r/m32, EDX:EAX is divided by the given operand; the quotient is stored in EAX and the remainder in EDX.
B.4.75 IDIV: Signed Integer Divide
IDIV r/m8 ; F6 /7 [8086]
IDIV r/m16 ; o16 F7 /7 [8086]
IDIV r/m32 ; o32 F7 /7 [386]
IDIV performs signed integer division. The explicit operand provided is the divisor; the dividend and destination operands are implicit, in the following way:
* For IDIV r/m8, AX is divided by the given operand; the quotient is stored in AL and the remainder in AH.
* For IDIV r/m16, DX:AX is divided by the given operand; the quotient is stored in AX and the remainder in DX.
* For IDIV r/m32, EDX:EAX is divided by the given operand; the quotient is stored in EAX and the remainder in EDX.
Dirk