flat assembler
Message board for the users of flat assembler.
![]() |
Author |
|
revolution
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. |
|||
![]() |
|
Fred
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. ![]() |
|||
![]() |
|
revolution
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 |
|||
![]() |
|
Fred
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? |
|||
![]() |
|
revolution
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} |
|||
![]() |
|
Fred
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. |
|||
![]() |
|
rugxulo
revolution wrote:
Wait, what??? Just do this: Code: movsd ; move 4 bytes movsw ; move 2 bytes movsb ; move 1 byte ![]() |
|||
![]() |
|
shoorick
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 } |
|||
![]() |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.
Website powered by rwasa.