Buffer1 db "11"
Buffer2 db "22"

All of this is usually in my .data? buffers actually...

Can you mov buffer1 to EAX than add buffer2 to EAX so that EAX will show 1122 in the message box.

I usually use Szcatstr but these are very small stings never over 4 BYTE. And Szcatstr is a lot of code for such a small operation...

Any idea would be appreciated.

Thanks
Posted on 2002-06-09 01:05:21 by cmax
Yep, just mov eax, OFFSET Buffer1 it will read past buffer1 into buffer2, assuming buffer2 is next to buffer1 - order matters on the data/data? segment.

P.S. You don't even need a null terminator - Isn't a good practice though. You might end up by some weird characters.

Example:



.DATA
buffer1 db "11"
buffer2 db "22" ; will print 1122
.CODE

...

.DATA
buffer1 db "11"
buffer2 db "22" ; will print 1122
var dd 1000

....

.DATA
buffer1 db "11"
buffer2 db "22"
three db "3" ;will print 11223
var dd 1000

....

.DATA
buffer1 db "11"
buffer2 db "22"
three db 3 ;will print 1122| (| is the odd character)
var dd 1000
It's better to terminate buffer2 with a NULL char. - just to be safe. :)
Posted on 2002-06-09 01:44:18 by stryker
------------------------------------------------------------------------------------
.data
buffer1 db "11",0
buffer2 db "22",0
buffer3 db 100 dup(0)
.
.
.

.code
.
.
.
invoke lstrcat,addr buffer3,addr buffer1
invoke lstrcat,addr buffer3,addr buffer2
invoke MessageBox,0,addr buffer3,0,MB_OK
.
.
.
------------------------------------------------------------------------------------

This will work fine ....
Posted on 2002-06-09 01:47:42 by Gandalf
I use this:



[...]
lea esi, szCurrentDBBuffer ; esi points to a buffer
[...]
.elseif byte ptr [nDB] == 2
mov dword ptr [esi], "iaMz"
mov dword ptr [esi + 4], "uO_l"
mov dword ptr [esi + 8], "xobt"
mov dword ptr [esi + 12], "txt."
[...]
Posted on 2002-06-09 04:36:04 by bazik
Thanks guys

These are some good idea to get me going... Thanks anyway Gandalf but i am trying not to use any api functions for this small operation *only 2 numbers per string* and i need the shortest way around it. lstrcat is something like what you find in M32.lib which is much faster.

If there are any others ideas please post.

Thank you
Posted on 2002-06-09 05:30:07 by cmax
If your buffers *always* contain 2 numbers each, you could use this:


.data
buffer1 db "12"
buffer2 db "34"

.data?
buffer3 db 4 dup (?)

.code
mov ax, word ptr [buffer2] ; eax = '__43'
shl eax, 16 ; eax = '43__'
mov ax, word ptr [buffer1] ; eax = '4321'
mov [buffer3], eax ; buffer: '1234'


If the buffers are next to each other, like in the example above, a simple dword copy would do too (mov eax, dword ptr / mov dword ptr , eax).

Thomas
Posted on 2002-06-09 05:40:32 by Thomas
I have been working with Mr. Thomas code because the numbers are 0 terminated. I have also been trying to do it with single numbers and i can't figure out how to make it work. I thought changing the word to BYTE and can't get it to work. I tried hard for the past few days but had not success.

buffer1 db "12"
buffer2 db "3"
.data? buffer3 db 4 dup (?)

.code
mov ax, WORD PTR
shl eax, 16
mov ax, BYTE PTR
mov , eax ::::::::::::::::::: Should = 123 but it don't work

Could you tell me the right way to do this.

Thanks again in advance

bAZiK, Posted on 2002-06-12 12:16:38 by cmax
buffer1 db "12"
buffer2 db "3"
.data? buffer3 db 4 dup (?)

.code
mov ax, WORD PTR
shl eax, 16
mov ax, BYTE PTR
mov , eax ::::::::::::::::::: Should = 123 but it don't work


Couple of things here:

1) mov ax, WORD PTR ~ This will place in ax = "?3" cause Buffer2 is only 1 byte long, and your asking for 2. As well its reversed cause of little endian operations in memory.

2) You shift it to be EAX = "?3??"

3) You ask for a byte, and you place it into a WORD?? Im surprised it will compile here, but my best guess is EAX = "?321" cause of little endian ordering again. (( if it will work )).

4) Lastly you write out to buffer3, which will write in memory "1","2","3","?".

So, even tho, as i see it you got it ordered 123, I dont see a NULL character ending the string (ie. ? != NULL), and i see some crazy mov to a WORD a BYTE amount of Info.. This may be you problem as well. I have not clue if this will even compile, but if it does, im assuming it will ignore the BYTE part and get a word amount for the AX register...

My version:


xor eax, eax
mov ah, [buffer2]
shl eax, 8
mov ax, [buffer1]
mov [buffer3], eax


EAX = "0000"
EAX = "0030"
EAX = "030?"
EAX = "0321"
Buffer3 = "1","2","3","\0"


Enjoy..
NaN
Posted on 2002-06-12 12:39:45 by NaN
I just tried bAZiK and it worked PERFECT. From what i see if anyone ever have a problem with this they will find the best 4 ways of completing this operation all right here... and we got NaN version that don't call ptr directly to boot Posted on 2002-06-12 12:52:55 by cmax