mac007
mac007

Reputation: 123

Get string length from input buffer 8086

Assuming you've read some ascii text into a character buffer of length say, 255 . How can you retrieve the length of the ascii text stored in the buffer into a CX register? (EDITED)

Thanks

Upvotes: 1

Views: 6657

Answers (2)

user1953449
user1953449

Reputation:

; STRLEN
LEA SI,PARA
MOV CX,-1
DO:
    LODSB
    INC CX
    CMP AL,0
    JNE DO

Upvotes: 1

Jerry Coffin
Jerry Coffin

Reputation: 490118

Search for the '$' using rep scasb, then subtract to get the distance from the beginning of the string.

; warning: untested code.
mov di, offset buffer
mov al, '$'
mov cx, 255
repnz scasb
sub di, offset buffer
mov cx, di

Upvotes: 2

Related Questions