News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

DCLS.INC

Started by Randall Hyde, August 07, 2006, 05:38:38 PM

Previous topic - Next topic

Randall Hyde

Hi All,
I've attached a small include file that will become one of the basic files that support the HLA Standard Library. This particular file, which can actually be used independently of the HLA stdlib, is used to declare variables and types in a MASM program using a more high-level syntax.

This include file introduces a macro named "DclType" that you can use to create new data type declaration macros.  Here is an example of DclType's usage:


   DclType int8, sbyte   ; Type int8 is the same as an sbyte (signed byte)


Here is one example of an int8 variable declaration (i8)


  int8 i8


DclType differs from "typedef" insofar as when you declare variables using a DclType'd variable you get some additional information and additional syntax options.  Consider the following declarations


  int8 i8[16]  ;An array of 16 int8 objects
  int8 i8a[4][4] ;A 2-D array of 16 int8 objects
  int8 *pi8  ;A pointer (dword) to an int8 object


There are even options for initializers, see the comments in the include file itself for details.

One of the main reasons for using this declaration is that it creates some type information for the variables that you don't get with normal MASM declarations. For example, when you declare


  int8 i8


Not only does this create an sbyte variable i8, but it also creates a text constant "$?Type_i8" whose string info is the type of the i8 variable ("int8" in this case).  Therefore, software (using conditional assembly) can test to see if a variable has been declared with of the DclType declared types (e.g., by testing to see if "$?Type_<varname>" is defined. And if that symbol is defined, then you can test the string value to see exactly what type it is.

The purpose of this macro (among other things) is to allow the creation of a macro like the HLA "stdout.put" macro that automatically determines the type of its arguements and prints the data using the appropriate format.

Here's a short sample program demonstrating the use of some of the macros in this header file:



; Assembly code emitted by HLA compiler
; Version 1.86 build 8951 (prototype)
; HLA compiler written by Randall Hyde
; MASM compatible output

            if  @Version lt 612
            .586p
            else
            .686p
            .mmx
            .xmm
            endif
            .model  flat
           
            include dcls.inc


offset32    equ <offset flat:>

            .data
           
            int128  a
            int64   b
            int32   d
            int16   e
            int8    f
            int128  *g
           
            int8    h[2][4]
            char    chr



            .code           


            public  _Main
_Main       proc    near32

_Main       endp

            end _Main

Cheers,
Randy Hyde



[attachment deleted by admin]

japheth


Hi,

AFAIK the GeneSys system is intended to be used by by ASM beginners. Having this is mind I doubt that includes of such kind are helpful. ASM beginners shouldn't start by using macros which hide the differences between assembler and HLLs. That's not the right way to go IMO.

Regards

Japheth


Randall Hyde

Quote from: japheth on August 08, 2006, 03:16:30 AM

Hi,

AFAIK the GeneSys system is intended to be used by by ASM beginners. Having this is mind I doubt that includes of such kind are helpful. ASM beginners shouldn't start by using macros which hide the differences between assembler and HLLs. That's not the right way to go IMO.

Regards

Japheth



Well, years of experience with HLA, the HLA Standard Library, and the Art of Assembly have taught me otherwise.

You might have a point if by "beginners" you mean people who have done *no* other programming before. But if you're just talking about "new to assembly", then having macros like these is a good idea.

And, btw, the purpose of the data type macros is *not* to hide the underlying data types (which is why the bit size is always specified in the type name), but to offer a clue to macros like an "stdout_put" macro as the the type of a data operand so it can display the value using an appropriate format.  Given the popularity of stdout.put in HLA, I can assure you that people appreciate this.

Cheers,
Randy Hyde

PBrennick

Hi Randy,
I have archived the include file and will await further developments.  As far as beginners go, Japheth is correct in one sense but not in all.  I will put this addition to the project in its own folder and let the beginner make the decision on their own.  The same as I will do with Ramon's IDE which is coming next week.

Paul
The GeneSys Project is available from:
The Repository or My crappy website