PDA

Click to See Complete Forum and Search --> : Input a string


Nov 13th, 2000, 05:53 PM
Could someone post the code to input a string and compare it to another string?

Njoannides
Nov 24th, 2000, 05:36 PM
A procedure to input a string :


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
njoannides@netcourrier.com

Darkwraith
Jun 27th, 2003, 02:05 PM
Routine: IsEqual


;-----------------------------------------------------------------------------
; 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.


;-----------------------------------------------------------------------------
; 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. :)