|
-
Nov 13th, 2000, 05:53 PM
#1
Could someone post the code to input a string and compare it to another string?
-
Nov 24th, 2000, 05:36 PM
#2
New Member
A procedure to input a string :
Code:
LireChaine PROC NEAR
;=====================================================;
; Cette procédure lit AL caractères dans DS : DX, ;
; elle renvoie dans AL le nombre de caractères lus ;
; ;
; Paramètres d'entrée : AL, DS, DX ;
; Paramètres de sortie: AL, DS, DX ;
; Registres détruits : AH ;
; Autres procédures : aucune ;
;=====================================================;
PUSH BX ;sauve BX car il est modifié
PUSH CX
MOV BX, DX ;BX va servir de registre de base
;pour adresser le premier octet
;du buffer
PUSH BX
MOV [BX], AL ;nombre de caractères maximum à lire
;placé dans le premier octet du buffer
MOV AX, 0A00H ;service 0AH
INT 21H ;interruption 21H
MOV AL, [BX+1] ;nombre de caractères réellement lus
POP CX
MOV [BX], CH
;restore le premier byte du buffer à sa valeur d'origine
POP CX ;récupère CX, BX
POP BX
RET ;retour au programme appelant
LireChaine ENDP
sorry for the french comments
Nicolas Joannidès
ASM, C, VB6
[email protected]
-
Jun 27th, 2003, 01:05 PM
#3
Fanatic Member
Routine: IsEqual
Code:
;-----------------------------------------------------------------------------
; IsEqual
; Checks to see if two strings are equal
; PRECONDITION:
; * SI contains the source string
; * DI contains the destination string
; POSTCONDITION:
; * Equal if zero flag is equal / zero, else unequal
;-----------------------------------------------------------------------------
IsEqual:
PUSH ECX
PUSH SI
PUSH DI
CALL Strlen
REPE CMPSB
POP DI
POP SI
POP ECX
RET
And to find the length of a string.
Code:
;-----------------------------------------------------------------------------
; Strlen
; Finds the length of a '$' terminated string
; PRECONDITION:
; * SI contains the string
; POSTCONDITION:
; * ECX contains length of string
; NOTE: "Cleaned" space is filled with '$'
;-----------------------------------------------------------------------------
Strlen:
PUSH SI ; Good practice to not affect the
; user's registers
MOV ECX, 0h ; Initialize the ECX register
DEC SI
LengthLoop:
INC ECX ; Increment count
INC SI ; Goto next position
CMP byte [SI], '$' ; Is it a terminating character
JNZ LengthLoop ; No. Therefore, loop again
POP SI ; Undo PUSH
RET
Hope these help.
Last edited by Darkwraith; Jun 27th, 2003 at 01:10 PM.
"Can't" and "shouldn't" are two totally separate things.
All questions should be answered. All answers should be true. That is why I post.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|