qa.hlp (Table of Contents; Topic list)
LoadPtr
   Example  Back  Contents  Index
──────────────────────────────────────────────────────────────────────────────
 
;* LoadPtr - Macro to load far address into segment:register pair, or
;* near address into register.
;*
;* Params:  sgmnt - Segment to be loaded with segment address
;*          reg - Register to be loaded with offset address
;*          ptr - Pointer to address
;*
;* Shows:   Instructions - lds     les
;*          Directives - MACRO     IF        IFIDNI     ELSE      ELSEIF
;*                       ENDIF     .ERR      %OUT       EXITM     ENDM
;*          Operators - < >       ;;
 
LoadPtr MACRO sgmnt, reg, ptr           ;; Macro definition
    IF @DataSize                        ;; If far pointer, and
        IFIDNI <sgmnt>, <ds>            ;;   if 1st argument is DS,
            lds reg, ptr                ;;   load DS:reg with far address
            EXITM
        ENDIF
        IFIDNI <sgmnt>, <es>            ;;   or if 1st argument is ES,
            les reg, ptr                ;;   load ES:reg with far address
            EXITM
        ENDIF
        .ERR                            ;; Generate error if not DS or ES
        %OUT 1st macro argument must be DS or ES
 
    ELSE                                ;; If near pointer,
        IFIDNI <sgmnt>, <es>            ;;   and if segment is ES,
            push ds                     ;;   ensure ES points to
            pop  es                     ;;   same segment as DS
        ENDIF
        mov reg, ptr                    ;; Then load reg with near address
    ENDIF
ENDM
                                    -♦-