Draw LABEL DWORD
Ten dd 0
Twenty dd 0
Thirty dd 0
Forty dd 0

If I declare labels as such I can access it with:
lea esi,
because the way I understand it, it was declared on a double word boundary, hence the multiply by 4

If I however want to declare the following, how can I access it because now it is not aligned on a definite boundary anymore and the string lengths differ.

Shapes LABEL DWORD
circle db 'CIRCLE' ,0
line db 'LINE' ,0
arc db 'ARC' ,0
Posted on 2004-03-09 19:12:49 by Pieter
hi,

how about using array of offsets?

.data

szFile1 db "File1", 0
szFile2 db "File2", 0 ;etc etc

mylist dd offset szFile1
dd offset szFile2
dd NULL


or fixed length strings OK? Can increase pointer or check if value NULL in loop.

tagMyList STRUCT ;fixed length of 32 bytes per item
myitem db 32 dup (?)
tagMyList ENDS

.data
newlist tagMyList <"File1">
tagMyList <"File2">
tagMyList <"File3">

bye
X05
Posted on 2004-03-09 20:33:13 by X05
In your first example, you don't even have to declare a separate label. You can always access your data with .

For your 2nd example, I would suggest the following (assuming 32-bit programming):
circle db 'CIRCLE' ,0

line db 'LINE' ,0
arc db 'ARC' ,0
Shapes dd circle,line,arc
The assembler will insert the address of the listed variables for the values of Shapes. You can then retrieve one of those addresses with Shapes or depending on your assembler.

Raymond
Posted on 2004-03-09 20:39:29 by Raymond
Thank you very much for the advise, I will try it
Posted on 2004-03-09 22:52:08 by Pieter
Try this... easier to maintain, and looks cleaner IMO.



; Who wrote this macro originally?
CTEXT MACRO y:VARARG
LOCAL sym

CONST segment
IFIDNI <y>,<>
sym db 0
ELSE
sym db y,0
ENDIF
CONST ends

EXITM <OFFSET sym>
ENDM

.data
TABLE LABEL DWORD
dd CTEXT("Circle")
dd CTEXT("Line")
dd CTEXT("Arc")

.code
mov edx, 1
mov eax, [TABLE + edx*4]
Posted on 2004-03-10 05:29:46 by f0dder
Thanx Fodder, I have tried Raymonds method and it worked just fine, will figure out what happens in your code and try it as well.
Regards
Posted on 2004-03-10 20:19:56 by Pieter
Pieter

Now that you've seen that my suggestion works fine, something else may be usefull to you in the future. The same method can work just as well with code labels.

If, for example, you want to go to different parts of your program based on user input, you could simply get their address in a similar variable in your data section and call those parts from a central dispatching section of code. This is what it could look like.
.data


wanted dd action1,action2,action3

.code

.........

dispatcher:
mov ecx,offset wanted
call [ecx+eax*4] ;EAX must be 0-based for the action wanted
...... ;called code returns here
;do whatever else is necessary

action1:
......
ret

action2:
......
ret

action3:
.....
ret
Have fun

Raymond
Posted on 2004-03-10 22:32:38 by Raymond
Pieter, my example basically does the same as Raymond's, while just looking prettier :) and being easier to maintain.
Posted on 2004-03-11 03:35:15 by f0dder

If I however want to declare the following, how can I access it because now it is not aligned on a definite boundary anymore and the string lengths differ.

Shapes LABEL DWORD
circle db 'CIRCLE' ,0
line db 'LINE' ,0
arc db 'ARC' ,0

Sometimes, in simple cases with a few text items <= 8 chars including the zero, I align the text to 8 bytes and access it with *8 scale index. The principle:


.data
base label byte
circle db 'CIRCLE',0,0
line db 'LINE',0,0,0,0
arc db 'ARC',0,0,0,0,0,0

.code
mov ebx,offset base
lea eax,[ebx+ecx*8] ; get the offset

Additionally, this metod adds (in this case) only 9 bytes in the data section.
Posted on 2004-03-11 13:30:13 by MazeGen