EntropySink
Technical & Scientific => Programming => Topic started by: ahluka on August 19, 2005, 05:32:42 AM
-
Well now I know which syscall is equivalent to C's system() function, I've hit another little snag. How in the name of Mary Moe do you concatenate strings in assembly? Would I be right in assuming you copy the base string into memory then calculate the end of it, appending the other string?
I'm going to read about the string operations in asm, but from what I remember they're just for storing / loading strings.
-
I suppose you could call strcat(), or use a simple for loop to copy the other contents onto the end of your string:
char* source;
char* dest;
while (*source++);
while (*source++ = *dest++);
or its equivalent in assembly. There are quite a few asm operations meant to string manipulation
-
Thank you, I get the idea now. I don't remember much about string ops, better look them up.
-
Remember that "string" in assembly is nothing more than a collection of characters. There are no real string operators as such, all you would do is move bytes to contigious memory locations to append one string to another.
Checkout MOVS, and STOS (Move string and Store string). MOVS moves the string element addressed by the (E)SI register to the location addressed by the (E)DI register one element at a time. Use REP / REPZ / REPNZ to repeat for all elements of a string.
edit>> Well, I guess there are string operators, but you get my drift.
-
org 100h
jmp start
string1 db 'Hello '
string2 db 'World'
string3 db 'XXXXXXXXXXX'
start:
cld
lea si, string1
lea di, string3
mov cx, 6
rep movsb
lea si, string2
mov cx, 5
rep movsb
end
would append World to Hello and put the result in string3 for example.
-
Yay my saviour :D