Hi Everyone,

I am new to ASM, am coming along. I am using GoASM, but can follow the syntax of MASM well enough.

I am wanting to create, write to, and read from a one-dimensional array of strings. I will make the strings maximum of 32 bytes length, and will zero-terminate them.

I realize that an "array" is a high-level concept, and that in ASM a block of memory is just that - a block of memory. Forgive those of us who are weak and still think in HLL, we'll get there ;)

I looked at the information given in Hutch's ASMIntro help file, under "Calculating Affective (sic) Address", which uses [ Base Address + Index * Scale + Displacement ]. I must be inplementing it wrong. What I did was:

mov eax, [ Base Address + Index * Scale + Displacement ]
lea eax, [ Base Address + Index * Scale + Displacement ]

and then using eax as the address sent to the lstrcpy function in the WinAPI, but this bombs very nicely, so I am not understanding something. In the function call I tried eax, and .

I think I understand that "Base Address" is essentially the label of where the data is stored, "Index" is - well it is the index, how else can you say it -, the "Scale" is the data size (32 in this case), and the "Displacement" is not applicable in this example of a one-dimension array. So, am I on the right track?

Can anyone post a simple example of how to do this either in MASM (without HL contructs or macros) or GoASAM syntax?

:stupid: Greg
Posted on 2003-03-28 06:47:48 by bushpilot
at first, your array strings should have not a maximal size of 32, but an _exact_ size of 32, so you can easy navigate with an index value (this will be the same fact in HHL too). The address-mode you wrote, cannot be used here, since the scale factor is limited to 16 (I think), but you can easily calculate the correct address with plain and simple math:



xStrings: db "Hallo Welt", 22 dup(0)
db "1234567890123456789012345678901", 0
db "This is line three", 14 dup(0)


lea eax, xStrings

; -- print out first string --

push MB_OK
push NULL
push eax
call MessageBox

; -- goto next string --

lea eax, [eax + MY_ENTRY_SIZE] ; same as add eax, MY_ENTRY_SIZE

; -- print out this string --

push MB_OK
push NULL
push eax
call MessageBox

; -- go directly to an index --

mov ecx, 3 ; could be dynamic

lea eax, xStrings
shl ecx, 5 ; same as imul ecx, 32
add eax, ecx

;; use resulting eax like above
I hope this shows you something new and helpful...
Posted on 2003-03-28 07:10:22 by beaster
Scale factor has a maximum of 8... I was wrong.
Posted on 2003-03-28 07:19:47 by C.Z.
Hi C.Z.,

This does not look too different than what I was trying last night. I'll try what you have written below tonight, there may be a difference that I don't remember.

It looks as if to read the data, I simply swap the two parameters for lstrcpy?


Posted on 2003-03-28 07:25:41 by bushpilot
Thank you beaster, this looks like what I was looking for.


PS Wht happened to C.Z.'s post? It disappeared - how do you do that?:confused:
Posted on 2003-03-28 10:36:02 by bushpilot

You can use the same addressing mode but change the value of the index by the step in memory you require. You will need to control the read length to ensure you don't go past the end of each 32 byte buffer in the array.

Depending on how large the array will be, you can do it in the .DATA and .DATA? sections as well.

.DATA? ; uninitialised data
buf1 db 32 dup (?)
buf2 db 32 dup (?)
buf3 db 32 dup (?)
buf4 db 32 dup (?)

array dd buf1, buf2, buf3,buf4 ; Store the addresses

Then you can read thriough or write to the addresses in the array by incrementing or decrementing by 4 either way.


Posted on 2003-03-29 03:34:58 by hutch--