I'm trying to write a function (for a project) that copies one string into another. I pretty much know how I'm going set it up, the only problem comes in when I try to move the character from the source string to the destination string. Below is what I have so far (I removed everything that doesn't have to do with the problem):

.386
.MODEL FLAT, C
INCLUDE S:\PatProj\STR_IO.INC
INCLUDE S:\PatProj\NUM_IO.INC

.DATA

.CODE
PUBLIC copy_string
copy_string:
push ebp
mov ebp, esp

CSDest EQU DWORD PTR
CSSource EQU DWORD PTR
CSMaxLen EQU DWORD PTR

push ebx
push edi
push esi

mov ebx, 0 ; number moved
mov edi, CSDest
mov esi, CSSource
CSTopLoop:
mov al, BYTE PTR
; if the below line is commented out, the
; program will run fine, if it's not,
; I get an error that says that the instruction
; could not be written at a certain memory
; location.
; I know the above line works fine because
; I have several test to see if it was doing
; what it should be doing, but I
; have no idea why the below line does
; not work
mov BYTE PTR , al

CSLoopExit:
mov eax, ebx
pop esi
pop edi
pop ebx
pop ebp

ret
END

Any help would be great. I'm using VC++ 6.0. And here's what the
C prototype looks like:

unsigned long copy_string(char *dest_str, const char *src_str, unsigned long max_len);

and how it's called:

char *the_dest = "";
char *the_source = "heyman";
unsigned long the_len = 3;
unsigned long x;
x = copy_string(the_dest, the_source, the_len);

Also, I can't use anything fancy, I can only use basic stuff (which is why it's character by character string copying).

later
Posted on 2002-04-13 15:14:07 by PAT or JK
i think the problem is the_dest doesn't have any space allocated to it. try using "char the_dest[128];" or something instead.
Posted on 2002-04-13 15:36:39 by Sloat
Thanks,

later
Posted on 2002-04-14 15:36:11 by PAT or JK