begin process at 2012 02 08 07:00:09
  Trouver un code source :
 
dans
 
Accueil > 

Code

 > 

Delphi et asm

 > PETIT ÉQUIVALENT DU ?: DU C EN DELPHI POUR LES CHAINES, LONGINT & BOOLEAN

PETIT ÉQUIVALENT DU ?: DU C EN DELPHI POUR LES CHAINES, LONGINT & BOOLEAN


 Information sur la source

Note :
8 / 10 - par 1 personne
8,00 / 10

  • 1

  • 2

  • 3

  • 4

  • 5

  • 6

  • 7

  • 8

  • 9

  • 10
Catégorie :Delphi et asm Niveau :Débutant Date de création :03/09/2003 Date de mise à jour :03/09/2003 02:48:34 Vu :6 007

Auteur : cutmaster

Ecrire un message privé
Commentaire sur cette source (0)
Ajouter un commentaire et/ou une note

 Description

Ces fonctions renvoit une valeur ou l'autre (chaine, longint ou boolean) en fonction de la valeur TRUE/FALSE passée en paramètre.
En C, on ferait Reponse=(Value=1)?1:2;
ou avec des chaines Reponse=(Key="Y")?"YES":"NO";

En Delphi, ça donnera Reponse:=ChoixS(Key='S','YES','NO');

J'aurais pu utiliser des variants et ne faire qu'une seule fonction mais ce n'était pas le but ici. Si quelqu'un veut se lancer dans l'écriture...

Source

  • function ChoixS(PremierChoix:Boolean; Choix1,Choix2:ShortString):ShortString; Assembler;
  • Asm
  • // If PremierChoix then Result:=Choix1 else Result:=Choix2;
  • //=- original version was 34 asm lines and 2 external procs by Delphi compiler ;) now it's 14 lines -=
  • push esi
  • push edi
  • test al,al
  • jz @@NotTrue
  • mov esi,Choix1
  • jmp @@End
  • @@NotTrue:
  • mov esi,Choix2
  • @@End:
  • mov edi,@Result
  • xor ecx,ecx
  • mov cl,[esi]
  • inc cl
  • rep movsb
  • pop edi
  • pop esi
  • End;
  • function ChoixL(PremierChoix:Boolean; Choix1,Choix2:LongInt):LongInt; Assembler;
  • Asm
  • // If PremierChoix then Result:=Choix1 else Result:=Choix2;
  • test al,al
  • jz @@NotTrue
  • mov eax,edx // it's true so put the first parameter into the result
  • ret
  • @@NotTrue:
  • mov eax,ecx // it's false, put second parameter into result
  • End;
  • function ChoixB(PremierChoix:Boolean; Choix1,Choix2:Boolean):Boolean; Assembler;
  • Asm
  • // If PremierChoix then Result:=Choix1 else Result:=Choix2;
  • test al,al
  • jz @@NotTrue
  • mov eax,edx // it's true so put the first parameter into the result
  • ret
  • @@NotTrue:
  • mov eax,ecx // it's false, put second parameter into result
  • End;
function  ChoixS(PremierChoix:Boolean; Choix1,Choix2:ShortString):ShortString; Assembler;
Asm
    //  If PremierChoix then Result:=Choix1 else Result:=Choix2;
    //=- original version was 34 asm lines and 2 external procs by Delphi compiler ;) now it's 14 lines -=
    push   esi
    push   edi
    test   al,al
    jz     @@NotTrue
    mov    esi,Choix1
    jmp    @@End
  @@NotTrue:
    mov    esi,Choix2
  @@End:
    mov    edi,@Result
    xor    ecx,ecx
    mov    cl,[esi]
    inc    cl
    rep    movsb
    pop    edi
    pop    esi
End;

function  ChoixL(PremierChoix:Boolean; Choix1,Choix2:LongInt):LongInt; Assembler;
Asm
    //  If PremierChoix then Result:=Choix1 else Result:=Choix2;
    test   al,al
    jz     @@NotTrue
    mov    eax,edx       // it's true so put the first parameter into the result
    ret
  @@NotTrue:
    mov    eax,ecx       // it's false, put second parameter into result
End;

function  ChoixB(PremierChoix:Boolean; Choix1,Choix2:Boolean):Boolean; Assembler;
Asm
  //  If PremierChoix then Result:=Choix1 else Result:=Choix2;
    test   al,al
    jz     @@NotTrue
    mov    eax,edx       // it's true so put the first parameter into the result
    ret
  @@NotTrue:
    mov    eax,ecx       // it's false, put second parameter into result
End;



 Sources du même auteur

RENVOIT UNE CHAINE DE X FOIS LE CARACTÈRE DEMANDÉ
AVOIR LE NOM DU JOUR DE LA SEMAINE DÉSIGNÉ
REMPLISSAGE FORMATÉ D'UN SHORTSTRING

 Sources de la même categorie

Source avec Zip APPELER UNE API EN ASM AVEC DELPHI par DeadlyPredator
RENVOIT UNE CHAINE DE X FOIS LE CARACTÈRE DEMANDÉ par cutmaster
AVOIR LE NOM DU JOUR DE LA SEMAINE DÉSIGNÉ par cutmaster
REMPLISSAGE FORMATÉ D'UN SHORTSTRING par cutmaster
3 FONCTIONS GRAPHIQUES PLUS RAPIDES QUE LES FONCTIONS DE BAS... par balgrim

Commentaires et avis

Aucun commentaire pour le moment.

 Ajouter un commentaire




Nos sponsors


Sondage...

Comparez les prix

CalendriCode

Février 2012
LMMJVSD
  12345
6789101112
13141516171819
20212223242526
272829    

Consulter la suite du CalendriCode

Photothèque

 
Développement réalisé par Nicolas SOREL (Nix) avec l'aide de : Cyril DURAND et Emmanuel (EBArtSoft), Merci à Vincent pour ses précieux conseils.
CodeS-SourceS.com© Toute reproduction même partielle est interdite sauf accord écrit du Webmaster
CodeS-SourceS.com© est une marque déposée tous droits réservés

Google Coop CodeS-SourceS Google Coop CodeS-SourceS
Temps d'éxécution de la page : 0,437 sec (4)

Nous contacter | Annoncer sur CodeS-SourceS | Mentions légales