News:

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

E^cube's GoAsm questions

Started by ecube, March 30, 2009, 04:22:12 AM

Previous topic - Next topic

ecube

Sorry E^cube I split this out of the headers thread to deal with it more exclusively - Donkey

Great! And I have some questions, that's GoASM related, not your headers related

1) you said you had to specify short and long jumps, what does that mean exactly?
2) I see you use offset a lot in sources, is addr not supported?
3) In a few GoASM sources, if i'm not mistaken I saw individuals use PROC, is that inferior to FRAME?
4)


mov edx,[esi]
and edx,0FFFFh
CInvoke(wsprintf,offset szOrdinal,"Ordinal %u",edx)


how come you used your macro vs regular invoke?

Also I just checked out your WinExplorer project,very nice :)

donkey

1. Jmp short is jmp >label, jmp long is jmp >>label. GoAsm does not automatically calculate the type of jump needed though it will throw an error if the target of a short jump is outside of the allowable range.

2. ADDR and OFFSET are interchangeable in GoAsm. both keywords are available but do the exact same thing. LOCALs can be mov'ed using offset, btw GoAsm does not use the famous lea eax to push the offset of a local, it is calculated using the stack pointer.

3. PROC is not available to GoAsm and will throw an error. To build a stack frame you have only FRAME. Though unlike MASM there are other ways as well, see USEDATA in the GoAsm manual. Because scoping is so much better in GoAsm it provides for some pretty interesting stuff, you can even have constants local to a procedure with LOCALEQU, or release LOCAL data inside a procedure and redefine it with LOCALFREE. Finally, since there is no type checking in GoAsm there is no need for PROTOs. BTW, with USEDATA you can write a procedure and use the LOCALs and arguments from a different procedure, it inherits the stack frame of the other procedure, very cool.

4. Invoke in GoAsm is only for STDCALL in Win32 and FASTCALL in Win64, to have the stack automatically balanced after a call to a C calling convention function I wrote that macro. Personally I just use ADD ESP,xxx, it's clearer for me.

Yes, WinExplorer was a lot of fun to write and demonstrates some useful techniques, which was its original goal. Pretty much on the back burner now though, but I do constantly farm it for code.
"Ahhh, what an awful dream. Ones and zeroes everywhere...[shudder] and I thought I saw a two." -- Bender
"It was just a dream, Bender. There's no such thing as two". -- Fry
-- Futurama

Donkey's Stable

ecube

Wow thanks for all that, i'm suprised wsprintf uses cdecl though which msdn confirms, I assumed all win api used stdcall :\. This kind of makes things tricky now as MASM  user32.inc automatically has wsprintf defined as  wsprintfA PROTO C and it allows you to call with invoke happily. GoASM only supports stdcall so this poses the problem of having to check each and every windows api for cdecl calling...ugh.

donkey

Hi E^cube,

Pretty much only ws___ calls and anything from the C runtime library are cdecl. There are very few, generally if you don't use the CRTL you can assume that the only CDECL call you make in your source is wsprintf. I have a list somewhere but can't seem to find it, it would be easy to generate one from the MASM protos.
"Ahhh, what an awful dream. Ones and zeroes everywhere...[shudder] and I thought I saw a two." -- Bender
"It was just a dream, Bender. There's no such thing as two". -- Fry
-- Futurama

Donkey's Stable

ecube

alright great, I may just mod 32bitto64 code I wrote to list all of masms proto C defs to be sure. GoASM won't throw a error or anything will it if you try and call a cdecl function?

donkey

Quote from: E^cube on March 30, 2009, 06:09:46 AM
alright great, I may just mod 32bitto64 code I wrote to list all of masms proto C defs to be sure. GoASM won't throw a error or anything will it if you try and call a cdecl function?

No, invoke doesn't care what the functions calling convention is, it just pushes (in Win32) the parameters onto the stack and executes a CALL instruction.
"Ahhh, what an awful dream. Ones and zeroes everywhere...[shudder] and I thought I saw a two." -- Bender
"It was just a dream, Bender. There's no such thing as two". -- Fry
-- Futurama

Donkey's Stable

ecube

Jeremy can you please keep up to date, or add additional links to your latest assembler+linke versions on your site, or atleast on here, so all can benefit not just select few? it took me forever to find your latest link in order to use donkeys headers, the linker was hidden in some random thread on this forum.

Donkey

C:\GoAsm\Examples\Hello64World2>\GoAsm\bin\GoAsm /x64 Hello64World2.asm

GoAsm.Exe Version 0.56.5d - Copyright Jeremy Gordon 2001/9 - JG@JGnet.co.uk

Warnings ......................
Line 227 of the include file \GoAsm\include\windows.h:-
Could not open file:-
#include windef.h
Line 228 of the include file \GoAsm\include\windows.h:-
Could not open file:-
#include winbase.h
Line 244 of the include file \GoAsm\include\windows.h:-
Must declare a section first -
Use DATA SECTION ["name"], CODE SECTION ["name"] or CONST SECTION ["name"]
Or just DATA, CODE or CONST; .DATA, .CODE or .CONST

any suggestions? I don't want to build all my programs in the include directory with the headers...that's not ideal at all.


after I copied the build.bat and the example.asm to the include directory I got this


C:\GoAsm\Include>\GoAsm\bin\GoAsm /x64 Hello64World2.asm

GoAsm.Exe Version 0.56.5d - Copyright Jeremy Gordon 2001/9 - JG@JGnet.co.uk

Error!
Line 119 of assembler source file (Hello64World2.asm):-
Unresolved material after LEA:-
              DQ 0
In the struct at Line 3270 of the include file winuser.h


the Hello64world2 line erroring is
INVOKE RegisterClassA,ADDR WNDCLASS

I used the #DEFINE WIN64 switch before including windows.h which is the only file I included.



donkey

Hi E^cube,

Did you set the INCLUDE environment variable ? The windows.h file has a note about it as does the GoAsm manual.

WNDCLASS is a structure name, you must supply a data buffer address in order to use it with ADDR/OFFSET

LOCAL wcx:WNDCLASS

INVOKE RegisterClassA,ADDR wcx

Edgar
"Ahhh, what an awful dream. Ones and zeroes everywhere...[shudder] and I thought I saw a two." -- Bender
"It was just a dream, Bender. There's no such thing as two". -- Fry
-- Futurama

Donkey's Stable

ecube

no I didn't, i'll take a look, sorry about that, thankyou for the help.

donkey

Hi E^cube,

Thinking that this might be a problem declaring the structure locally, I tried this:

TestLocal FRAME
LOCAL wcx:WNDCLASS

INVOKE RegisterClassA,ADDR wcx
mov Q[wcx.hInstance],0 // This member uses a redefined data type
RET
ENDF


Everything seems to work perfectly:

QuoteC:\Programming\GoAsm\BIN\GoAsm.EXE /x64  "TestStuff.asm"

GoAsm.Exe Version 0.56.5c - Copyright Jeremy Gordon 2001/9 - JG@JGnet.co.uk
Output file: TestStuff.obj
C:\Programming\GoAsm\BIN\GoLink.EXE /entry Start  "TestStuff.obj"

GoLink.Exe Version 0.26.10 beta3- Copyright Jeremy Gordon 2002/9-JG@JGnet.co.uk
Output file: TestStuff.exe
Format: X64 size: 2,048 bytes

Make finished.
Total compile time 235 ms
"Ahhh, what an awful dream. Ones and zeroes everywhere...[shudder] and I thought I saw a two." -- Bender
"It was just a dream, Bender. There's no such thing as two". -- Fry
-- Futurama

Donkey's Stable

ecube

I been converting some of my 32bit masm code to 64bit in GoASM the last few hours and I must say it's been a real pleasure!

the inline text support for functions
invoke messagebox,0,'neat0',etc..

the direct callin with invoke such as
invoke getprocaddr,rax,'whatever'
invoke rax,etc <---

the prototype less function fram
blah frame param1,param2

ret
endf

is all great! its stuff I wish MASM did by default, the only thing missing is the .IF,.ELSEIF,.ELSE,.ENDIF, I hope Jeremy adds them, so I can start converting my 32bit source full on!

also donkey invoke wsprintfA works fine directly, no need for a special macro.

also whats the switch in windows.h that I can set the global path like all includes in
\GoASM\Includes\

can GoASM produce 64bit static link libraries?

donkey

Quotealso donkey invoke wsprintfA works fine directly, no need for a special macro.

I should have mentioned that the macro is for 32 bit only, wsprintf uses FASTCALL in WIN64. I did not restrict it to 32 bit mode because there is a chance that you might want to write a CDECL function for yourself and use it, I have a couple of functions that are CDECL that I may eventually convert to WIN64 without bothering to convert to FASTCALL.
"Ahhh, what an awful dream. Ones and zeroes everywhere...[shudder] and I thought I saw a two." -- Bender
"It was just a dream, Bender. There's no such thing as two". -- Fry
-- Futurama

Donkey's Stable

donkey

Hi E^cube,

Wait til you see the real power of GoAsm invoke, no more GetProcAddress except for delay loads...

// call the "Whatever" function in SomeDll.dll
invoke SomeDll.dll:Whatever, param1, param2

// include the "Whatever" function from a static lib and call it
invoke SomeLib.lib:Whatever, param1, param2

// Call ordinal 2 in a DLL
invoke SomeDll.dll:2 , param1, param2

GoAsm invoke is much more powerful than you are used to as a MASM user.

Using #dynamiclinkfile you can skip the SomeDll.dll for named functions (without conflicts):

#dynamiclinkfile SomeDll.dll
invoke Whatever, param1, param2

And you can even use RichEdit without LoadLibrary since exported data is also accessible:

#dynamiclinkfile RichEd20.dll
// Touch the DLL to force it to be mapped
mov eax,[IID_ITextHost2] // IID exported by RichEd20.dll

GoAsm can produce OBJ files that can be used by MS lib.exe or PoLib.exe to create a static library however there is no lib compiler in GoTools.
"Ahhh, what an awful dream. Ones and zeroes everywhere...[shudder] and I thought I saw a two." -- Bender
"It was just a dream, Bender. There's no such thing as two". -- Fry
-- Futurama

Donkey's Stable

ecube

wow thanks donkey, I must admit when I first seen your library a long time ago with the strings, files etc I got raged and thought to myself "why the hell is coding in this Goasm stuff" as I had to convert to Masm. But more I learn about GoAsm, the more i'm convinced that it's very close to being superior.The .if stuff is the only thing holding it back, everything else is golden :D With the recent MASM64 release it's clear Microsoft is saying sh*t on the ASM community, so they've lost my support. Also how do I

#include \GoAsm\include\windows.h

make goasm not complain about being unable to find that? I looked for a global switch/path in various .h's, didn't see it. any hints?

donkey

GoAsm is written by an assembly language programmer who uses it, MASM is written by a committee of C++ programmers who don't. As is evidenced here, its nice to have the author listen to your concerns and act on them, bugs don't have a long lifespan in GoAsm, it can be years in MASM.

Quote from: E^cube on March 31, 2009, 01:54:43 AM
Also how do I

#include \GoAsm\include\windows.h

make goasm not complain about being unable to find that? I looked for a global switch/path in various .h's, didn't see it. any hints?

I'm not sure what you mean here, there should be no absolute paths in the header project, generally you would simply use

#include windows.h

the include environment variable takes care of the paths. For stuff like GdiPlus there are relative paths to the sub folder but that is the extent of path dependency. In your case the include variable should be:

INCLUDE= C:\GoAsm\include

From there everything should work.
"Ahhh, what an awful dream. Ones and zeroes everywhere...[shudder] and I thought I saw a two." -- Bender
"It was just a dream, Bender. There's no such thing as two". -- Fry
-- Futurama

Donkey's Stable