The MASM Forum

Projects => Rarely Used Projects => GoAsm => Topic started by: bartc on April 29, 2017, 06:09:33 AM

Title: Nasm to Goasm
Post by: bartc on April 29, 2017, 06:09:33 AM
I've been using Nasm as a compiler target for years, but now want to try Goasm.

Is there a summary somewhere of the differences in syntax?

(And, more importantly, do I have to research a bunch of history facts every time I post?!)
Title: Re: Nasm to Goasm
Post by: bartc on April 29, 2017, 08:49:35 PM
In the absence of just a simple list of how to do labels, memory accesses, imports, exports etc, I'm just trying trial and error. I tried this program:

CODE SECTION
main:

sub RSP,8
sub RSP,32
mov RCX,addr KK1
call puts
add RSP,32
mov EAX,0
sub RSP,32
call exit

DATA SECTION

;string table:
KK1: db 'Hello World!',10,0


It was compiled with:

    goasm /x64 hello.asm64

And linked with:

    golink /entry main hello.obj \windows\system32\msvcrt.dll

It produces a 2KB file hello.exe which runs, but doesn't show any output. Anyone know what's wrong my the code?

Also, I understand that the label KK1 is automatically exported, so might clash with the same label used in another module. How to define a label that is local to this file?

Thanks.
Title: Re: Nasm to Goasm
Post by: TWell on April 29, 2017, 10:52:49 PM
missing option /console
Title: Re: Nasm to Goasm
Post by: jj2007 on April 29, 2017, 11:18:52 PM
Quote from: bartc on April 29, 2017, 08:49:35 PM
In the absence of just a simple list of how to do labels, memory accesses, imports, exports etc, I'm just trying trial and error.

If you chose "plain" Masm instead of GoAsm, you would find plenty of material in \Masm32\examples
Here is one:include \masm32\include\masm32rt.inc ; plain Masm32 for the fans of pure assembler

.code
AppName db "Masm32:", 0

start: MsgBox 0, "Hello World", addr AppName, MB_OK
exit

end start


Check also What you absolutely need to get started (http://www.webalice.it/jj2006/Masm32_Tips_Tricks_and_Traps.htm). And maybe you could post a few explanations what you intend to do.

Re code not showing output, Nidud told you already about the linker option. Some simpler editors do not autodetect the subsystem, so you need to set it manually, e.g. via a menu "build as console app" or similar.
Title: Re: Nasm to Goasm
Post by: shankle on April 30, 2017, 12:59:39 AM
My 2 cents worth-----
Are you using the 32 bit or 64-bit compiler?
It does make a difference.
Title: Re: Nasm to Goasm
Post by: wjr on April 30, 2017, 02:48:09 AM
In the GoAsm Manual index under "adapting files for GoAsm" you will see a list of the changes that the tool AdaptAsm can do, and another list with details on the remaining items to check or convert.

As for local labels, there are various methods for local code labels and stack based data labels, but correct, for DATA and CONST labels, these symbols will be available for external use.

However, for the example that you used, the KK1 label is used for a string that may only get used once. For something like this, if you used INVOKE with the actual string as a parameter, GoAsm will put the null terminated string in the CONST section if there is one (or DATA, or lastly CODE) and take care of passing the proper address to this string.
Title: Re: Nasm to Goasm
Post by: bartc on April 30, 2017, 05:17:45 AM
Quote from: TWell on April 29, 2017, 10:52:49 PM
missing option /console
That did the trick, thanks.

But a problem has come up which I can't explain. If I create a new program hello.asm64 (generated from my compiler) like this:
...
And actually, while trying to paste the code, I've think I've just seen the cause. The compiler generates asm code with LF line endings only. GoAsm doesn't like it, but it just says this:

Error!
No code or data found in assembler source file
OBJ file not made

If I made any change with my text editor, even nothing at all, just saving the same text, it would appear to fix it. But my editor writes CRLF. GoAsm doesn't mind CR only, but then my editor doesn't like it! So it'll have to be CR,LF.