News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

Fasm and MasmBasic

Started by clamicun, April 25, 2017, 07:42:31 AM

Previous topic - Next topic

clamicun

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

??

clamicun

I think this one is better

jj2007

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
  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 and Launch$() offer, and try do the same in FASM. Start with this simple example:

include \masm32\MasmBasic\MasmBasic.inc      ; download
  Init
  Inkey "Current time is ", Launch$("cmd /c time /t")
EndOfCode

mineiro

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?
I'd rather be this ambulant metamorphosis than to have that old opinion about everything

hutch--

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.

hutch--

 :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

jj2007

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?):
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. 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)

hutch--

 :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.

clamicun

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 ,... 

jj2007

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.

clamicun

btw. jj,

mysql_start_masm.asc

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

jj2007

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...

LordAdef

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.



clamicun

*** 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 ***

jj2007

Quote from: clamicun on April 25, 2017, 09:18:45 PM
*** MasmBasic version 09.01.2017 ***

Uuuuuralt! Reinstall the current version, and it will work.