Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

NASM %define %ifdef %include - Converting C to NASM

578 views
Skip to first unread message

Jim Carlock

unread,
May 1, 2008, 10:26:53 AM5/1/08
to
Hi,

I am looking to combine a bunch of "C standard .h" files
into one "MyInclude.inc" file.

Is there a suggested manner in which to get this done?

In the end, I seek to include ONLY ONE file, by using
the %include directive more than once.

An example...

;
; START MyInclude.inc
;

; prevent multiple inclusions
%ifndef MYINCLUDE_INC
%define MYINCLUDE_INC
;standard inclusions...
%endif

;WHICH SECTION do we include?
;
%ifdef SECTION_INC
;
;SEEKING a way to jump into and process ONLY the
;STDUNI_H section. Do NOT want to use an assembly
;jmp instruction. There a NASM directive to do
;this? Or can anyone suggest another way to get
;this accomplished?
;
%endif

;
;NOTE: Do we want an assembler label here? I think
;NOT! But is there a way to jump to a different
;location inside this one file without creating any
;assembly language (using NASM directives)?
;
STD_UNI_H:
%ifdef INCLUDE_STDUNI_H
;
%ifndef STDUNI_H
;STDUNI_H is NOT defined, so define it
;
%define STDUNI_H
;... all the stuff to get included ...
%else
;STDUNI_H is defined
;
;seek a way to exit this file...
;HOPING for %exit directive or some sort of other
;STOP_PROCESSING_THIS_INCLUDE_FILE directive.
%endif
;
%ifndef STDIO_H
;
%else
;seek a way to exit this file...
;HOPING for %exit directive or some sort of other
;STOP_PROCESSING_THIS_INCLUDE_FILE directive.
%endif
%endif

;
; END MyInclude.inc
;


;
; START MyMain.asm
;
%include "MyInclude.inc"

%ifdef HAVE_STDUNI_H
;
;already defined, so process ONLY the HAVE_STDUNI_H
;section.
;
%include "MyInclude.inc"
%endif

;
; END MyMain.asm
;

Am I thinking too far outside the box?

For instance,

%define SECTION_INC STDUNI_H

then a way to %exit that section when finished processing,
and a way to enter that section so that ONLY that one
gets processed (perhaps a %jump into it).

I don't see a %exit directive nor a %jump directive.

Is that perhaps something worthwhile to add. Perhaps
a sample way around it using a macro might be helpful.

Thanks.

--
Jim Carlock
North Carolina Swimming Pool Contractors
Custom Designed Swimming Pools
Custom Designed Spas
Custom Designed Water Features
http://www.aquaticcreationsnc.com/

Henry

unread,
May 1, 2008, 9:13:06 PM5/1/08
to

Frank Kotler

unread,
May 3, 2008, 3:01:36 PM5/3/08
to
Jim Carlock wrote:

...


> In the end, I seek to include ONLY ONE file, by using
> the %include directive more than once.

???

...


> I don't see a %exit directive nor a %jump directive.


I don't know, Jim. Seems to me you're trying to treat included material
as a "program", when it's essentially an "automated cut and paste".
Define "WHAT_I_WANT", %ifdef WHAT_I_WANT, %endif... and the rest of it
won't be included - nothing to %jump over, nothing to %exit. Even easier
is to *not* combine everything into one file, and %include the ones you
need... perhaps "collecting" them:

%include "thisprogram.inc"
...
; the program
;----------

; thisprogram.inc:
%include "stdio.inc"
%include "sockets.inc"
...

But you should be able to do it like:

%include "everything.inc"
%define NEED_STDIO
%define NEED_SOCKETS
...

I've seen Windows include files that work like that. I didn't understand
what the point was then, either :) (actually, the point was to speed up
Nasm!)

You can specify "-d", "-p" and "-I" options on the command line, or as
an environment variable, to control what gets included, if that helps.

I don't see the need for "execution"-type directives... but maybe I
don't understand what you're trying to do...

Best,
Frank

s_dubrovich

unread,
May 3, 2008, 11:50:56 PM5/3/08
to

I'm confused to, as to what Jim is after, exactly. Also, I wasn't
sure if nasm supported nested include's but it does. Perhaps the
following will do it, or give further ideas:
btw, nasm also supports nested %IF's as well...

;; myinc.nsm test includes
;; -f bin -l myinc.lst -o myinc.bin myinc.nsm

;;----Conditional Equates----
TRUE equ 1
FALSE equ TRUE-TRUE ;;conditionals test for Z,NZ

CS1 equ TRUE ;; desired state flags
CS2 equ TRUE
CS3 equ TRUE

%include "CS.INC"

;; the rest

;; =- EOF=-

;; CS.INC
;; CS Include more files

%IF CS1
%INCLUDE "CS1.H"
%ENDIF

%IF CS2
%INCLUDE "CS2.H"
%ENDIF

%IF CS1
%INCLUDE "CS3.H"
%ENDIF

;; -= eof =-

;; CS1.h

db 'this is CS1'

;; -= eof =-

;; CS2.H

db 'this is CS2'

;; -= eof =-

;; CS3.H

db 'this is CS3'

;; -= eof =-

= = = = =

1 ;; myinc.nsm test includes
2 ;; -f bin -l myinc.lst -o
myinc.bin myinc.nsm
3
4 ;;----Conditional Equates----
5 TRUE equ 1
6 FALSE equ TRUE-
TRUE ;;conditionals test for Z,NZ
7
8 CS1 equ TRUE ;; desired state
flags
9 CS2 equ TRUE
10 CS3 equ TRUE
11
12 %include "CS.INC"
13 <1> ;; CS Include more files
14 <1>
15 <1> %IF CS1
16 <1> %INCLUDE "CS1.H"
17 <2> ;; CS1.h
18 <2>
19 00000000 746869732069732043- <2> db 'this is CS1'
20 00000009 5331 <2>
21 <1> %ENDIF
22 <1>
23 <1> %IF CS2
24 <1> %INCLUDE "CS2.H"
25 <2> ;; CS2.H
26 <2>
27 0000000B 746869732069732043- <2> db 'this is CS2'
28 00000014 5332 <2>
29 <2>
30 <1> %ENDIF
31 <1>
32 <1> %IF CS1
33 <1> %INCLUDE "CS3.H"
34 <2> ;; CS3.H
35 <2>
36 00000016 746869732069732043- <2> db 'this is CS3'
37 0000001F 5333 <2>
38 <2>
39 <1> %ENDIF
40 <1>
41 <1> ;; -= eof =-
42
43 ;; the rest
44
45 ;; =- EOF=-

hth,
Steve

0 new messages