The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: Foulone on March 02, 2005, 05:38:26 AM

Title: Help with structs...
Post by: Foulone on March 02, 2005, 05:38:26 AM
I want to create a structure for use with a high score table, something of the nature:

struct highscores
hs_score dd 0
hs_name db 4
ends
(producing a constant highscores_struct_len = 8, if possible)

then populate my highscore table using the struct, something like

highscore_table:
highscores 5,abc
highscores 10,def
highscores 15,ghi

producing the following data
highscore_table
dd 5
db "abc",0
dd 10
dd "def",0
dd 15
dd "ghi",0

is this possible? what would be the correct syntax

Title: Re: Help with structs...
Post by: donkey on March 02, 2005, 10:13:14 AM
MAX_HIGH_SCORES equ 10

highscores STRUCT
hs_score DD ?
hs_name DB 4 DUP (?)
highscores ENDS

.DATA
Scores highscores MAX_HIGH_SCORES DUP (<?>)
index dd ?
szname db "abc",0

.CODE
mov eax, [index]
mov [Scores[eax].hs_score], 15
invoke lstrcpyn, [Scores[eax].hs_name], offset szname, 4


[index] would contain a number from 0 to MAX_HIGH_SCORES-1 that would be the position in the array where the high score is placed.
Title: Re: Help with structs...
Post by: manhattan on March 02, 2005, 03:02:28 PM
For constant initialization you can also use


highscores struct
hs_score dd ?
hs_name db 3 dup (?)
_zero db 0
highscores ends

highscore_table highscores <5, "abc">
                highscores <10, "def">
                highscores <15, "ghi">
Title: Re: Help with structs...
Post by: Foulone on March 03, 2005, 04:46:25 AM
Thanks guys  :U