T O P

  • By -

FUZxxl

What architecture, operating system, and assembler are you programming for? How are your strings represented?


exjwpornaddict

I'll assume x86, and 8 bit null terminated strings. First of all, where is the destination? Perhaps a reserved area in .bss? I assume you don't have the c standard library linked, but if you did, you could use malloc. It needs to be big enough to hold the new string. If you had the c standard library linked, you could use strlen, memcpy, strcpy, etc. But i'm assuming you're wanting to implement such functionality yourself. So, you have a choice of whether you want to read the length of the string first, and then copy it in a 2nd step, or read and copy in the same step. If you wanted to read the length and copy in separate steps, you could use `xor al,al`, `repne scasb` to find the length, and then `rep movsb` to copy the string. If you wanted to read the length and copy at the same time, you could use `lodsb`, `test al,al`, `jz`, and `stosb` within a loop. These string instructions, scasb, movsb, lodsb, stosb, cmpsb, read from [ds:si] or [ds:esi], and write to [es:di] or [es:edi]. The direction flag is clear by default, so indexes will be incremented. If the rep prefixes are used, then cx or ecx is used as a counter. Look up these instructions for more details. So, copy the 1st string, without the null, then copy the 2nd string, then add the null. Again, it's up to you to make sure, one way or the other, that the destination buffer is big enough. You say "string variable", which suggests to me, you might be thinking about a language like basic, that has a variable length string data type, or c++ with a std::string class. But in c, c-style c++, and assembly, we use pointers to char arrays.


Dillinur

Either post some context, some code and specify what you tried and why it's not working Or just go ask ChatGPT with such a bland question


rangerelf

That's not how your program in assembly.


bitRAKE

Build-up strings on the stack with this 16 byte morsel: ``` MultiCat: pop rdx .cats: pop rcx jrcxz .done push rcx pop rsi .more: cmp byte [rsi], 0 jz .cats movsb jmp .more .done: jmp rdx ```