News:

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

Calculation

Started by gamer, February 19, 2011, 07:43:34 AM

Previous topic - Next topic

gamer

Hi,

I have small issue.


eax hold the string address

EAX 00414235  "123456789"


Now i want to copy only first 5 bytes to edx, i know about moving strings,, but how to split this one??

dedndave

you can't fit 5 bytes into EDX - a dword register can hold 4, though

i assume what you really want is a pointer to a string in EDX
as usual, there are a few ways to do it
the "best" way depends on what you want it for - lol
if you want a temporary string - or if you do not need the full string later on, you can modify the existing string

here is an example of a temp modification
        .DATA
MyString db '123456789',0

        .CODE

;string pointer in EDX

        mov     edx,offset MyString

;temporarily modify the string

        push    [edx+4]
        mov byte ptr [edx+5],0

;display it

        push    edx
        print   edx
        pop     edx

;restore the original string

        pop     [edx+4]

you could also make a temporary copy of the first 5 bytes on the stack
of course - if you want permanent instances of both strings, you would want to make a copy
as i said - a lot depends on how you are using it
if you want to do this once in the program - if you want to do it several times - if the length is always 5 - or some variable length
all these questions determine the best approach

gamer