在宏中传递偏移差或常量

Passing offset difference or constants inside macro

大学作业,必须用emu8086。没有 emu8086.inc

假设我有

msg db "Hello"
msgend:
msglen1 equ $ - msg
msglen2 db $ - msg

然后:

mov ax, msgend - offset msg ; ax gets the correct length
mov ax, msglen1             ; correct length
mov ax, msglen2             ; correct length

; same names as offsets to make it clear, 
; how which parameters would be passed. 
; But not the same in real code.
TESTMACRO macro msg msgend msglen1 msglen2
    mov ax,    msg ; correct offset
    mov ax, msgend ; correct offset
    mov ax, msgend - offset msg ; zero length
    mov ax, msglen1             ; again zero length
    mov ax, msglen2             ; correct length, but it used up a word
endm

所以。我无法以任何方式在宏中传递字符串的长度,除非传递在一个字中分配的长度。 但我很感兴趣,如果我能用一个常数来做到这一点。

使用 = 来定义您的等式而不是 equ

equ 等式的值在使用时计算,在您的情况下,这意味着 msglen1 中的 $mov ax, msgLen1指令。

= 等式的值是在定义时计算的,在这种情况下应该会给出您想要的值。