Hi, I'm very unexperienced with the use of strings in ASM. I try to convert this C code to ASM:
void AddLetter(char letter)
{
char myString[2];
if (strlen(text) < MAX_TEXT_LENGTH)
{
myString[0] = letter;
myString[1] = '\0';
strcat(text, myString);
}
}
the variables text and constant MAX_TEXT_LENGTH are global. text is just another array of char
Any help on the making of this function into ASM?
void AddLetter(char letter)
{
char myString[2];
if (strlen(text) < MAX_TEXT_LENGTH)
{
myString[0] = letter;
myString[1] = '\0';
strcat(text, myString);
}
}
the variables text and constant MAX_TEXT_LENGTH are global. text is just another array of char
Any help on the making of this function into ASM?
It is easy, you should really try a bit, it would be a enrichissing experience : you can always help you by compiling the program and disassemble it, or generating an assembly listing using the compiler (VC++ is able to do that).
Btw you don't need myString nor the strcat for such a function. Readiosys is right, give it a try and post your attempt here, you'll learn from it.
Thomas
Thomas
This is silly. :tongue:
Posted on 2002-05-28 14:19:32 by bitRAKE
Posted on 2002-05-28 14:19:32 by bitRAKE
after the reading of the working with strings in the help file, this is what I have created:
AddLetter proc letter :BYTE
mov ecx, text
FindTerminator:
mov al,
cmp al, 0
je addletter
inc ecx
jmp FindTerminator
addletter:
mov , letter
inc ecx
mov , 0
ret
AddLetter endp
but it does not compile. this is the best tha I could do
AddLetter proc letter :BYTE
mov ecx, text
FindTerminator:
mov al,
cmp al, 0
je addletter
inc ecx
jmp FindTerminator
addletter:
mov , letter
inc ecx
mov , 0
ret
AddLetter endp
but it does not compile. this is the best tha I could do
Needless jmp.
Reorgonize it:
Reorgonize it:
mov ecx,text ;pointer
@@:
mov al,[ecx]
inc ecx
test al,al
jne @B
mov [ecx-1],letter
mov [ecx],al
It helps to show the line with the error, and what error message you get:
mov , 0
MASM doesn't know what size to store, byte, word, or dword. You must tell it:
mov byte ptr , 0
mov , 0
MASM doesn't know what size to store, byte, word, or dword. You must tell it:
mov byte ptr , 0