flat assembler
Message board for the users of flat assembler.
Index
> Macroinstructions > Fun with someone's strcat |
Author |
|
revolution 07 Nov 2010, 13:11
Your use of ax instead of al is fine.
But your use of ecx as a counter for rep movsw should be counting elements, not bytes. In your third code section you are not reading the string when trying to find the length, you only increment di (should be edi) until it reaches zero. |
|||
07 Nov 2010, 13:11 |
|
Fred 07 Nov 2010, 15:10
Quote: But your use of ecx as a counter for rep movsw should be counting elements, not bytes. Could you explain it a little more in-depth? That's how the initial code was, except using edx. Quote: In your third code section you are not reading the string when trying to find the length, you only increment di (should be edi) until it reaches zero. Yes, you're right - it actually doesn't work. Bah... I'm sure I tested it yesterday... that's one downside with doing it at 04:30, I guess. Thanks for pointing out the errors, I'll try to fix it. |
|||
07 Nov 2010, 15:10 |
|
revolution 07 Nov 2010, 15:29
Code: mov ecx,1 rep movsd ;move 4 bytes, one dword element mov ecx,1 rep movsw ;move 2 bytes, one word element mov ecx,1 rep movsb ;move 1 byte, one byte element |
|||
07 Nov 2010, 15:29 |
|
Fred 07 Nov 2010, 16:59
Yes, that makes sense.
Code: macro strcatW dest,src{ local .get_str_len mov edi,dest mov esi,src mov ecx,-1 .get_str_len: mov eax,[edi] inc edi inc ecx test ax,ax jne .get_str_len rep movsw} This seems to work, but I can see that I don't understand it fully yet. Moving the data to eax works... for now, at least. But something else is that I can put some random values into ecx and it will still work. Why's that? |
|||
07 Nov 2010, 16:59 |
|
revolution 07 Nov 2010, 20:59
Try this:
Code: macro strcatW dest,src{ local .get_str_len mov edi,dest mov esi,src mov ecx,-1 + 1 ;we need one more byte to copy the zero terminator also .get_str_len: mov ax,[esi] ;word values only add esi,2 ;we read two bytes inc ecx ;add one element test ax,ax jne .get_str_len mov esi,src ;recover start address .find_dest_pointer: mov ax,[edi] ;word values only add edi,2 ;we read two bytes test ax,ax jne .find_dest_pointer sub edi,2 rep movsw} |
|||
07 Nov 2010, 20:59 |
|
Fred 07 Nov 2010, 22:32
Yeah, I looked through my code a little more in-depth today and saw what I tried to do and what I really did. I guess that means that I learned something. (POWER UP)
Thanks for the code snippets and explanations. |
|||
07 Nov 2010, 22:32 |
|
rugxulo 08 Nov 2010, 16:59
revolution wrote:
Wait, what??? Just do this: Code: movsd ; move 4 bytes movsw ; move 2 bytes movsb ; move 1 byte |
|||
08 Nov 2010, 16:59 |
|
shoorick 09 Nov 2010, 06:41
another example:
Code: macro _strcat dest,sour { mov edi,dest mov esi,sour mov ecx,-1 xor eax,eax repne scasw ; searching zero word in first string sub edi,2 ; restore pointer to the zero at the and of the first string .m: cmp word [esi],0 ; copy word by word same time comparing words with zero movsw jne .m ; to know when to stop } |
|||
09 Nov 2010, 06:41 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.