I'm reading Assembly Language Step by Step Programming with Linux by Jeff Duntemann.
In the book he mentioned that the code
EatMsg: db "Eat at Joe's",10
mov ecx,EatMsg
Copies not the content of EatMsg but the memory where the content is stored at. This is understood and I have confirmed it via edb. But the statement:
EatMsg: dw "Eat at Joe's",10
When I checked this code in the debugger its the same memory address when using the db directive, that's understood as well however I know that dw, refers to "define word" (2 bytes).
But can someone tell me what actually happens during execution does the CPU reads a word at a time, because of the dw directive? I'm trying to visualize it.
The book confuses me because he mention that the general purpose registers would hold the address of the define string then I read the below excerpt and got confuse:
WordString: dw 'CQ'
DoubleString: dd 'Stop'
The DW directive defines a word-length variable, and a word (16 bits) may hold two 8-bit characters. Similarly, the DD directive defines a double word (32-bit) variable, which may hold four 8-bit characters. The different handling comes in when you load these named strings into registers. Consider these two instructions:
mov ax,WordString
mov edx,DoubleString
In the first MOV instruction, the characters ‘‘CQ’’ are placed into register AX, with the ‘‘C’’ in AL and the ‘‘Q’’ in AH. In the second MOV instruction, the four characters ‘‘Stop’’ are loaded into EDX in little-endian order, with the ‘‘S’’ in the lowest-order byte of EDX, the ‘‘t’’ in the second-lowest byte, and so on. This sort of thing is a lot less common (and less useful) than using DB to define character strings, and you won’t find yourself doing it very often. Because eatsyscall.asm does not incorporate any uninitialized data, I’ll hold off discussing such definitions until we look at the next example program.
How the CPU executes this and whats the benefit of using the db directive against the dw directive?
Thanks in advance
WordString
andDoubleString
without the square brackets is incorrect for Nasm.