News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Reading past Terminated String

Started by ic2, May 19, 2007, 11:47:27 PM

Previous topic - Next topic

ic2

#15
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]

dsouza123

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.

dsouza123

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

ic2


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...

ic2

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]

dsouza123

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]

ic2

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