News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

getting index of entered character

Started by fusspot, August 14, 2007, 01:18:38 PM

Previous topic - Next topic

fusspot

Hi! I'm so new to assembly language programming and I'm just lost.  :dazzled:
I have an array of characters and my program asks the user to enter a character. How do I get the index (in the array) of the entered character?
For example, my array is "abcde" and the user enters 'c' (which is index 2). How do I obtain the index of 'c' in "abcde"?
Thanks.


ramguru

You should first learn concepts of programming before entering dangerous asm zone  :lol
;So the string is just array of bytes, first you get a pointer to string's starting location
mov esi, OFFSET str
;Then declare register that will be your index
xor ecx, ecx
;Then you enter the loop
@funky_loop:
;Then you get a character from the array
mov al, BYTE PTR [esi]
;Then you compare it with your character
cmp al, 'c'
;If it corresponds... you jump @outta_funky_loop
jz  @outta_funky_loop
;Then you increase the index register
inc ecx
;Then you increase pointer
inc esi
;Then you check if it's the end of string
cmp al, 0
;If it's not the case you again jump to the beginning of the loop
jnz @funky_loop

@outta_funky_loop:

raymond

Sounded like HOMEWORK didn't it???? :naughty: :naughty: :naughty:
When you assume something, you risk being wrong half the time
http://www.ray.masmcode.com