I'm having trouble just making clear EQU directive in assembler (8086).
abc EQU xyz
Does EQU literally swaps abc when found in code with xyz, whatever xyz represents, value etc?
i.e. Can i write?
varA EQU [bp+4]
mov ax, varA
And one more question is EQU globally accessed, i.e. can I define EQU out of procedure, and in procedure to use it?
EQU
items are not variables, they don't take any memory space :
EQU
referes to a constant value, it becomes a synonym for that value. This value can't be overwritten, even if you try it won't change.EQU
referes to another variable, it becomes a synonym for that variable, so everything that happens to the synonym will happen to the variable.Copy-paste next code in EMU8086 and run :
.model small
.stack 100h
.data
xyz DW 2016 ;◄■■■ ABC IS NOT A VARIABLE, IT IS
abc EQU xyz ; JUST A SYNONYM FOR XYZ.
pqr EQU 10 ;◄■■■ PQR IS NOT A VARIABLE, IT IS
; JUST A SNYNONYM FOR NUMBER 10.
varA EQU [bp+2] ;◄■■■ BP POINTS TO GARBAGE.
.code
mov ax, @data
mov ds, ax
mov abc, 25 ;◄■■■ XYZ BECOMES 25!!!!
mov pqr, 999 ;◄■■■ NO ERROR, BUT THE VALUE WILL NOT CHANGE.
mov ax, pqr ;◄■■■ AX IS NOT 999, AX=10.
mov si, varA ;◄■■■ GARBAGE.
mov bp, sp
mov si, varA ;◄■■■ DIFFERENT GARBAGE.
push ax ;◄■■■ PUSH 10.
call my_proc
mov ax, NUMBER ;◄■■■ YES, EQUS ARE GLOBAL!!! (AX=0B9H).
mov ax, 4c00h
int 21h
;-----------------------------------------
my_proc proc
mov bp, sp
mov si, varA ;◄■■■ WRONG VALUE (ANOTHER GARBAGE).
mov si, [bp+2] ;◄■■■ PROPER VALUE (10).
varB EQU [bp+2]
mov si, varB ;◄■■■ WRONG AGAIN.
NUMBER EQU 0b9h ;◄■■■ DEFINE EQU INSIDE PROCEDURE.
ret
my_proc endp
In the case of [bp+2]
it just doesn't seem to work, probably because the compiler can't get a fixed value.