News:

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

question about STRUCTERs

Started by Dasar, June 20, 2006, 12:45:07 PM

Previous topic - Next topic

Dasar

hi all


i have written this little code, to understand how to manipulate with STRUCTERs, but there is a problem, i tried alot to fix it, but i couldn't


this is the code:




.386
.MODEL FLAT, STDCALL

option casemap:none

include \masm32\include\windows.inc
include \masm32\include\user32.inc
include \masm32\include\kernel32.inc
include \masm32\include\masm32.inc
; ¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤

includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\user32.lib
includelib \masm32\lib\masm32.lib

;====================================================================


TFirstStruct STRUCT
    Name    db      255     dup(?)
    Work    db      255     dup(?)
TFirstStruct ENDS


.data
  MyString db "how are you ?",0
  Caption db "Caption",0

.data?

MyStruct   TFirstStruct <>

.code

    start:

    invoke szCopy, Addr MyString, Addr MyStruct.Name

    invoke MessageBox, 0, Addr MyStruct.Name , Addr Caption, MB_OK

    invoke ExitProcess, 0

end start


comment * the problem is:

C:\masm32\MyFile.asm(37) : error A2008: syntax error : Name
C:\masm32\MyFile.asm(39) : error A2008: syntax error : Name

its a syntax error :'(                                      *





could you please tell me where is the mistake here ??

and if its possible, please tell me about all the methods i can use to do what i want to do..

and any hint or notice is also very appreciated ^_^





another request:

do you know any Channels on IRC, interested in Assembly programming ? especially MASM32



thank you alot in advance ^_^

Shantanu Gadgil

TFirstStruct STRUCT
    Name    db      255     dup(?)
    Work    db      255     dup(?)
TFirstStruct ENDS

The problem is with the variable name "Name" :)
To ret is human, to jmp divine!

Ossa

Just to clarify that for you, "name" is a reserved word - you cannot use it... call it "Name_" or something.

Ossa
Website (very old): ossa.the-wot.co.uk

Dasar

thank you alot for your answers


i want to remind:

Quoteand if its possible, please tell me about all the methods i can use to do what i want to do..

and any hint or notice is also very appreciated ^_^



another request:

do you know any Channels on IRC, interested in Assembly programming ? especially MASM32


and thank you again : )





Ossa

Quoteand if its possible, please tell me about all the methods i can use to do what i want to do..

I'm not too sure what you want to do, can you clarify?

Quotedo you know any Channels on IRC, interested in Assembly programming ? especially MASM32

Sorry, no. (I might be interested if there is one though.)

Ossa
Website (very old): ossa.the-wot.co.uk

Dasar

Quoteand if its possible, please tell me about all the methods i can use to do what i want to do..

I'm not too sure what you want to do, can you clarify?

thanx Ossa..

i mean assign values to structure members.

Ratch

     MASM could be a little more specific about that error.  Instead of "synthax error", it could say "reserved word" instead.  Ratch

Ossa

Quote from: Dasar on June 20, 2006, 02:03:27 PM
i mean assign values to structure members.

OK, well this is mainly syntax stuff, as the method you use is really dependent on what you are trying to achieve.

MyStructure STRUCT
    dwDataItem1 dd ?
    szDataItem2 db 250 dup (?)
    fDataItem3 REAL4 ?
MyStructure ENDS


So, global definitions:

.data?

MyUninitData MyStructure <>
MyArray MyStructure 100 dup (<>)

.data

MyInitData MyStructure <123, "Hello", 23.6f>



Defining locals:

MyProc PROC pMyPointer:DWORD
    LOCAL MyLocal:MyStructure
    LOCAL MYLocalArray[100]:MyStructure


Using directly:

    mov eax, MyInitData.dwDataItem1
    mov MyArray[3].dwDataItem1, eax
    mov MyArray[37].fDataItem3, eax
    mov MyUninitData.dwDataItem1, eax


Using from a pointer:

    mov edx, offset MyInitData

    ; First method

    mov eax, [edx][MyStructure.fDataItem3]
    mov [edx][MyStructure.dwDataItem1], eax

    ; Second method

    ASSUME edx:PTR MyStructure

    mov eax, [edx].fDataItem3
    mov [edx].dwDataItem1, eax

    ASSUME edx:NOTHING

    ; Third method

    mov eax, (ptr MyStructure [edx]).fDataItem3
    mov (ptr MyStructure [edx]).dwDataItem1, eax


(There are more I think, but I only use those 3)

Using in invoke:

    invoke MyProc, addr MyInitData
    invoke MyProc, MyInitData.dwDataItem1
    invoke MyProc, addr MyInitData.fDataItem3
    invoke MyProc, MyArray[35].dwDataItem1
    invoke MyProc, addr MyArray[35].szDataItem2
    invoke MyProc, addr MyArray[35]


Various info:

sizeof MyStructure     ; 258
sizeof MyUninitData    ; 258
lengthof MyUninitData  ; 1
sizeof MyArray         ; 258*100 = 25800
lengthof MyArray       ; 100


Not sure if that helps, if not then just ask again,
Ossa




Small Disclaimer: There are things that I've said in there that I've used very seldom and might have wrong: number one amoung them is the use of a string in a structure initialisation - I believe they are all correct though.
Website (very old): ossa.the-wot.co.uk

Ehtyar

Try www.searchirc.com, i idle in #asm on efnet, good chan. and just a warning, don't join #winprog, they take very unkindly to noobs <insert obscenity here> :(

Dasar

Ossa, thank you very much, for your help and your explanation ^_^
QuoteNot sure if that helps, if not then just ask again,
Ossa

this helps alot :) , Ossa, Really you're a nice one  :D

Ehtyar, thank you for the site and for the info  ^_^