.DATA
Items label word
db BLOCK, COLOR1, 176, 40, 40, 40
db BLOCK, COLOR1, 214, 1, 1, 1
db BLOCK, COLOR1, 176, 40, 40, 40
db BLOCK, COLOR1, 214, 1, 1, 1
end
Hi there, a moment ago I was studying someone else code
and I ecountered the code above. What I want to know is
the second line (Items label word) what does it do (and
the meaning of it) and how you would access it.
Thanx for your help.
It creates a label. The type it gets is the one in the LABEL directive.
Notice that the given label is declared to be of type WORD, but that the first data is created as a BYTE type. There's probably some optimization going on where the values in the table are loaded/modified/stored two bytes at time, instead of one at a time.
If it were written as
Items db BLOCK, COLOR1, 176, 40, 40, 40
db BLOCK, COLOR1, 214, 1, 1, 1
db BLOCK, COLOR1, 176, 40, 40, 40
db BLOCK, COLOR1, 214, 1, 1, 1
then everywhere you wanted to move two bytes requires writing the WORD PTR type override, as follows:
mov ax,word ptr Items ; get block and color of first entry
mov bx,word ptr Items[2] ; get next two numbers
mov cx,word ptr Items[4] ; get last two numbers of first entry
With the LABEL directive, you can eliminate WORD PTR in the three example moves.
If MASM allowed
Items dw 0 dup(?) ; Don't generate any data
it would accomplish the same task.Thanx, you've made it very clear (good explaination!)