I'm programming using MASM 6.11 on an old Windows 95 laptop, and I'm having a problem switching between data segments.
For the sake of organization I wanted to use a different data segment to hold all of the variables that are only used by my macros. That different data segment is also placed inside the macro file.
I thought I could specify a different data segment by just MOV
ing the new segment into DS, but that doesn't seem to be working. I get the following error repeated many times upon assembling.
error A20068: Cannot address with segment register
Here's an example .ASM
, and .MAC
file showing my program's basic layout.
;********************
; STACK SEGMENT
;********************
TheStack STACK SEGMENT
DB 64 DUP ('THESTACK') ;512 bytes for the stack
TheStack ENDS
;********************
; END STACK SEGMENT
;********************
;********************
; DATA SEGMENT
;********************
Data SEGMENT
var db ?
Data ENDS
;********************
; END DATA SEGMENT
;********************
;********************
; CODE SEGMENT
;********************
Code SEGMENT
assume CS:Code,DS:Data
MAIN PROC
;set Data to be the Data Segment
mov ax, Data
mov ds, ax
MAC3
;Return to DOS
mov ah,4ch ;setup the terminate process DOS service
mov al,0 ;ERRORLEVEL takes 0
int 21h ;return to DOS
MAIN ENDP
Code ENDS
;********************
; END CODE SEGMENT
;********************
END Start
And the .MAC file:
MAC1 MACRO
mov MacVar1,bx
ENDM
MAC2 MACRO
mov MacVar2,cx
ENDM
MAC3 MACRO
mov ax, MacData
mov ds, ax
MAC1
MAC2
mov ax, Data
mov ds, ax
ENDM
;********************
; DATA SEGMENT
;********************
MacData SEGMENT
macVar1 dw ?
macVar2 dw ?
MacData ENDS
;********************
; END DATA SEGMENT
;********************