evodevo
evodevo

Reputation: 509

Local data in a macro

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   

Upvotes: 0

Views: 165

Answers (1)

Frank Kotler
Frank Kotler

Reputation: 1452

push ds ; save old ds
push cs
pop ds ; make ds same as cs
; do your thing
pop ds ; restore old ds

...should do what you want. Why not put all your data in your code segment, set ds to that, and leave it there?

Upvotes: 2

Related Questions