
proc doesn't seem to work in NASM
Quote:
> I saw the run-time stack problem after I posted. Thanks. I moved the
> procedure to the end of the file. In another test program, I encountered a
> starting point problem. (The documentation says to use ..start:, but that
> gave me a compiler error as well.) So I guess a second question is how to
> give the code an explicit starting point.
If you're using "-f obj" format, "..start:" should work - it's
recognised *only* in "-f obj" format. Your code looks like it's intended
for "-f bin" format (no "mov ax, data"/"mov ds, ax"...). In "-f bin"
format, you can't specify a starting-point - it starts at the beginning
of your ".text" segment.
Quote:
> Yes, I copied c16.mac to the same directory as the test file.
In some distributions of Nasm, there are two sets of "c16/c32.mac"
files. The ones in the "misc" directory are broken - I think they work
with Nasm 0.97 - the set in the main source directory work (?). I think
that might be the problem, at least it would cause the problem you're
seeing. As debs said, I know a little about Nasm, but macros are not my
strong point - I hardly ever use 'em.
Quote:
> Rummaging around the internet, I found a somewhat similar thread that gave a
> problem using %$i in a macro. The suggested solution was to use .i instead.
> I compiled using the dot and I get no errors. But does this mean the same
> thing? What I'm after is a locally defined variable (so I can use the same
> identifier in another procedure). I also want to do the same thing with
> labels. Using %DmyLab, for example, in the procedure generates an error as
> well.
Try "%%DmyLab" - I *think* that's how macro-local labels are done. Nasm
uses the dot for local labels - ".label" actually becomes
"last_non_local_label.label" internally. I'm not sure if it will work
properly inside a macro or not. Try it. Use the "preprocess only" option
- "nasm -e -o myfile.pre myfile.asm" - to see what you're getting.
Quote:
> The exact error message is:
> macrotest2.asm:24: error: parser: instruction expected
> macrotest2.asm:25: error: parser: instruction expected
Not very helpful. It's not trivial to produce an intelligent
error-message when the problem, essentially, is that Nasm's confused.
Nasm isn't alone in having this problem, IMO, but it *is* something that
could use work.
Quote:
> Lines 24 and 25 are
> %$i arg
> %$j arg
> The source follows:
> %include "c16.mac"
> %macro Exit 0
> mov al, 0h
> mov ah, 4ch
> int 21h
> %endmacro
> section .data
> val dw 50
> val2 dw 90
> section .text
> push word [val2]
> push word val
> call _nearproc
> pop bx
> pop ax
> Exit
> proc _nearproc
> %$i arg
> %$j arg
> mov ax,[bp + %$i]
> mov bx,[bp + %$j]
> add ax,[bx]
> endproc
I could be mistaken, but I think you're swapping "val" and "[val2]"
here, aren't you? As I interpret it, "i" is the "first variable up the
stack" - the offset of "val" - and you're putting that in ax...
But you've got to get the thing to assemble, before you worry about
that. I'm not the right one to educate you about Nasm's macros. I hope
someone who actually uses them can help. FWIW, here's the difference in
the macro files:
This is the "good" one...
---------------
%imacro arg 0-1 2 ; used with the argument name as a label
%00 equ %$arg
; we could possibly be adding some
; debug information at this point...?
%assign %$arg %1+%$arg
%endmacro
-----------------
And this is the "broken" one...
----------------------
%imacro arg 0-1 2 ; used with the argument name as a label
equ %$arg
%assign %$arg %1+%$arg
%endmacro
---------------------
If that's the problem, you may be all set. I hope so - if I liked
punctuation that well, I'd be using Gas :)
Best,
Frank