News:

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

copy letter from string

Started by vivendi, October 19, 2006, 05:24:40 PM

Previous topic - Next topic

vivendi

Hey, suppose i have a string stored in eax; "hello", how can i copy the first letter to another register like ebx??
And also the second, third and fourth offcourse.

dsouza123

If the whole string was in eax if would be 3 characters and a zero byte  "hel",0
then it could be transfered easily,

mov ebx, eax

al would have 0
ah would have l

more likely it is "hello",0 with eax holding the starting address of the string
and ebx the starting address of the destination string buffer.

mov cl, byte ptr [eax]
mov byte ptr [ecx], cl

mov cl, byte ptr [eax+1]
mov byte ptr [ecx+1], cl

mov cl, byte ptr [eax+2]
mov byte ptr [ecx+2], cl

mov cl, byte ptr [eax+3]
mov byte ptr [ecx+3], cl

mov cl, byte ptr [eax+4]
mov byte ptr [ecx+4], cl

mov cl, byte ptr [eax+5]
mov byte ptr [ecx+5], cl

OR

mov ecx, [eax]
mov [ebx], ecx

mov cx, word ptr [eax+4]
mov word ptr[ecx+4], cx

vivendi

Thank you, i prefer to try the last one first :)
Its indeed a string like "hello",0
I was just wondering, why do you mov it in ecx first, and why is eax between [] ??
Then after that ebx is between [] and then you move ecx into ebx. Why not into ebx right away?
Then you suddenly use cx, why not ecx? Or is it the same??
Sorry, but im still fairly new to this so i hope you can explain me my questions.
Thanks for you help anyway.

AssemblyBeginner

hi vivendi,
             
            suppose bl contains 10h and at 10h address there is 01h

            mov al,bl          ;move 10h to al,in this al=10
            mov al[bl]        ;move whatever at 10h address into al, in this al=01h

    hope clears