Einzelnen Beitrag anzeigen

Basilikum

Registriert seit: 9. Aug 2003
389 Beiträge
 
Delphi 7 Professional
 
#4

Re: SetBit-Funktion verbessern?

  Alt 10. Jul 2004, 20:46
Zitat von negaH:
Delphi-Quellcode:
function BitSet(Value,BitIndex: LongWord; State: Boolean): LondWord;
asm
    shr ecx, 1
    btc eax, edx
end;

procedure BitSet(var Value: LongWord; BitIndex: LongWord; State: Boolean);
asm
    shr ecx, 1
    btc dword ptr [eax], edx
end;
dies setzt jedoch voraus, dass das betroffene Bit nicht bereits 1 war...
Zitat von intel 8086 Family Architecture:
The destination bit indexed by the source value is copied into the Carry Flag after being complimented (inverted).
also ist doch ein Compare notwendig:

Delphi-Quellcode:
Function BitSet(Const Value : LongWord;Const Bit : Byte;Const State : Boolean) : LongWord;
Asm
  OR CL,CL
  JNZ @@True

  BTR EAX,EDX
  RET

@@True:
  BTS EAX,EDX
end;
  Mit Zitat antworten Zitat