How to use LES in assembly language?

Viewed 307

I have to create COM file and use LES there. I didn't find any examples of using LES, only this one. And there is an error "operand types do not match" in the string LES BX, VIDEO What should I do? I thought we can use register bx for LES.

.model  tiny
.code
ORG 100h
start:                                 
LES BX, VIDEO ; ES = B800h (memory VGA), BX = 72Eh      
MOV AX, 0         ; reset registers
MOV ES, AX        ; ES = 0
MOV BX, AX        ; BX = 0

MOV BX, VIDEO     ; analog of using LES
MOV ES, VIDEO+2   ; with using two commands MOV
                ; ES = B800h (memory VGA), BX = 72Eh
RET               ; exit

VIDEO DW 72Eh
DW 0B800h
END start
1 Answers

The LES instruction is used with a dword memory operand. Your instruction LES BX, VIDEO refers to a word memory operand because VIDEO is followed by a DW (define word) directive. That is why you get the error "operand types do not match".

You can change this:

VIDEO DW 72Eh
      DW 0B800h

into

VIDEO DD 0B800h:072Eh

And of course the code that follows:

MOV AX, 0         ; reset registers
MOV ES, AX        ; ES = 0

will destroy what you just loaded in the ES segment register!

Related