First, suppose you need a simple extension of the standard SMALL MODEL, in which you just need just one other segment for data. To do this, you can use the standard COMPACT MODEL. We illustrate how you declare data for the extra data segment (called the FARDATA SEGMENT), and how to use it.
title Use of Fardata .model compact ; not small model .stack 100h .data ; data declared here goes into the usual (NEAR) DATA SEGMENT len dw 13 s1 db 'Hello, World!' ; s1 has length 13 .fardata ; data declared here goes into the extra (FAR) DATA SEGMENT s1 db 'Goodbye, All!' ; NOTE: the variable s1 in each data segments are distinguished .code ; ; ... ; ; Here is how to use fardata. Suppose you want to move ; the contents of s1 in @fardata to s1 in @data. mov ax,@fardata ; or use the default segment name, _fardata mov es,ax assume es:@fardata ; tasm needs to know lea si,s1 ; because of ASSUME, this ; refers to s1 in @fardata ; mov ax,@data mov ds,ax assume ds:@data lea di,s1 ; because of ASSUME, this ; refers to s1 in @data ; mov cx,len rep movsb ; ; ...
What if you need more than two data segments? Then use .fardata declarations with explicitly named data segments.
.fardata dataseg1 len dw 8 s1 db 'very far' ; s1 has length 8 .fardata dataseg2 s1 db 'further!' s2 db 'unique' .code ; ; ... ; mov ax,dataseg2 mov es,ax assume es:dataseg2 lea si,s1 ; s1 in dataseg2 ; mov ax,dataseg1 mov ds,ax assume ds:dataseg1 lea di,s1 ; s1 in dataseg1 ; mov cx,len rep movsb ; ; ...If the name of a variable (e.g., s2) is globally unique, you can also get its segment number as follows:
mov ax, seg s2 ; instead of mov ax,dataseg2 mov ds, ax
Also, if these operations of modifying ds and es occurs in a procedure, remember to save and restore the old values of ds and es.
assume ds:dataseg1we are associating ds with the data segment object named ''dataseg1'', not associating ds with the number of the the data segment object named ''dataseg1''. In contrast, when we say
mov ax,dataseg1 mov ds,axwe are just loading a number into ds.
The default names of the segments in these standard models may be found in HELPPC (Assembler Programming Topics, under `segment names'). E.g. in the small model, the .code, .data, .const, .data? and .stack segments are named _TEXT, _DATA, CONST, _BSS and STACK, respectively.
.model ...or
model ...The former form is to achieve compatibility with MASM. The latter form is called the "ideal form". Similarly, we could just say
FARDATA ...instead of ``.fardata ...''.
The ideal form for the segment directive is
SEGMENT name [align] [combine] [use] ['class']