Using conditional assembly syntax question.

Started by Relvinian, May 14, 2009, 08:50:20 PM

Previous topic - Next topic

Relvinian

Hello,

I have originally written some ASM code in MASM with their appropriate .INC include files and corresponding .H files so I can use the same functions in both ASM and C/C++ code. Now I've decided to go back and update some of the code and also add a lot more functions to my ASM libraries that I've created over the years.

For this, I have decided to switch the syntax of the .asm files to GoAsm and try to get away from .inc files and have a common .h file that I can use in both ASM and c/c++ code.  The question I have that arises from reading over the GoAsm manual is this:


#include "asmrtl_defines.h"
#if !defined(_UNICODE) && !defined(UNICODE)  // supports both MFC and Windows style defines.
  #include "ansi\asmrtl_prototypes.h"
  #include "ansi\asmrtl_structs.h"
#else
  #include "unicode\asmrtl_prototypes.h"
  #include "unicode\asmrtl_structs.h"
#endif


The above code compiles just fine with c/c++.  Is this syntax valid for GoAsm?  If not, what would I have to change?  I am not sure if the #if !defined(???) is what is valid and also if you can have multiple checks on a single line.  I can go back and change all the .h files to use #ifndef if the rest is valid.

Relvinian

jorgon

Hi Relvinian

GoAsm does use the "#if" form and does not use "if".

However GoAsm does not recognise "defined" or "!defined", and you will need to change this to #ifdef or #ifndef.

GoAsm does not support "&&".  Instead you can use "&" or AND for a bitwise AND.



Author of the "Go" tools (GoAsm, GoLink, GoRC, GoBug)

Relvinian

Jeremy,

Thank you for the reply on the syntax statement of the !defined() and defined() plus the and/oring of conditionals.

My ultimate goal is to use the same .h for both c/c++ and .asm projects so I have modified a single .h file with the changes. Before I delve into changed all other .h files (and eliminating all my .inc) plus changing all the .asm files to match GoAsm syntax (which I don't mind at all), I would like to get the single .h file down first. The rest of the .h (and my .inc) files are not going to be anymore complex than this as conditional assembly (compilation) is concerned.  ;-)

Below is one of my .h files that I have changed (full version listed other then some comments at the top). Is this going to be valid for GoAsm?

#ifndef(AFX_ASMRTL_H__INCLUDED_)
#define AFX_ASMRTL_H__INCLUDED_

#if _MSC_VER > 1000
  #pragma once  // only process this file once per source file
#endif // _MSC_VER > 1000

// ---------------------------------------------------------------------------
// Base Windows System include
// ============================================================================
#if _MSC_VER > 1000
  #ifndef(VC_EXTRALEAN)
    #define VC_EXTRALEAN    // Exclude rarely-used stuff from Windows headers
  #endif // _MSC_VER > 1000
#endif
#include <windows.h>

// ----------------------------------------------------------------------------
// Base ASMRTL32 library includes which have defines, structure definitions,
// commonly used function prototypes and the required memory routines.
// ANSI or UNICODE based on define where applicable during assembling.
// ============================================================================
#include "asmrtl_defines.h"
#ifdef(_UNICODE)  // MFC unicode defined
  #include "unicode\asmrtl_prototypes.h"
  #include "unicode\asmrtl_structs.h"
#elif(UNICODE)  // Windows unicode defined
  #include "unicode\asmrtl_prototypes.h"
  #include "unicode\asmrtl_structs.h"
#else
  #include "ansi\asmrtl_prototypes.h"
  #include "ansi\asmrtl_structs.h"
#endif
#include "asmrtl_memory.h"

// ============================================================================
#endif // #define AFX_ASMRTL_H__INCLUDED_


Thanks for taking the time to help me get the .h files in order for GoAsm usage.

Relvinian

jorgon

Hi Relvinian

GoAsm can handle all of this, except that the line starting #pragma will be ignored completely.


Author of the "Go" tools (GoAsm, GoLink, GoRC, GoBug)

jorgon

Actually I've just noticed in GoAsm source code that #if defined, #if !defined, #elif defined and #elif !defined is also supported.
Sorry it wasn't in the help file so I assumed it wasn't.

Author of the "Go" tools (GoAsm, GoLink, GoRC, GoBug)

Relvinian

Quote from: jorgon on May 16, 2009, 05:26:03 PM
Hi Relvinian

GoAsm can handle all of this, except that the line starting #pragma will be ignored completely.


I was hoping that it would.  Only the Visual Studio compiler needs this #pragma.  That's why I wrapped it in a check. ;-)

Relvinian

Relvinian

Quote from: jorgon on May 16, 2009, 05:36:46 PM
Actually I've just noticed in GoAsm source code that #if defined, #if !defined, #elif defined and #elif !defined is also supported.
Sorry it wasn't in the help file so I assumed it wasn't.


That's awesome.  I'm too use to using #if defined(), #if !defined(), etc because my main programming is c/c++ (that's what I do for a living).  :-)

Relvinian

PS - Thanks again for the help.  Now the task of going through all my thousands of .asm / .inc / .h files and updating the code to GoAsm syntax and adding the new .asm modules to my ASMRTL.DLL library.