je suis entrain d'apprendre l'asm
et voilà mon très basic code qui sert à :
Retourne un pointeur vers la première occurrence d’une chaîne de recherche dans une chaîne.
Code : Tout sélectionner
;*****************************************************************************************************************************************************************************************
EnableASM
CompilerIf #PB_Compiler_Processor = #PB_Processor_x86
Macro asmarch:E:EndMacro
Macro pushsize(s):s:EndMacro
CompilerElse
Macro asmarch:R:EndMacro
Macro pushsize(s):s * 2:EndMacro
CompilerEndIf
Procedure StringInStr(Str1,Str2)
PUSH asmarch#dx ;Caractère unicode à comparer
PUSH asmarch#SI ;le compteur
MOV asmarch#ax,[p.v_Str1 + pushsize(8)] ;adresse vers Str1
MOV asmarch#cx,[p.v_Str2 + pushsize(8)] ;adresse vers Str2
!.__loop: ;entrer dans la boucle
CMP word [asmarch#ax],0 ;vérifier si c est la fin de texte "Str1"
JZ ._endloop ;quitter la boucle
MOV dx, word [asmarch#cx] ;copier le caractère actuel "word"
TEST dx,dx ;vérifier si c est la fin de texte "Str2"
JZ ._endloop ;quitter la boucle
CMP word [asmarch#ax],dx ;comparer les deux caractères
JZ ._NextWord ;sont identiques , continuer sur le caractère suivant
;Sinon
MOV asmarch#cx,[p.v_Str2 + pushsize(8)] ;Re-pointez sur le début du texte"Str2"
XOR asmarch#SI,asmarch#SI ;réinitialiser le compteur
MOV dx, word [asmarch#cx] ;Re-comparer les deux caractères
CMP word [asmarch#ax],dx
JZ ._NextWord
JMP ._SkiPNextWord
!._NextWord:
ADD asmarch#SI,2 ;ajouter "2 = Sizeof(Word)" a compteur
ADD asmarch#cx,2 ;avancer sur le caractère suivant sur "Str2"
!._SkiPNextWord:
ADD asmarch#ax,2 ;avancer sur le caractère suivant sur "Str1"
JMP .__loop ;rester en boucle
!._endloop: ;Fin Boucle
CMP word [asmarch#cx],0 ;fin de texte à chercher,donc tous les caractères sont présents sur str1.
JNZ ._No ;Sinon retourner 0
SUB asmarch#ax,asmarch#SI ;Retourner point vers la première occurrence
JMP ._ret
!._No:
XOR asmarch#ax,asmarch#ax
!._ret:
POP asmarch#SI
POP asmarch#dx
ProcedureReturn
EndProcedure
;version pb pour comprendre
Procedure PBStringInStr(Str1,Str2)
Protected edx
Protected esi
Protected eax = Str1
Protected ecx = Str2
Repeat
If PeekW(eax) = 0
Break
EndIf
edx = PeekW(ecx)
If edx = 0
Break
EndIf
If PeekW(eax) = edx
eax + 2
ecx + 2
esi + 2
Else
ecx = Str2
esi = 0
edx = PeekW(ecx)
If PeekW(eax) = edx
ecx + 2
esi + 2
EndIf
eax + 2
EndIf
ForEver
If PeekW(ecx) = 0
eax - esi
Else
eax = 0
EndIf
esi = 0
edx = 0
ProcedureReturn eax
EndProcedure
Debug StringInStr(@"abcd",@"d")