4

I want to work with two data segments in my TASM program. I know, it sucks, but I have to have two pretty big arrays, each one FFFFh in size (and I wish I could have them bigger).

I ASSUMEd the segments as following: assume cs:code, ds:data, ds:dat2, ss:stac. Before each usage of a variable in any of the data segments, I wrote:

mov ax, data (or dat2)
mov ds, ax

Now, when I try to compile, I get the following error for each line in which I use a variable:

**Error** source.ASM(232) Can't address with currently ASSUMEd segment registers

Also, I noticed the error only happening when I refer to the variable directly. When I write mov ax, example I get an error, yet when I write mov ax, offset example I don't get the error.

Is there a way to solve this? Or, even better, not use two data segments?

Thanks!

Barak Nehmad
  • 67
  • 2
  • 8
  • I'm not sure that you can `assume` multiple segments for the same segment register at the same time. Have you considered using `es` for the second data segment? – Michael Oct 07 '15 at 09:12
  • Guess you now know why we have moved on to 32 and 64 bit programs. – Bo Persson Oct 07 '15 at 12:07

1 Answers1

4

ASSUME is just an information for the assembler, it does neither produce nor change any code. You have to insert it, if the assembler complains, e. g. "CS unreachable from current segment". You can redefine an ASSUME at every place of the source code, it is valid for the following lines.

Example:

.MODEL huge

_TEXT SEGMENT
ASSUME CS:_TEXT
start:
    mov ax, _DATA
    mov ds, ax

    lea dx, [txt1]
    mov ah, 09h
    int 21h

    mov ax, _DAT2
    mov ds, ax

    lea dx, [txt2]
    mov ah, 09h
    int 21h

    jmp far ptr far_away

_TEXT ENDS

_TEXT2 SEGMENT
ASSUME CS:_TEXT2
far_away:
    mov ax, _DAT3
    mov ds, ax

ASSUME DS:_DAT3
    mov dx, example
    mov ah, 02h
    int 21h
    xchg dh, dl
    int 21h
    mov dl, 13
    int 21h
    mov dl, 10
    int 21h

    lea dx, [txt3]
    mov ah, 09h
    int 21h

    mov ax, 4C00h
    int 21h
_TEXT2 ENDS

_DATA SEGMENT
ORG 0FF00h
    txt1 DB "TXT_1", 13, 10, '$'
_DATA ENDS

_DAT2 SEGMENT
ORG 0FF00h
    txt2 DB "TXT_2", 13, 10, '$'
_DAT2 ENDS

_DAT3 SEGMENT
ORG 0FF00h
    example DW 'ab'
    txt3 DB "TXT_3", 13, 10, '$'
_DAT3 ENDS

_STACK SEGMENT STACK 'STACK'
      DW  1000h dup(?)
_STACK ENDS

END start
rkhb
  • 14,159
  • 7
  • 32
  • 60