Reputation:
I assume that the source and destination in MOV instruction must have the same size and when I write these instructions:
.data
var dw 0
.code
mov al,56h
mov var,al
I get the error that operands do not match 16-bit address and 8-bit register but in this condition, I don't get any error but still, var is 32 bit(double word) and ax is 16 bit so why I don't get any errors?
.data
var dd 0
.code
mov ax,56h
mov var,ax
I'm using emu 8086.
Upvotes: 1
Views: 452
Reputation:
8086 uses max 16 bit registers. When you tried to assign a 16 bit value to 32 bit variable, emu8086 assumes your variable is 16 bit.
Other assemblers that use the same syntax (MASM and TASM) do require an explicit word ptr
size override if you want to store only the low word of a named location that you defined as a dword. e.g. mov word ptr [var], ax
.
For emu8086, you only need this when storing one byte into a word variable.
The MASM/TASM behaviour is more consistent with letting the symbol name imply a size when storing an immediate, like mov var, 1
implies word ptr
if you defined it with dw
, even though there are no registers in the instruction to imply a size.
Upvotes: 1