News:

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

GAS macros

Started by hutch--, December 22, 2005, 03:25:04 AM

Previous topic - Next topic

hutch--

One would have to say that the documentation for AS could only be described as "very ordinary" but after downloading the current mingw binutils and carefully reading the help file, I found the ".altmacro" operator and suddenly many things become possible. Below are the few I have going so far. There is also a "vararg" for the last argument that I have not played with yet.

For whatever reason, the only version of AS that seems reliable with this stuff so far is the one from Freebasic. The ones I have downloaded from Mingw do not work properly but they have earlier build dates.


    .altmacro
    .macro WNDCLASSEX pre
      .bss
      .align 8
      pre&:
        pre&.cbSize:        .long 0
        pre&.style:         .long 0
        pre&.lpfnWndProc:   .long 0
        pre&.cbClsExtra:    .long 0
        pre&.cbWndExtra:    .long 0
        pre&.hInstance:     .long 0
        pre&.hIcon:         .long 0
        pre&.hCursor:       .long 0
        pre&.hbrBackground: .long 0
        pre&.lpszMenuName:  .long 0
        pre&.lpszClassName: .long 0
        pre&.hIconSm:       .long 0
      .text
    .endm

    .altmacro
    .macro MSG pre
      .bss
      .align 8
      pre&:
        pre&_hwnd:      .long 0
        pre&_message:   .long 0
        pre&_wParam:    .long 0
        pre&_lParam:    .long 0
        pre&_time:      .long 0
        pre&_pt:        .long 0
      .text
    .endm

    .altmacro
    .macro sztext uname,quoted_text
      .data
        uname&: .string quoted_text
      .text
    .endm


They allow code that is coming closer to readable and usable.


msgloop:

    MSG msg

  stlbl:
    TranslateMessage OFFSET(msg)
    DispatchMessage OFFSET(msg)
    GetMessage OFFSET(msg),0,0,0
    test eax, eax
    jnz stlbl

    ret


Seems to work fine for the WNDCLASSEX as well.


    WNDCLASSEX wc

    mov DWORD PTR wc.cbSize,           48
    mov DWORD PTR wc.style,            CS_BYTEALIGNWINDOW | CS_BYTEALIGNCLIENT
    mov DWORD PTR wc.lpfnWndProc,      OFFSET WndProc
    mov DWORD PTR wc.cbClsExtra,       0
    mov DWORD PTR wc.cbWndExtra,       0
    mov DWORD PTR wc.hInstance,        OFFSET hInstance
    mov DWORD PTR wc.hIcon,            OFFSET hIcon
    mov DWORD PTR wc.hCursor,          OFFSET hCursor
    mov DWORD PTR wc.hbrBackground,    COLOR_BTNFACE
    add DWORD PTR wc.hbrBackground, 1
    mov DWORD PTR wc.lpszMenuName,     0
    mov DWORD PTR wc.lpszClassName,    OFFSET szclassname
    mov DWORD PTR wc.hIconSm,          OFFSET hIcon

    RegisterClassEx OFFSET(wc)


String data can be done on one line.


    sztext szfile,  "&File"
    sztext szedit,  "&Edit"
    sztext sznew,   "&New\tCtrl+N"
    sztext szopen,  "&Open\tCtrl+O"
    sztext szquit,  "&Exit\tCtrl+Q"
    sztext szundo,  "&Undo\tCtrl+Z"
    sztext szcut,   "&Cut\tCtrl+X"
    sztext szcopy,  "C&opy\tCtrl+C"
    sztext szpaste, "&Paste\tCtrl+V"
    sztext szclear, "C&lear\tDEL"


The "&" character appears to work on both ends of the string data you wish to pass to the macro.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

Vortex

Nice work Hutch. How can we get the help file where you found the detailed explanation of GAS macros?


hutch--

Thjis is the file I downloaded to get the text format. I got it from the Mingw site.

binutils-2.16.91-20050827-1.tar.gz

The file with the data on AS is "as.info-1". It is in some strange format that I don't have the correct reader for but it can be read in a text editor.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

Tedd

Quote from: hutch-- on December 22, 2005, 07:58:19 AM
The file with the data on AS is "as.info-1". It is in some strange format that I don't have the correct reader for but it can be read in a text editor.

It'll be in "man" page format (as in the unix command "man as")
I presume there'll be a converter somewhere.
No snowflake in an avalanche feels responsible.

hutch--

Here is the current test piece. I have used some of the macro capacity and its starting to look like civilised code. I have not tested them out yet but there appears to be an .IRP and .IRPC pair of loop commands that will probably be useful. It the "structures" in the test piece I have used the GAS .ifndef .endif and they work fine.

[attachment deleted by admin]
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

Vortex

Hi Hutch,

I downloaded binutils-2.16.91-20050827-1.tar.gz and tried to use as.exe coming with this package :

.macro invoke func:req,args:vararg

   .ifnb \args
      push \args
   .endif

   call \func

.endm


This simple maco fails and I receive the error messages :

QuoteMsgbox.as: Assembler messages:
Msgbox.as:52: Error: suffix or operands invalid for `push'
Msgbox.as:56: Error: too many memory references for 'push'
Msgbox.as:67: Error: too many memory references for 'push'

Msgbox.as from my Gas+Scan.zip example.

Anyone who has some ideas to solve the problem?

hutch--

Vortex,

I get the same effect from both of the versions I have downloaded. It may be the case that the version of AS that comes in Freebasic has been modified so the only real chance is to try and get the source for it but it will probably mean having to have GCC set up on a machine as well to build it as well.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

MichaelW

Unlike the AS version that is distributed with FreeBASIC version 0.14 beta, the AS version from binutils-2.16.91-20050827-1.tar.gz does support :req and :vararg. But for some reason it will not work with Hutch's includes (or at least the new ones).

This seems to work OK, but reversing the arguments is going to require some additional functionality, perhaps something like CATSTR and SUBSTR.

/* ««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««« */

    .intel_syntax noprefix
    .global _entry_point

    //.include "\\gas\\include\\winequ.gi"
    //.include "\\gas\\include\\masm32.gi"
    //.include "\\gas\\include\\user32.gi"
    //.include "\\gas\\include\\kernel32.gi"
    //.include "\\gas\\include\\gdi32.gi"

    .altmacro

    .macro test1 arg1:req,arg2:vararg
      .print "\arg1"
      .print "\arg2"
    .endm
   
    .macro invoke func:req,args:vararg
      //.ifnb \args
        .irp param,\args
            push param
        .endr
      //.endif
       call \func
    .endm

.data
    message: .asciz "message"
    title:   .asciz "title"
.text
/* ««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««« */

_entry_point:

    //test1          // to test req.
    test1 my
    test1 my,other
    test1 my,other,brother,darryl
   
    invoke _MessageBoxA@16,0,OFFSET(message),OFFSET(title),0
   
    invoke _ExitProcess@4, 0

/* ««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««« */


Looking as some of the GAS source, I think a custom build may be the only method of getting the functionality right.


eschew obfuscation

hutch--

I downloaded and had a quick look at the source for it but I don't have GCC set up on any machine. It looked very much like the builds I used to do on Linux boxes for Eggdrop bots years ago. I wonder how much work it would take to set it all up so it builds properly and can be modified ? The version number on the AS that came with Freebasic is an inbetween build from the recent published builds at Mingw so the author may have done a set of custom modifications on the source himself.

From a quick look at the source, it does not look all that bad except my C is really rusty and what may be a viable proposition is to gut all the multiport stuff out of it so that x86 can be done properly.

I have just cleaned up and attached a tool I have had for a while, its a library to decorated name list utility. Run it on a library or group of libraries and it will produce a text file with a list of decorated names for each library. This should be useful in any future include files for AS.

[attachment deleted by admin]
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

Vortex

MichaelW,

Thanks for correcting the invoke macro. Back home, I will try it.

Hutch,

Your tool looks nice :U
Notice that Pelle's librarian Polib has the capacity to create DEF files with decorated names from import libraries.

James Ladd

Does anyone use cygwin and gas?
In this environment you can do a 'man as' to get manual pages and you can also do
'info as' to get a tutorial/manual that is rather detailed.