I am a new bee of assembly language. When i am learning to write a struct, strange things happened.
This is the struct i define
User struct
name byte 20 dup(0)
password byte 10 dup(0)
more byte "bbbbbbbbbbbbbbbbbbbbbbbbbbbb"
User ends
this is how i declare a variable
user1 User <"chi","fan">
but when i inspect variable user1 in visual studio 2019, i cant see the first member of struct name
my full code of data.asm
Employee struct
IdNum byte "000000000" ; 9
LastName byte 30 DUP(0) ; 30
ALIGN word ;
Years word 0 ; 2
ALIGN dword ;
SalaryHistory dword 0,0,0,0 ; 16
Employee ends
Employee2 struct
IdNum byte "000000000" ; 9
LastName byte 30 DUP(0) ; 30
ALIGN word ;
Years word 0 ; 2
ALIGN dword ;
SalaryHistory dword 0,0,0,0 ; 16
Employee2 ends
User struct
name byte 20 dup(0)
password byte 10 dup(0)
more byte "bbbbbbbbbbbbbbbbbbbbbbbbbbbb"
User ends
user1 User <"chi","fan">
worker4 Employee <"888","555">
worker2 Employee2 <"aaa","bbb">
my full code in main.asm
.386
.model flat,stdcall
.stack 4096
ExitProcess proto,dwExitCode:dword
.data
include data.asm
.code
main PROC
mov worker4.SalaryHistory, 1000H ;
;
invoke ExitProcess,0
main ENDP
END main
environment: windows,visual studio 2019
TL;DR: In modern versions of MASM (including the versions in Visual Studio) a line beginning with name
is effectively ignored.
NAME
is a reserved word in MASM. Versions of MASM in Visual Studio process the NAME
directive as taking a string, but these modern versions of MASM ignore the results of the directive. NAME
is a directive that exists to allow better source compatibility with earlier versions of MASM.
Because of this a line that starts with NAME
like:
name byte 20 dup(0)
is essentially ignored. This is why it doesn't appear in the debugger, nor can you reference it with something like:
mov user1.name, 'c'
The result of this should be that name
is an undefined symbol.
Solutions:
name
member to something like uname
or any other name that isn't a MASM reserved word.Use the NOKEYWORD
option to tell MASM that you want to override name
as a reserved word. Add this to the top of data.asm
(or main.asm
)
OPTION NOKEYWORD:<NAME>
This tells MASM not to consider NAME
as a reserved word. This should prevent the unwanted behaviour of MASM ignoring an entire line that starts with NAME
.