2
votes

when we want to make an initialized variable like this:

name db 'zara ali'

we have made a byte size variable but we stored a string in it

how it is possible??

and when we use this instruction:

MOV ecx, name

we have stored a byte sized variable in a 4 byte size register, while in MOV instruction both operands must be of same size. how it's possible??

1

1 Answers

8
votes

name db 'zara ali' is just a shorthand for

name db 'z', 'a', 'r', 'a', ' ', 'a','l','i'

that is another shorthand for

name db 'z'
     db 'a'
     db 'r'
     db 'a'
     db ' '
     db 'a'
     db 'l'
     db 'i'

thus that's a sequence of bytes, the address of the first one is given the name name.

MOV ecx, name has different semantics in different assemblers.
In NASM it doesn't read the variable name it stores the value of the symbol name in ecx - it is equivalent to the TASM/MASM notation

mov ecx, OFFSET name
lea ecx, name           ;This is an abuse of notation but valid in TASM

In MASM/TASM it reads the DWORD (implied by the use of a DWORD register like ecx) at the address name, thus reading the first four bytes (zara).
It is equivalent of mov ecx, [name] or mov ecx, DWORD [name] in NASM.