This is how I store local data in a macro (I use TASM):
locals LL
.model small
.stack 100h
.data
.code
exit proc
mov ax, 4C00h
int 21h
endp
printStr macro str
jmp LLcode
_str db str,'$'
LLcode:
push ax dx
mov dx, @code
mov ds, dx
mov dx, offset _str
mov ah, 9
int 21h
mov dx, @data
mov ds, dx
pop dx ax
endm
start:
printStr 'Hello world
call exit
end start
However, now I have to change ds to code segment address in every macro and later change it back to the data section address. Is there a better way to do this? Or a “standard” way how everyone does that?
Or maybe this is a better way?
push ax dx ds
mov dx, @code
mov ds, dx
mov dx, offset _str
mov ah, 9
int 21h
pop ds dx ax
…should do what you want. Why not put all your data in your code segment, set
dsto that, and leave it there?