Using a far pointer for a function call

When a far jump is performed in real address mode or in virtual mode, the 8086 processor jumps to the code segment and offset specified by the target operand.

Program source code

title Author: Evgeny Sergeevich Dovgopolov

.model small
.stack 100h

data segment public
    string db 0Ah, 0Dh, "Hello Assembly World!$"
data ends

code segment public
    assume ds:data, cs:code

    main proc
        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      dl, 'D'          ; Copy the value of the character 'D' into the dl register
        call far ptr PrintChar    ; Call the PrintChar procedure

        lea      dx, ds:[string]  ; Load the address of the string array into ds:dx
        call far ptr PrintString  ; Call the PrintString procedure

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

code ends

print_s segment public
    assume cs:print_s

    PrintChar proc far
        push     ax               ; Save the ax register value on the stack

        mov      ah, 02h          ; Copy the console output function number into ah
        int      21h              ; Call the interrupt

        pop      ax               ; Pop the value from the stack into the ax register
        retf                      ; Far return from the PrintChar procedure
    PrintChar endp

    PrintString proc far
        push     ax               ; Save the ax register value on the stack

        mov      ah, 09h          ; Copy the string output function number into ah
        int      21h              ; Call the interrupt

        pop      ax               ; Pop the value from the stack into the ax register
        retf                      ; Far return from the PrintString procedure
    PrintString endp

print_s ends
end main

D
Hello Assembly World!

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