If I understand you correctly, you want FRED to be defined somewhere and used by many modules/source files? Each module/source file, uses FRED and instead of changing the value in each source file and re-assembling each file, just change one instance of FRED and have it use everywhere? If this is the case, you can just plop the equ
ates into a static library and link against it. This does not work with %define
, only equ
.
Try this:
libequates.asm
global FRED, JOHN
FRED equ 5
JOHN equ 6
makefile for libequates.asm (modify for you needs)
LIBRARY = libequates
all: $(LIBRARY) PostMake
$(LIBRARY): $(LIBRARY).o
ar -cr $(LIBRARY).a $(LIBRARY).o
strip --strip-unneeded $(LIBRARY).a
$(LIBRARY).o: $(LIBRARY).asm
nasm -f elf64 $(LIBRARY).asm -F dwarf
PostMake:
mkdir -p ~/projects/lib/
mv $(LIBRARY).a ~/projects/lib
Now to use and test if it works (I will use printf
for simplicity):
externs.asm
extern FRED, JOHN, printf, exit
global start
section .data
fmtint db "%d", 10, 0
section .text
start:
mov rsi, FRED
mov rdi, fmtint
xor rax, rax
call printf
mov rsi, JOHN
mov rdi, fmtint
xor rax, rax
call printf
mov rdi, 0
call exit
makefile for externs.asm
APP = externs
all: $(APP) clean
$(APP): $(APP).o
ld -o $(APP) $(APP).o -entry start -L ~/projects/lib -lequates -lc -dynamic-linker /lib64/ld-linux-x86-64.so.2
$(APP).o: $(APP).asm
nasm -f elf64 $(APP).asm -F dwarf
clean:
rm $(APP).o
and output:
Now, you only need to change the equate value in one place, re-assemble only the static library and re-link your program/modules.