The LDS and LES instructions

Loading a far pointer (segment:offset) from memory.

Format of the LDS and LES instructions

InstructionDescription
LDS reg16, mem32Load DS:reg16 with a far pointer from memory (segment in DS, offset in reg16).
LES reg16, mem32Load ES:reg16 with a far pointer from memory (segment in ES, offset in reg16).

The LDS (Load Pointer into DS) instruction loads a 32-bit far pointer (a 16-bit offset and a 16-bit segment selector) from memory into a pair of registers: the specified general-purpose register and the DS register. The offset is loaded into the destination register and the segment into DS.

The LES (Load Pointer into ES) instruction works in a similar way, but loads the segment part into the ES register.

These instructions are convenient for working with data located in other segments.

Example of using LDS and LES

In this example we copy an array of words from the data data segment into the dstnum buffer located in the additional segment extr, using the LDS and LES instructions to load the addresses.

title Author: Evgeny Sergeevich Dovgopolov

.model small
.stack 100h

data segment public
    srcnum dw  1, 2, 3, 4, 5, 6, 7
    srclen equ ($-srcnum) / 2
    srcptr dd  srcnum
data ends

extr segment public
    dstnum dw srclen dup(0FFFFh)
    dstptr dd dstnum
extr ends

code segment public              ; Start of the code segment
    assume ds:data, es:extr, cs:code

    main proc                    ; Start of the main procedure
        mov     ax, seg data     ; Get the data segment address and store it in ax
        mov     ds, ax           ; Pass the data segment address from ax to ds
        mov     ax, seg extr     ; Get the address of the additional data segment and save it in ax
        mov     es, ax           ; Pass the data segment address from ax to es

        mov     cx, srclen       ; Copy the length of the srcnum array into the cx register
        les     di, es:[dstptr]  ; Load the dstptr far pointer into the es:di register pair
        lds     si, ds:[srcptr]  ; Load the srcprt far pointer into the ds:si register pair

    CopyLoop:
        mov     ax, ds:[si]      ; Copy an element from the data segment ds:si into the ax register
        mov     es:[di], ax      ; Copy the value of the ax register into the extr segment es:di

        add     si, 2            ; Increment the si index by 2
        add     di, 2            ; Increment the di index by 2
        loop    CopyLoop         ; Loop while CX≠0

        mov     ax, 4C00h        ; Copy the termination function number into ah and the value into al
        int     21h              ; Call the interrupt
    main endp                    ; End of the main procedure

code ends                        ; End of the code segment
end main                         ; End of file. The main procedure is the entry point

Example taken from the textbook "HANDYFAR - MASM (Evgeny Sergeevich Dovgopolov)".

Processor status flags

CF
No
PF
No
AF
No
ZF
No
SF
No
TF
No
IF
No
DF
No
OF
No