This should be doable but i don't know how...
Would anyone know how would i get all of the these numbers from Terminated strings.
The idea is to copy strings 1-5 into a separate buffer in One Chunk if possible ....
while at the same time or afterward replacing the zero byte with a dash, than terminate the new string. I tried a lot of things but could not make it work. I know i could use CatString but i want to learn how to do it as i described above in a difference way if possible. Not to go pass the letter A
x_1 db "1",0
x_2 db "2",0
x_3 db "3",0
x_4 db "4",0
x_5 db "5",0
c_A db "A",0
c_B db "B",0
c_C db "C",0
c_D db "D",0
c_E db "E",0
Output needed: 1-2-3-4-5
Thanks in advance.
Something like:
lea eax, X_1 ; load eax with address of your first buffer
cmp BYTE PTR eax, 'A' ; just in case first letter is A
jz end ; go past the loop if it is
@@:
add eax, 1 ; move to first null termination
mov BYTE PTR eax, '-' ; make it a hyphen
add eax, 1 ; move to next letter
cmp BYTE PTR eax, 'A' ; check it for a
jnz @b ; if it's not, move on to next buffer
end: ; do the rest of your stuff with your new buffer here
My syntax is quite possibly wrong, but this should give you the general idea, provided i understand what you're trying to do. You can use lea eax, X_1 again to get the start of your new buffer.
Ehtyar.
Thanks Ehtyar,
It works, but not the exactly the way i was think of. But it gave me even move food for thought :)...
I been wanting to know how to do this forever... I tried everything but asking :( ... Now I'm 9 steps closer :)...
invoke MessageBox,0,offset x_1,0,0
Results is:
1-2-3-4-5-A
The only real problem is that it over-write the Strings in memory, making them unuseable for other stuff because the zero terminator has been replaced.
That's why i wanted to copy all 5 strings to another buffer than operate on it from there.
Your code is is perfect for doing the job but better with-in another buffer.
I always know the Characters count so my final question about this is... How do i copy the first 5 terminated strings to another buffer. Strlen stops at 0.
I'm going to try to change parts of strlen to only stop at the Characters (A).
I just want to know how to do that REALLY... because i already see that all i got to do is reverse your code to just replace the dash back with the 00h zero terminator... And that may even be as fast and efficient as placing it all into another buffer. But i just want to know how to do it...
Thanks again Ehtyar
.386
.model flat,stdcall
option casemap:none
include \masm32\include\windows.inc
include \masm32\include\user32.inc
include \masm32\include\kernel32.inc
includelib \masm32\lib\user32.lib
includelib \masm32\lib\kernel32.lib
.data
x_1 db "1",0
x_2 db "2",0
x_3 db "3",0
x_4 db "4",0
x_5 db "5",0
c_A db "A",0
c_B db "B",0
c_C db "C",0
c_D db "D",0
c_E db "E",0
;Output needed: 1-2-3-4-5
.data?
; r_BUFFER db 20 dup(?)
r_BUFFER dd ?
numA dd ?
numB dd ?
.code
start:
;.........................................
lea eax, x_1 ; load your first buffer
cmp BYTE PTR [eax], 'A' ; just in case letter A
jz end_it ; go past if it is
@@:
add eax, 1 ; move to first null
mov BYTE PTR [eax], '-' ; make it a hyphen
add eax, 1 ; move to next letter
cmp BYTE PTR [eax], 'A' ; check it for (A) again
jnz @b ; if not,go to next buffer
; do the rest of your
; stuff with your new
; buffer here
invoke MessageBox,0,offset x_1,0,0
end_it:
invoke ExitProcess,0
The shorter way
mov eax,offset x_1
mov ebx,offset buff
mov ch,'-'
next:
mov cl,[eax]
mov [ebx],cl
cmp cl,'5'
jz done
mov [ebx+1],ch
add eax,2
add ebx,2
jmp next
done:
mov byte ptr [ebx+1],0
or the longer way
mov ebx,OFFSET buff
mov esi,OFFSET dash
invoke lstrcat,ebx,OFFSET x_1
invoke lstrcat,ebx,esi
invoke lstrcat,ebx,OFFSET x_2
invoke lstrcat,ebx,esi
invoke lstrcat,ebx,OFFSET x_3
invoke lstrcat,ebx,esi
invoke lstrcat,ebx,OFFSET x_4
invoke lstrcat,ebx,esi
invoke lstrcat,ebx,OFFSET x_5
The longer way will work with any length string.
Ooops :S Just a little oversight there.....sorry about that. I've never been one for algorithms, probably should have tested it myself before posting. Anyway, glad i could help even in a limited capacity ;)
Ehtyar.
QuoteOoops :S Just a little oversight there.....
That was'nt an oversight to me. It help me to see things a lot more clearly and still figuring out a lot of new things i did not know about behind it.
I would not have thought to over-write than repair with the same algorithms. I have over-written string buffers in the pass
(by accident or trying something new) than had no clue how to get it back until now. I bet I'm not the only one. Now i know how to deal with limited capacity :)
My goal was to cut-down on memory usage. I been writing in a way to get multi ways of re-using a single or a group of string buffers. And now i see it all was not in vain.
What's happening sinsi,
Thanks for the example, I got Ehtyar code near down pack and running like crazy. I'm be checking your out very shortly. It looks wonderful. Can't wait to get to it...
I'll be re-building with all of this for quite a while. Replacing all the silly work-around junk in my code.
be back soon with a cool procedure build from all of this.Thanks Guys
For the most part i got this code doing near what i am after.
..............................................
This is what i'm after:
DT00 :0100 :0200 :0300 :0400 :0500
..............................................
But this is what i get:
:0100 :0200 :0300 :0400 :0500 :A00
..............................................
It suppose to return the data like so:
base on the original code design:
I can live with this until i get sinsi code to read:
more than one char including repairing this one.
i like them both:
:DT00 :0100 :0200 :0300 :0400 :0500 :A00
..............................................
I stuck a call to szCopy and two calls to szCatStr which use szLen. All three have been modified to totally free-up EAX so basically it allow this extra coding to jump in-between Ehtyar code to do some farther modification of strings... But for some reason i loss the start-up string. DT disappear but everything else display correctly.
My main concern is the start-up string and not the ending of the string. That part can be fixed with strRev or inString that way it won't compucate things since im still asking for help. Do anyone know where i went wrong with this code. See Attachment:
[attachment deleted by admin]
wsprintf anyone?
.data
x_1 db "1",0
x_2 db "2",0
x_3 db "3",0
x_4 db "4",0
x_5 db "5",0
fmtstring db 'DT00 :%02s00 :%02s00 :%02s00 :%02s00 :%02s00',0
fmtstring2 db 'DT00 :%02d00 :%02d00 :%02d00 :%02d00 :%02d00',0
.data?
outbuffer db 100h dup(?)
.code
invoke wsprintf,addr outbuffer,addr fmtstring,addr x_1,addr x_2,addr x_3,addr x_4,addr x_5
invoke MessageBox,0,addr outbuffer,0,0
invoke wsprintf,addr outbuffer,addr fmtstring2,1,2,3,4,5
invoke MessageBox,0,addr outbuffer,0,0
Taking advantage of uniform string sizes and repetitive code.
.386
.model flat,stdcall
option casemap:none
include \masm32\include\windows.inc
include \masm32\include\user32.inc
include \masm32\include\kernel32.inc
includelib \masm32\lib\user32.lib
includelib \masm32\lib\kernel32.lib
.data
x_xx db "xx",0
DATA_MARK db "DT",0
x_01 db "01",0
x_02 db "02",0
x_03 db "03",0
x_04 db "04",0
x_05 db "05",0
c_A db "A",0
c_B db "B",0
c_C db "C",0
c_D db "D",0
c_E db "E",0
ADD_THIS db "00 ",0
szCaption db "Caption",0
.data?
TEMP_32 db 32 dup(?)
TEMP_256 db 256 dup(?)
.code
start:
mov esi, offset DATA_MARK
mov edi, offset TEMP_256
mov edx, dword ptr ADD_THIS
mov ecx, 6
@@:
mov eax, [esi]
add esi, 3
mov [edi], eax
add edi, 2
mov [edi], edx
add edi, 4
mov byte ptr [edi], ":"
add edi, 1
dec ecx
jnz @B
sub edi, 3
mov byte ptr [edi], 0
invoke MessageBox,0,addr TEMP_256,addr szCaption, MB_OK
invoke ExitProcess,0
end start
[attachment deleted by admin]
Thanks drizz, dsouza123 and everybody
I'm 100 step closer to writing smaller and smarter ASM.
Hello Everybody
I'm hooked on this PTR stuff and have got all of these examples working within my programs. So now i can go back and review them as an refresher course as i continue to learn.
I been working with this code attached below and i can't get it to insert text properly.
This one is based on Ehtyar example, but I'm now using a counter. I been trying since i last posted and is not getting anywhere fast. Could someone help me out with this once again. I'll be into this for quite a while.
Thanks in advance
ic2
[attachment deleted by admin]
This works, hope it gives you some ideas.
.386
.model flat,stdcall
option casemap:none
include \masm32\include\windows.inc
include \masm32\include\user32.inc
include \masm32\include\kernel32.inc
includelib \masm32\lib\user32.lib
includelib \masm32\lib\kernel32.lib
.data
rString db "1x0",13,10,0
x_0 db "0",0
x_1 db "1",0
x_2 db "2",0
x_3 db "3",0
x_4 db "4",0
x_5 db "5",0
x_6 db "6",0
x_7 db "7",0
x_8 db "8",0
x_9 db "9",0
Counter dd ?
TEMP_32 db 32 dup(?)
TEMP_256 db 256 dup(?)
szTitle db "100 to 190",0
.code
start:
mov esi, offset x_0
mov edi, offset TEMP_256
mov eax, dword ptr rString
movzx edx, word ptr rString+4
mov Counter, 10
@@:
mov ah, [esi]
add esi, 2
mov [edi+0], eax
mov [edi+4], dx
add edi, 5
dec Counter
jnz @B
invoke MessageBox, 0, offset TEMP_256, offset szTitle, 0
invoke ExitProcess,0
end start
[attachment deleted by admin]
Thanks dsouza123,
You guys have provided nearly all the information of How-to-Insert. This is not easily founded, anywhere, at any ASM Forum. During my days of searching, I type keyword "Insert Text" and found ONLY one single direct THREAD about it out of a hundreds ... My eye ball start throbbing a lot. I searched that hard.
The thing is, all of the above is going to help me and many others to cut our programs down to size. I see it all mentally and have replaced a little junk code already in my spare moments when not searching. But i can't move any farther until i know what can be done.
This is too important to me so. Everything here is much more than i was hoping for, but I'm not going to pass up the chance of a life time to get to the bottom of it all when the solution is only a line or two away.
dsouza123, your code is perfect for DWORD size strings. I can ONLY see why it don't work for longer strings and not much farther.
If it can be change to do the SAME THING for the beginning and the end of longer strings, for me that will be the bomb.
Operating on Both Ends or Not... is not important as long as it can do either end separately. Getting to the middle should'nt be a big deal but that don't even matter anyway, i use instring.
I was trying CLD and STD but i have not even got to first based because the code is to deep to understand and change right off.
per group of strings will always be the same length.
per group of strings will always received the same size insert.
rString db "1x0-ABCDEFGHIJKLMN",13,10,0
rString db "ABCDEFGHIJKLMN-1x0",13,10,0
Can we get around this?
.386
.model flat,stdcall
option casemap:none
include \masm32\include\windows.inc
include \masm32\include\user32.inc
include \masm32\include\kernel32.inc
includelib \masm32\lib\user32.lib
includelib \masm32\lib\kernel32.lib
.data
rString db "1x0-ABCDEFGHIJKLMN",13,10,0
x_0 db "0",0
x_1 db "1",0
x_2 db "2",0
x_3 db "3",0
x_4 db "4",0
x_5 db "5",0
x_6 db "6",0
x_7 db "7",0
x_8 db "8",0
x_9 db "9",0
szTitle db "100 to 190",0
strln dd sizeof rString ; 21 bytes
Counter dd szTitle - x_0
TEMP_32 db 32 dup(?)
TEMP_256 db 256 dup(99)
.code
start:
mov esi, offset x_0
mov edi, offset TEMP_256
shr Counter, 1 ; byte count list of strings / bytes per string
L0:
mov ecx, 0 ; copy rString to destination starting at edi
L1:
mov al, [rString+ecx]
mov [edi+ecx], al
inc ecx
cmp ecx, strln ; 0..20, 21 bytes
jb L1
mov al, [esi]
add esi, 2
mov [edi+1], al ; replace x char using current char from list of strings
add edi, strln
dec edi ; edi increased by strln - 1 (== 20)
dec Counter
jnz L0
invoke MessageBox, 0, offset TEMP_256, offset szTitle, 0
invoke ExitProcess,0
end start
Thank you dsouza123
I have one final question about this. I don't mean to be bothersome or wear the Forum out, but i nearly got all of this down to a science, except i can't count :(
I'm trying to insert the same number in two locations per string.
I got the first two numbers inserted properly, but i can't get the 3rd and 4th number in place. add esi, 4 and 5 may be what is giving me the problem. I can't figure out what to use. I know it's not add esi, 3 again, i don't think. I tried a lot of ways, but i don't know what im doing.
Could someone show me the syntax to insert the 3rd and 4th number with an brief explanation of why it work. I do appreciate it.
What i don't understand is exactly what (add esi, num value) does in this case. It not adding like 1+1=2 i don't think or is it.
mov al, [esi] ; 1st Num Inserted = 9
mov [edi + 1], al ; 9
mov [edi + 11], al ; 9
mov al, [esi + 1] ; 2nd Num Inserted = 0
add esi, 3 ;
mov [edi + 2], al ; 90
mov [edi + 12], al ; 90
mov al, [esi + 2] ; 3rd Num Inserted = 1
add esi, 4 ;
mov [edi + 3], al ; 901
mov [edi + 13], al ; 901
mov al, [esi + 3 ; 4th Num Inserted = 5
add esi, 5 ;
mov [edi + 4], al ; 9015
mov [edi + 14], al ; 9015[\code]
What are the contents of the strings ?
If the string that is the source of numbers to insert is something like
source db "9015",0
and the destination string is something like
dest db "ABCDEFGHIJKLMNOPQRSTUVWXYZ",0
and you want the result to be
dest db "A9015FGHIJK9015PQRSTUVWXYZ",0
and esi and edi point to the strings
mov esi, offset source
mov edi, offset dest
then the code would be
mov al, [esi] ; 1st Num Inserted = 9
mov [edi + 1], al ; 9
mov [edi + 11], al ; 9
mov al, [esi + 1] ; 2nd Num Inserted = 0
mov [edi + 2], al ; 90
mov [edi + 12], al ; 90
mov al, [esi + 2] ; 3rd Num Inserted = 1
mov [edi + 3], al ; 901
mov [edi + 13], al ; 901
mov al, [esi + 3] ; 4th Num Inserted = 5
mov [edi + 4], al ; 9015
mov [edi + 14], al ; 9015
esi and esi act as indexes into the strings,
whether by themselves [esi] [edi] or with displacements [esi + 1] [edi + 12]
they are indicating the location (which byte) in the string is being worked on.
The way the code you posted would have worked with an extended source string
.data
source db "9015abcdefghijklm",0
dest db "ABCDEFGHIJKLMNOPQRSTUVWXYZ",0
the result in dest
A90bgFGHIJK90bgPQRSTUVWXYZ
Well, i must be getting closer. I remove the 4th insertion code and changed this line to (add esi, 1) in the 3rd insertion code .... It runs, but now i get 8 extra strings per number.
Another strange thing is that I can swear that this was the first thing i tried while trying to stumble upon the solutions many, many times ...
i tried difference numbers like 123456 in the add esi, num space and got nothing all night but now all of a sudden i get this...
I modified your last example. It all based on your original last last example but with difference strings to allow the right amount of space for insertion.
Example:
A FGHIJK PQRSTUVWXYZ 1-9
A FGHIJK PQRSTUVWXYZ 10-99
A FGHIJK PQRSTUVWXYZ 100-999
A FGHIJK PQRSTUVWXYZ 1000-9999
If all is well this would be the last string of the list
A9999FGHIJK9999PQRSTUVWXYZ
1-9 works great
10-99 works great
100- and beyond don't work
A9015FGHIJK9015PQRSTUVWXYZ ; this is what i get
A9015FGHIJK9015PQRSTUVWXYZ
A9015FGHIJK9015PQRSTUVWXYZ
A9015FGHIJK9015PQRSTUVWXYZ
A9015FGHIJK9015PQRSTUVWXYZ
A9015FGHIJK9015PQRSTUVWXYZ
A9015FGHIJK9015PQRSTUVWXYZ
A9015FGHIJK9015PQRSTUVWXYZ
A9015FGHIJK9015PQRSTUVWXYZ
etc
A9015FGHIJK9015PQRSTUVWXYZ ; this is what i should get
A9016FGHIJK9016PQRSTUVWXYZ
A9017FGHIJK9017PQRSTUVWXYZ
A9018FGHIJK9018PQRSTUVWXYZ
A9019FGHIJK9019PQRSTUVWXYZ
A9020FGHIJK9020PQRSTUVWXYZ
A9021FGHIJK9021PQRSTUVWXYZ
A9022FGHIJK9022PQRSTUVWXYZ
A9023FGHIJK9023PQRSTUVWXYZ
etc
This is the one i changed that got me this far
mov al, [esi + 2] ; 3rd Num Inserted = 1
add esi, 1 ;
mov [edi + 3], al ; 901
mov [edi + 13], al ; 901
The example you JUST posted will make all the numbers the same
9015... but you did not know all of what i was after. This should finally explain it. I came a long way with your example and still going .
If i would have explained it this way in the beginning you would have known. I just did not know where to start. So i posted small numbers than realized each time i should have asked about this no, i should have asked about said that... every time i kind of messed it up...
Here what i been working with since. I had it up to triple it size with a lot of confusing try out... I just cleaned it up so you can see what i been trying to do without getting everyone else confused also.
Also, when it come to my naming procedures that others help me out with i like this one the best because it fits and since i can't pronounce your name i just say diagnosis 1 2 or 3
[attachment deleted by admin]
The main issue was the code to calculate dscount_x,
shr dscount, 1 only applied when the length of each individual string was 2 bytes.
The other issue is the pointer to the row only gets updated (once)
after all the characters are placed in the rStringx
Extra variables to clear things up.
.data
indiv_1 dd x_1 - x_0
indiv_2 dd x_11 - x_10
indiv_3 dd x_101 - x_100
indiv_4 dd x_1001 - x_1000
Here is a working dsouza_3 with a more general routine to calculate dsCount_3.
dsouza_3:
mov edx, 0 ; byte count list of
mov eax, dsCount_3 ; strings / bytes per string
mov ecx, indiv_3
div ecx
mov dsCount_3, eax
C0: mov ecx, 0
C1: mov al, [rString3 + ecx] ; copy rString to destination
mov [edi + ecx], al ; starting at edi
inc ecx
cmp ecx, SIZE_OF3 ; 0..20, 21 bytes
jb C1
mov al, [esi] ; row 1
mov [edi + 1], al ; replace 1st char at
mov [edi + 10], al ; replace 2st char at col 2
mov al, [esi + 1] ; row 2
mov [edi + 2], al ; replace x char by list
mov [edi + 11], al ; replace x char by list
mov al, [esi + 2] ; row 3
mov [edi + 3], al ; replace x char by list
mov [edi + 12], al ; replace x char by list
add esi, indiv_3 ; is increased by 1 row
add edi, SIZE_OF3
dec edi ; edi increased by
; strln - 1 (== 20)
dec dsCount_3
jnz C0
ret
[attachment deleted by admin]
dsouza123, I feel this to all who went of there way to help out. I'm forever in your debt.
I mean this and plan to do something about it someday soon...Stay Tune.
Thanks you