The MASM Forum

General => The Workshop => Topic started by: clamicun on April 25, 2017, 07:42:31 AM

Title: Fasm and MasmBasic
Post by: clamicun on April 25, 2017, 07:42:31 AM
2 progs.
They do exactely the same job. Checking for mysld.exe and start it, if it doesn't run.

One written for  flat assembler.
The other for  MasmBasic.

Flat assembled exe has 3 KB
Masm assembled exe 27 KB

??
Title: Re: Fasm and MasmBasic
Post by: clamicun on April 25, 2017, 08:01:12 AM
I think this one is better
Title: Re: Fasm and MasmBasic
Post by: jj2007 on April 25, 2017, 08:26:22 AM
I plead guilty: MasmBasic is bloated! But it does in a handful of lines what needs over 100 lines in FASM.

include \masm32\MasmBasic\MasmBasic.inc      ; download (http://masm32.com/board/index.php?topic=94.0)
  Init
  .if !FindProcess("mysqld.exe")
      Launch "mysld.exe", SW_MINIMIZE, 1
      .if ExitCode()==STILL_ACTIVE
            Inkey "congrats"
      .else
            Inkey "something went wrong: ", Err$()
      .endif
  .else
      Inkey "already running"
  .endif
EndOfCode


It's called overhead. MasmBasic is assembler, but it offers lots of functions that often depend on each other, and therefore cannot be separated as neatly as e.g. the Masm32 library. So you get roughly 20kB as the minimum exe size. That is not much compared to the 8 MB of a QT Hello World proggie, but I understand of course that those who are chasing the smallest possible executable aren't happy about it.

Check what Launch (http://www.webalice.it/jj2006/MasmBasicQuickReference.htm#Mb1045) and Launch$() (http://www.webalice.it/jj2006/MasmBasicQuickReference.htm#Mb1047) offer, and try do the same in FASM. Start with this simple example:

include \masm32\MasmBasic\MasmBasic.inc      ; download (http://masm32.com/board/index.php?topic=94.0)
  Init
  Inkey "Current time is ", Launch$("cmd /c time /t")
EndOfCode
Title: Re: Fasm and MasmBasic
Post by: mineiro on April 25, 2017, 10:06:16 AM
Quote from: jj2007 on April 25, 2017, 08:26:22 AM
That is not much compared to the 8 MB of a QT Hello World proggie, but I understand of course that those who are chasing the smallest possible executable aren't happy about it.
hello sir jj;
well sir, how to reach portability without that?
You're talking from a windows point of view, a linux point of view is about somebody that can have qt+gtk by default on their systems, so, executable size is not a problem.
Qt is doing a very good job, this is why many programs are turned to Qt these days, one that gets out gtk+ and turned into qt was wireshark, lets pray to mozilla don't turn to qt?
Title: Re: Fasm and MasmBasic
Post by: hutch-- on April 25, 2017, 11:18:45 AM
RE : The posted examples, do your comparison with the 2 assemblers, not an assembler against emulated basic. FASM is a good tool but MASM is also a good tool if you know how to write it. To make the comparison you need to write a MASM example.
Title: Re: Fasm and MasmBasic
Post by: hutch-- on April 25, 2017, 06:42:22 PM
 :biggrin: Now you will have to be careful with this 1.5k bloated pig, its written in pure MASM.  :P


; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    include \masm32\include\masm32rt.inc
; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

    .code
      nmfile db "mysqld.exe",0
      mbtext db "Sorry, can't find that file",0
      mbtitl db "Error",0

start:
   
; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

    call main
    exit

; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

main proc

    invoke WinExec,OFFSET nmfile,1

    .if eax == ERROR_FILE_NOT_FOUND || eax == ERROR_PATH_NOT_FOUND
      invoke MessageBox,0,OFFSET mbtext,OFFSET mbtitl,MB_OK
      ret
    .endif

  ; ---------------------------
  ; do what you want to do here
  ; ---------------------------

    ret

main endp

; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

end start


This is "makeit.bat"


@echo off

if not exist rsrc.rc goto over1
\masm32\bin\rc /v rsrc.rc
\masm32\bin\cvtres /machine:ix86 rsrc.res
:over1

if exist "masmver.obj" del "masmver.obj"
if exist "masmver.exe" del "masmver.exe"

\masm32\bin\ml /c /coff "masmver.asm"
if errorlevel 1 goto errasm

if not exist rsrc.obj goto nores

\masm32\bin\PoLink /SUBSYSTEM:WINDOWS /OPT:NOREF "masmver.obj" rsrc.res
if errorlevel 1 goto errlink

dir "masmver.*"
goto TheEnd

:nores
\masm32\bin\PoLink /SUBSYSTEM:WINDOWS /OPT:NOREF "masmver.obj"
if errorlevel 1 goto errlink
dir "masmver.*"
goto TheEnd

:errlink
echo _
echo Link error
goto TheEnd

:errasm
echo _
echo Assembly Error
goto TheEnd

:TheEnd

pause
Title: Re: Fasm and MasmBasic
Post by: jj2007 on April 25, 2017, 07:07:04 PM
Quote from: mineiro on April 25, 2017, 10:06:16 AMYou're talking from a windows point of view

If QT was really portable, then there would be no "Windows point of view". It would simply run on Windows. Which seems to be a major challenge (What programming language was Skype originally written in? (https://www.quora.com/What-programming-language-was-Skype-originally-written-in)):
Quotethe result looked like crap, our progress seemed slow and we ditched the QT about 2 months before public beta release

So much about the "good job" 8)

Quote from: mineiro on April 25, 2017, 10:06:16 AMhow to reach portability without that?

You may have noted that HJWasm can produce executables for Windows and Linux. Test it, use something really, really simple like this:
windows=1  ; a switch
if windows
  include \masm32\include\masm32rt.inc
else
  include \whatever\linuxstuff.inc
endif
.code
start:
if windows
  invoke MessageBox, 0, chr$("It works..."), chr$("Hello World"), MB_OK
  exit
else
  ... put the Linux equivalent to MessageBox here ... *)
  ... put the Linux equivalent to ExitProcess here ...
endif
end start


Portable, mineiro!!! And it doesn't need 8 MB. I could test it only under Windows, it assembles to 1,536 bytes 8)

*) Little warning: Finding this might not be as trivial as it looks! Prepare an Aspirine and a glass of water, and try to read (C++) MessageBox for Linux like in MS Windows (http://stackoverflow.com/questions/1384125/c-messagebox-for-linux-like-in-ms-windows). For giggles:
QuoteHere is my solution. I chose to use Motif (OpenMotif) as it requires comparably few extra libraries (Xm, Xt, X11). Depending on the message size, my implementation opens a simple message box


Btw Hutch is right, compare assemblers, not libraries - this produces a 1024 byte exe, see attachment:
include \masm32\include\masm32rt.inc ; pure Masm32

.code
start:

    .if rv(WinExec, "mysqld.exe", 1) == ERROR_FILE_NOT_FOUND || eax == ERROR_PATH_NOT_FOUND
MsgBox 0, "Sorry, can't find that file", "Error:", MB_OK
    .else
; ---------------------------
; do what you want to do here
; ---------------------------
    .endif

    exit
end start


Now, I have a CHALLENGE to the FASM crew - reproduce only this tiny element in FASM if you can:
.if rv(WinExec, "mysqld.exe", 1) == ERROR_FILE_NOT_FOUND

You will fail miserably, but give it a try, please, and be honest enough to confess that FASM can't even do such simple things 8)
Title: Re: Fasm and MasmBasic
Post by: hutch-- on April 25, 2017, 07:17:42 PM
 :biggrin:

You don't need to issue a challenge to the FASM folks, there is no-one here competent to take up the challenge but you can be sure that FASM is a very competent tool in the right hands. Tomas was not aiming at the high level emulation that MASM routinely does which is fair enough, the target was a lower level form of notation.
Title: Re: Fasm and MasmBasic
Post by: clamicun on April 25, 2017, 07:32:20 PM
Everything is fine.
I am a Masm and MasmBasic fan.
I only started to play around with fasm  because of Masms problem with

invoke Process32First, ...
invoke Process32Next ,... 
Title: Re: Fasm and MasmBasic
Post by: jj2007 on April 25, 2017, 07:49:02 PM
Quote from: hutch-- on April 25, 2017, 07:17:42 PMFASM is a very competent tool in the right hands. Tomas was not aiming at the high level emulation that MASM routinely does which is fair enough, the target was a lower level form of notation.

I have no problem with FASM, really. Those who want to write a replacement for a slow C/C++ routine can do that perfectly in Masm, Fasm, Nasm, whatever - the x86 instruction set is known, and one can eventually learn the subtle differences between jle and jae etc.

Once you embark on more serious projects, though - say, 10k lines and above, "pure" assembler will become a less beautiful option. Unless you want to spend the rest of your life staring at Olly's wonderful disassembly window :biggrin:

I have a real problem with QT, though. Dumping megabytes of crappy libraries on innocent Windows users with the argument "but it's portable" is something that merits naming and shaming. Windows is a pile of s**t, sure, but if Linux can't organise a native MessageBox built into the OS, not in "somebody's favourite library", then you understand why its market share is still invisible in the pie charts.
Title: Re: Fasm and MasmBasic
Post by: clamicun on April 25, 2017, 08:01:15 PM
btw. jj,

mysql_start_masm.asc

gives an error
"Constant value too large: 6D7973716C642E657865h"
Title: Re: Fasm and MasmBasic
Post by: jj2007 on April 25, 2017, 08:06:40 PM
Quote from: clamicun on April 25, 2017, 08:01:15 PM
btw. jj,

mysql_start_masm.asc

gives an error
"Constant value too large: 6D7973716C642E657865h"

Just tested with a variety of assemblers, no such problem ::)

Which line chokes? Which MasmBasic version are you using? The FindProcess() macro was introduced months ago... (http://masm32.com/board/index.php?topic=94.msg63598#msg63598)
Title: Re: Fasm and MasmBasic
Post by: LordAdef on April 25, 2017, 09:15:50 PM
well, there is a trade with MasmBasic and it's its 20k overhead.

Just reminding that some IDEs like EasyCode also have some trade too.

If I'm not mistaken EasyCode has and overhead of 15kb.

It's a trade size vs features.


Title: Re: Fasm and MasmBasic
Post by: clamicun on April 25, 2017, 09:18:45 PM
*** MasmBasic version 09.01.2017 ***
Tmp_File.asm(3) : Error A2273: Constant value too large: 6D7973716C642E657865h

### check your NanoTimer calls ###
Tmp_File.asm: 13 lines, 1 passes, 171 ms, 0 warnings, 1 errors
*** Assembly Error ***
Title: Re: Fasm and MasmBasic
Post by: jj2007 on April 25, 2017, 09:49:35 PM
Quote from: clamicun on April 25, 2017, 09:18:45 PM
*** MasmBasic version 09.01.2017 ***

Uuuuuralt! Reinstall the current version (http://masm32.com/board/index.php?topic=94.0), and it will work.
Title: Re: Fasm and MasmBasic
Post by: clamicun on April 25, 2017, 10:03:55 PM
Deleted MasmBasic
Installed version 24 April 17
Richmasm.exe opens a MessageBox ...Bad DLL  RichEdit20A and closes

??? My Computer ?
Title: Re: Fasm and MasmBasic
Post by: clamicun on April 25, 2017, 10:21:50 PM
Deleted MasmBasic
Installed 24 April 2017

RichMasm.exe opens a messagebox  "Bad DLL?"
                                                      "RichEdit20A"
and closes.
??? my computer ?
Title: Re: Fasm and MasmBasic
Post by: jj2007 on April 25, 2017, 10:44:51 PM
Strange. During the installation,
- did you see the big box with "Accept & install"?
- immediately after, did you see the green document titled "This help file refers to MasmBasic version 24 April 2017"?

If yes, RichMasm had no problem with the RichEd20.dll
If no, i.e. if immediately after the "Accept & install" you saw that ugly box, then I have a problem :(

Which Windows version are you using? Brazilian version of WinXX? Even so, it should find a valid \System32\RichEd20.dll ::)

Do you have C:\Program Files (x86)\Common Files\microsoft shared\OfficeXX folders?

Btw no need to delete the MasmBasic folder. The re-installation does not overwrite any valuable files.
Title: Re: Fasm and MasmBasic
Post by: clamicun on April 26, 2017, 12:19:45 AM
Strange. During the installation,
- did you see the big box with "Accept & install"?

YES

- immediately after, did you see the green document titled "This help file refers to MasmBasic version 24 April 2017"?

NO

If yes, RichMasm had no problem with the RichEd20.dll
If no, i.e. if immediately after the "Accept & install" you saw that ugly box, then I have a problem :(

Which Windows version are you using? Brazilian version of WinXX? Even so, it should find a valid \System32\RichEd20.dll ::)

Win7Ultimate

Do you have C:\Program Files (x86)\Common Files\microsoft shared\OfficeXX folders?

Thats what I have ... C:\Program Files\Common Files\microsoft shared\ ....

Installs perfectly but when it starts the mentioned messagebox appears ...

No way to use it
Title: Re: Fasm and MasmBasic
Post by: clamicun on April 26, 2017, 01:12:54 AM
Now I installed the April version but use the old RichMasm.exe from janary ... everything works
Title: Re: Fasm and MasmBasic
Post by: felipe on April 26, 2017, 01:26:09 AM
Quote from: hutch-- on April 25, 2017, 06:42:22 PM
:biggrin: Now you will have to be careful with this 1.5k bloated pig, its written in pure MASM.  :P

; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    include \masm32\include\masm32rt.inc
; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

    .code
      nmfile db "mysqld.exe",0
      mbtext db "Sorry, can't find that file",0
      mbtitl db "Error",0

start:
   
; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

    call main
    exit

; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

main proc

    invoke WinExec,OFFSET nmfile,1

    .if eax == ERROR_FILE_NOT_FOUND || eax == ERROR_PATH_NOT_FOUND
      invoke MessageBox,0,OFFSET mbtext,OFFSET mbtitl,MB_OK
      ret
    .endif

  ; ---------------------------
  ; do what you want to do here
  ; ---------------------------

    ret

main endp

; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

end start

I know this code it's trivial for you, but i come from assembly real mode programming in ms-dos and i'm learning to do assembly programming in 32 bits since a couple of months. But i want to say that this code it's both: illustrative and really good.  Thanks for sharing again!  :t :eusa_boohoo:

Title: Re: Fasm and MasmBasic
Post by: hutch-- on April 26, 2017, 01:45:24 AM
Hi felipe,

You will find that once you get used to what this stuff looks like that its both simpler and a lot cleaner than the old real mode DOS. The FLAT memory model means no segment/offset, just linear addressing, instead of interrupts you just call system functions which is what the API functions are. The real fun though is still in pure mnemonic code and here you have a wider range of instructions, less restrictions and a lot more power.
Title: Re: Fasm and MasmBasic
Post by: jj2007 on April 26, 2017, 02:19:02 AM
Quote from: clamicun on April 26, 2017, 01:12:54 AM
Now I installed the April version but use the old RichMasm.exe from janary ... everything works

Great, but that doesn't solve the mystery :biggrin:

Can you do me a favour and copy the console messages which the attached test version will throw?
Just extract ReTest.exe to the same folder as RichMasm.exe, i.e. \Masm32\MasmBasic\ReTest.exe, run it, switch to the console, maximise it and copy the text (see Copy To the Clipboard From the Windows Command Prompt (https://www.howtogeek.com/howto/windows-vista/copy-to-the-clipboard-from-the-windows-command-prompt/)).

You should get something like
LoadRich: RE-used []

Expanded
eax             75
ecx             0
$esi            C:\Program Files (x86)\Common Files\Microsoft shared\Office1?\RichEd20.dll
$ebx            ?\RichEd20.dll

out
flags:          czSo
$esi            C:\Program Files (x86)\Common Files\Microsoft shared\Office11\RichEd20.dll
$ebx            1\RichEd20.dll

used
flags:          cZso
$esi            C:\Program Files (x86)\Common Files\Microsoft shared\Office11\RichEd20.dll
GetInfo correction for MainX=0
Title: Re: Fasm and MasmBasic
Post by: felipe on April 26, 2017, 02:29:20 AM
Hutch:
I'm aware now of the high level capacity of masm (ml) like in using .if or similars, for example. And i have been learning all the differences between the 8086 and the 386 (as a base starting point) architectures. But, yes, the differences between: a) The int instructions in real mode programming and the bios functions or even the dos functions, and, b)The windows api functions is what takes me more time to get. That's why this kind of code it's illustrative for me, because i'm learning the rules to call this functions from the assembly program.  :dazzled:... :lol:
Title: Re: Fasm and MasmBasic
Post by: clamicun on April 26, 2017, 03:09:02 AM
LoadRich: RE-used []

Expanded
eax             69
ecx             0
$esi            C:\Program Files\Common Files\Microsoft shared\Office1?\RichEd20
.dll
$ebx            ?\RichEd20.dll

out
flags:          cZso
$esi            C:\Program Files\Common Files\Microsoft shared\Office1
$ebx

used
flags:          cZso
$esi            C:\Program Files\Common Files\Microsoft shared\Office1
Title: Re: Fasm and MasmBasic
Post by: jj2007 on April 26, 2017, 04:18:23 AM
Thanks, very helpful :icon14:
Is that a 32-bit OS? I would have expected C:\Program Files (x86)\ ::)

Attached another debug version.
Title: Re: Fasm and MasmBasic
Post by: nidud on April 26, 2017, 06:06:56 AM
deleted
Title: Re: Fasm and MasmBasic
Post by: jj2007 on April 26, 2017, 06:17:42 AM
Yes indeed. I use this:

txOffice db "%CommonProgramFiles%\Microsoft shared\Office1?\RichEd20.dll", 0
Title: Re: Fasm and MasmBasic
Post by: clamicun on April 26, 2017, 06:43:27 AM
32bit

RichEd20.dll requested (0=Office11 or Sys32): []

Expanded
eax             69
ecx             0
$esi            C:\Program Files\Common Files\Microsoft shared\Office1?\RichEd20
.dll
$ebx            ?\RichEd20.dll

out
flags:          cZso
$esi            C:\Program Files\Common Files\Microsoft shared\Office11\RichEd20
.dll
$ebx            1\RichEd20.dll

used
flags:          cZso
$esi            C:\Program Files\Common Files\Microsoft shared\Office11\RichEd20
.dll






Title: Re: Fasm and MasmBasic
Post by: jj2007 on April 26, 2017, 07:14:02 AM
Thanks a lot for testing this, clamicun. If the attached new version works (and it should!), I'll update the package.

RichMasm it looks in these Office folders for the best version of RichEd20.dll. If it can't find any (frequent case), the fallback option is Windows\System32\RichEd20.dll - old and slow but it's installed everywhere.

Unfortunately, the fallback option was completely broken - too much messing around with the other versions :(
Those who have M$ Office installed would have never noticed. But apparently, you don't have these Office folders.
Title: Re: Fasm and MasmBasic
Post by: clamicun on April 27, 2017, 02:22:41 AM
same story
messagebox

bad DLL?
RichEdit20A
Title: Re: Fasm and MasmBasic
Post by: clamicun on April 27, 2017, 02:31:58 AM
Nein

ReTest25April.exe does it  ... Opens a console window before and loads RichEdit
RichEdit.exe doesn't
Title: Re: Fasm and MasmBasic
Post by: jj2007 on April 27, 2017, 03:09:30 AM
Quote from: clamicun on April 27, 2017, 02:31:58 AMReTest25April.exe does it  ... Opens a console window before and loads RichEdit

Great, thanks for testing :icon14:

New version 26 April is online. (http://masm32.com/board/index.php?topic=94.0) As mentioned above, there is no need to disinstall MasmBasic or delete folders etc, just download & run the installer, it will detect which files need updating.
Title: Re: Fasm and MasmBasic
Post by: LordAdef on April 27, 2017, 03:23:24 AM
QuoteNew version 26 April is online.

JJ, in my case, should I update as well (I´m ok here, everything rock-solid as usual)
Title: Re: Fasm and MasmBasic
Post by: jj2007 on April 27, 2017, 03:37:11 AM
Quote from: LordAdef on April 27, 2017, 03:23:24 AM
QuoteNew version 26 April is online.

JJ, in my case, should I update as well (I´m ok here, everything rock-solid as usual)

Yes, why not. Here is a nine-liner that can help you ;)

GuiParas equ "Hurry up, get MasmBasic!!!!", w180, h48, s0
include \masm32\MasmBasic\Res\MbGui.asm
GuiControl GoOnline, "syslink", 'Click here (http://masm32.com/board/index.php?topic=94.0) to download MasmBasic'
Event Command
  .if NotifyCode==NM_CLICK && wParam==GoOnline
      wMsgBox 0, Link$(), "Open?", MB_OKCANCEL
      If_ eax==IDOK Then <wShEx Link$()>
  .endif
GuiEnd