Evening.
I need to exchange two buffers, or at least I think I do. How do I do this? I have found an exchange macro whilst searching to board, but it doesn't do the trick, and to be honest I don't understand it.
Help/explanation appreciated!
Thanks
Posted on 2003-12-27 15:54:15 by adamjjackson
the hard way

make a temporary buffer equal the size of the biggest buffer
copy the content of the biggest buffer to it
copy the content of the small buffer to the biggest buffer (may need to create a totally new buffer with regards to size handling)
copy the content of the large buffer to the smaller buffer after you resized it to fit the new size
free the temp buffer

or....


just copy their pointers :grin: (that only requires 1 temporary DWORD)
Posted on 2003-12-27 16:30:28 by Hiroshimator
Depending on your requirements, one way is to use the stack (or any spare register) as an intermediary.

Assuming for a moment that esi points to the start of one buffer and edi points to the start of the other, and ecx is loaded with the size of the buffer to be exchanged, you COULD do this:

.while ecx != 0
push dword ptr
push dword ptr
pop dword ptr
pop dword ptr
add esi,4
add edi,4
sub ecx,4
.endw

That's ugly and not exactly optimal, but it works.
I'm curious WHY you need to exchange the contents of two buffers, if the buffers were allocated dynamically (are not defined in a .data segment) why not just exchange the POINTERS to the buffers?

Have a nice day :)
Posted on 2003-12-27 16:36:33 by Homer
Ok. I've got a load of numbers stored in a text file. I want to find the largest number. So, I thought that I would have two buffers. Move the first two strings to those buffers.
Convert one digit at a time (most significant first obv), and compare them.

I want to return the largest number in buffer1. So if the bigger number happens to be in buffer 2, i need to move it into buffer1.

Then I repeat this with the next number, until I run out.
I'll have a look at that in a minute, thanks...
Posted on 2003-12-27 16:44:05 by adamjjackson
does that mean that 5e+46 < 500000000? :grin:
Posted on 2003-12-27 16:51:18 by Hiroshimator
Errr, bit confused!
Posted on 2003-12-27 16:55:12 by adamjjackson
If you start comparing with the most significant digits, is 5 > 400 ?

So why do you need to exchange (swap) buffers ?
All you describe is a copy (or move) operation.
Posted on 2003-12-27 17:10:33 by tenkey
Ah, I understand now. But it's okay in this case. All the numbers are the same length, they're dates and times eg now:
200312272313
yyyymmddhhmm. So they can be compared like that!


The proc returns the string of the highest number in a buffer. If that string happens to be loaded into a buffer other than my output one for the purpose of the comparison it will need to be moved to the output buffer...
Posted on 2003-12-27 17:14:35 by adamjjackson


@@:
mov eax, [esi+ecx]
xchg eax, [edi+ecx]
mov [esi+ecx], eax
sub ecx,4
jnz @B
_done:
Posted on 2003-12-27 23:28:40 by roticv
Adam,

It seems you are doing a lot more than you need to find which number is the highest. If you can parse the text file so that you present one number at a time, just write the first one to a buffer then if the next one is bigger write it to the buffer but if its not, don't.

Just scan the entire file and the buffer will end up with the largest number.

Regards,
http://www.asmcommunity.net/board/cryptmail.php?tauntspiders=in.your.face@nomail.for.you&id=2f46ed9f24413347f14439b64bdc03fd
Posted on 2003-12-28 07:19:22 by hutch--
Thanks, that's pretty much what I'm doing :)
All sorted now anyway, at least I learnt some things!
Cheers
Posted on 2003-12-28 15:38:31 by adamjjackson