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.
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:
Sounded like HOMEWORK didn't it???? :naughty: :naughty: :naughty: