NASM - The Netwide Assembler
NASM Forum => Programming with NASM => Topic started by: Roman on May 29, 2012, 08:48:26 AM
-
Hi All!
Sory for my English, i do not know it :)
I have a trouble:
i have some code, this code have follow line
%include 'FILE_NAME'
and compile as follows
nasm -dFILE_NAME=filename.asm test.asm
but i gets error
fatal: unable to open include file `FILE_NAME'
I need this to work, can you help me?
-
Well, I can't get it to work as you specify. We could do:
nasm -p filename.asm test.asm
That will "pre-include" filename.asm, but it's limited to including the file at the beginning of test.asm. Will that work for you?
If you need the included file at some specific place in test.asm, other than at the beginning, you may be stuck with...
%ifdef __LINUX__
%include "linux.inc"
%elifdef __WINDOWS__
%include "windows.inc
%elifdef __BSD__
%include "bsd.inc"
%else
%error "Must define __LINUX__, __WINDOWS__ or __BSD__"
%endif
or some such. This would limit you to fixed choices, rather than being able to define an arbitrary filename on the command line.
Hopefully, your include file can be the first thing in your source file - the "-p" switch would be much easier!
Best,
Frank
-
Thanks, but this is not what I need to. There is a code with a documentation, and it is said that method I described above will work.
Documentation said that I need nasm 0.98.35, but I tried that version and it still does't work.
-
0.98.35 was a long time ago!
What I think I'm running up against is that if the parameter to %include doesn't include quotes around it, Nasm complains that "%include expects a filename". If I do put quotes around it, the macro "FILE_NAME" doesn't get expanded to "filename.asm". I just tried no quotes in the %include directive, and:
nasm -dFILE_NAME=\"filename.asm\" test.asm
This appears to be working! I question whether it'll work in a dos/doze environment, since they use the backslash differently (as I recall... you could try it). You don't say what platform you're on, so maybe this isn't an issue.
Is this "code with documentation" available to the public? Can you post a link?
Best,
Frank
-
Thanks! It work:)
I use Archlinux
Is this "code with documentation" available to the public?
sorry, there is no.
-
Try using the %defstr directive to quote the argument.
BITS 32
%macro incdef 1
%push _incdef_
%defstr %$file %{1}
%include %{$file}
%pop
%endmacro
incdef SYSTEM_CALLS
SECTION .text
GLOBAL _start
_start:
sys_write 1, msg_str, msg_len
sys_exit 0
SECTION .data
msg_str db "Hello, World!", 10
msg_len equ ($-msg_str)
%macro sys_write 3
mov edx, %3
mov ecx, %2
mov ebx, %1
mov eax, 4
int 80h
%endmacro
%macro sys_exit 1
mov ebx, %1
mov eax, 1
int 80h
%endmacro
$ ls
demo.asm macros.asm
$ nasm -f elf demo.asm -DSYSTEM_CALLS=macros.asm
$ ls
demo.asm demo.o macros.asm
$ gcc -nostartfiles demo.o -o demo
$ ./demo
Hello, World!
$