When using MASM 6.15 under DOSBox whenever I try to do:
mov al, [cx]
or
mov al, [cx + bx]
or
mov al, [cx + 4]
I am getting the error: 'Only Base or Index Registers are allowed'
But then again, let's say I have an array var1. If I do:
.model small
.stack 4096
.data
var1 BYTE 1, 2, 3, 4, 5, 6, 7, 8, 9
.code
main proc
mov ax, @data
mov ds, ax
mov cx, 5
mov al, [var1 + cx]
mov ah, 4Ch
int 21h
main endp
end main
It works perfectly fine. Why doesn't it give the same error as above? CX is not a base or index register.
What is the whole working essence of the [] operator?
CX is known as the count register, as the ECX, CX registers store the loop count in iterative operations. DX is known as the data register. It is also used in input/output operations.
The add instruction adds together its two operands, storing the result in its first operand. Note, whereas both operands may be registers, at most one operand may be a memory location. The inc instruction increments the contents of its operand by one. The dec instruction decrements the contents of its operand by one.
The MOV instruction MOV copies the data in the source to the destination. The data can be either a byte or a word. Sometimes this has to be explicitly stated when the assembler cannot determine from the operands whether a byte or word is being referenced.
The EAX, EBX, ECX, EDX, EBP, EDI, and ESI registers are all 32-bit general-purpose registers, used for temporary data storage and memory access. Some of CPU instructions modify specific registers.
This is a bug in some versions of MASM. There are cases like these where MASM will try to incorrectly encode an instruction that shouldn't be possible. It should have thrown an error trying to encode this, as CX can't be used as a base or index in 16-bit addressing.
mov al, [var1 + cx]
Instead of generating an error it incorrectly generates it as:
mov bh, var1[bx+si]
The invalid instruction is encoded as:
8A B8 xx xx
Where xx xx
is the offset of var1
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With