News:

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

MasmBasic

Started by jj2007, October 06, 2009, 08:24:57 PM

Previous topic - Next topic

jj2007

23 May 2012: MasmBasic resides now in the new Masm32 Forum. See also the online list of functions.

This thread may remain online for some time, but check the new site for the latest edition :wink

(18 May: Try/Catch/Finally uses linker's mapfile to let editor jump to the line that triggered the exception)

MasmBasic is a library that allows to use BASIC syntax in assembler, i.e. it is not a "separate" language but rather a library of macros and routines, fully compatible with MASM (from version 6.15 upwards, see e.g. version 8.0), JWasm and the latest Masm32 SDK (version 11). I wrote it for my own use and pleasure, but since many forum members contributed to it, through good advice and even better algos, I think it is just fair to release it here. The usual disclaimers apply, of course - do not use for military purposes, in hospitals and anywhere else where buggy applications could cause damage. You have been warned :8)

So what exactly is MasmBasic?

Quoteinclude \masm32\MasmBasic\MasmBasic.inc

.code
start:
   GetFiles *.asc
   mov ebx, eax
   Print Str$("%i files found:", ebx), CrLf$, "No.", Tb$, "Name"
   For_ n=0 To ebx-1
      Print Str$("\n#%i\t", n+1), Files$(n)
   Next
   Exit

end start

This snippet (by the way: a full-fledged Windows application :bg) gives the following output:
Quote
50 files found:
No.     Name
#1      BCD.asc
#2      CallDLL.asc
...
#49     TinyRTF.asc
#50     VirtualAllo.asc

As the example shows,
    1. MasmBasic is not BASIC: mov ebx, eax is not part of any BASIC dialect.
    2. MasmBasic is assembly, i.e. it will flawlessly assemble with Microsoft Macro Assembler (MASM, version 6.15 upwards) or, alternatively, with Jwasm

Here is a more complex application. This snippet opens Windows.inc, converts all hexadecimal equates into decimal ones, and writes it back to disk:

Quoteinclude \masm32\MasmBasic\MasmBasic.inc

.code
start:   call Convert
   Exit

Convert proc
LOCAL pos, posAfter, MyTimer, MyCounter
  and MyCounter, 0
  mov MyTimer, Timer
Recall "\Masm32\include\Windows.inc", L$()   ; load an array of strings from file
  mov ebx, eax
  For_ n=0 To ebx-1
   mov pos, Instr_(1, L$(n), "equ", 5)      ; start in pos 1, 1=case-insensitive + 4=full word
   .if pos
      mov esi,
Val(Mid$(L$(n), pos+3, 99))   ; get the numeric value of the string behind equ
      .if signed edx<0                     ; edx returns the number of usable chars; a
         neg edx                        ; negative number indicates a hex$ or bin$ was found
         add edx, pos
         add edx, 3
         mov posAfter, edx
         inc MyCounter
         
Let L$(n)=Left$(L$(n), pos-1)+"EQU "+Str$(esi)+Mid$(L$(n), posAfter)
      .endif
   .endif
  Next
Store "MyWindows.inc", L$()      ; write all strings back to file
  sub MyTimer, Timer
 
Print Str$("\nConverting %i hex equates in Windows.inc to decimals", MyCounter), Str$(" took %i ms\n", 0-MyTimer)
  ret
Convert endp

end start


Output:
QuoteConverting 7676 hex equates in Windows.inc to decimals took 31 ms

MasmBasic comes with RichMasm: Download the archive at the bottom of this post, and extract it to the root of your Masm32 folder with the "use folder names" option. The editor is configured to give context-sensitive help with the F1 key, and to expand many instructions. For example,
opo [space] will expand to Open "O", #1,
mb becomes MsgBox 0, "¨", "Hi", MB_OK
for_ becomes For_ n=0 To ebx-1 ... Next
ism becomes invoke SendMessage,
etc.; more in \masm32\MasmBasic\MbGuide.rtf (in RichMasm:  File/MasmBasic Guide)

Last but not least an ultra-short Win32 application :wink

include \masm32\MasmBasic\MasmBasic.inc
Init
Credits
Exit
end start


Let me know who is missing :bg

Alphabetical list of available commands (March 2012 - many string functions now have a wide aka Unicode variant):
QuoteApp16, wArrayFill, ArrayMinMax, ArraySearch, ArraySort, Asc, Bin$, Chr$, CL$, wCL$, CatchRTE, ClearLocalVariables, wClip$(), HtmlClip$, Clr, Clr$, ConsoleColor, Copy, CopyData$, Count/wCount, CurDir$, CreateInvoke, CrtDate$, CrtTime$, Cvi, Cvl, Date$, deb, Declare, DefNum, Delete, Dim My$(a, b), Dim MyStruc(99) As RECT, Dim MyDword(x) As DWORD etc, Dll, Erase, Err$, ErrLines, SetErrLine, ExeFolder$, Exist, Exit, ExpandEnv$, Fcmp, FileRead$, FilesDiffer, For_ .. Next, Fsign, GetField, GetFiles, GfSize, GfDate$, GfTime$, GfAgexxx, GetRegVal, gsl, gsl_INIT, gsl_EXIT, Hex$, ImgPaint, Inkey, Input, Insert, Instr_, Kill, LastFileDosName, LastFileName, LastFileSize, Launch, Left$, Len, Let, Locate, Lower$, Ltrim$, Max, Mid$, Min, Mirror$, MouseK, MouseX, MouseY, MovVal, NanoTimer, New$, Open I/O/A/U, PopCount, Print, Print #n, PrintCpu, PrintLine, QSort, QSortDesc, Rand, Recall, Rename, Replace$, Res$(), Right$, Rinstr, Rtrim$, Seek, SendData, wSetClip$, SetField, SetRegVal, Space$, Sqrt, Store, wStr$, String$, StringsDiffer, Swap, ToolTips, Trim$, UnZipFiles, Upper$, Val, Win$()/SetWin$, WinByTitle, wChr$, wData, wInstr, wLeft$/wMid$/wRight$, wLen, wLet, wLower$/wUpper$, wMsgBox, wPrint #n, wRes$, SendControlKey, SetHtmlClip$, wSetWin$, Try/Catch, ZipFiles

Archive moved to the new Masm32 Forum

dedndave

very nice Jochen - i wondered what you were working on - lol   :U
let me play with it a while

hutch--

JJ,

Looks good.  :thumbu

It makes sense to remove a lot of the non-critical hack work so thatwork can be pointed at the type of code that takes time to develop properly.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

jj2007

Quote from: hutch-- on October 06, 2009, 11:00:02 PM
JJ,

Looks good.  :thumbu

Thanks :bg

Quote
It makes sense to remove a lot of the non-critical hack work so that work can be pointed at the type of code that takes time to develop properly.

You hit the nail on the head - that's what I intended with this library. Much of this can also be done with Masm32, of course. I chose the Basic syntax because almost everybody with a basic (pun intended) knowledge can intuitively grasp what the above code does. And I tried to keep it newbie-friendly, with boundary checks and runtime error messages etc. This is version 0.9, so to speak. I had a lot of spare time in my holidays, so I could finally complete what was built up over time in The Laboratory. It seems almost bug-free now, but here and there I'll have to polish things. For example, the 200 ms for converting Windows.inc are 95% due to a slow Store L$() routine that writes string by string to a file...

newAsm

Hi jj2007,

Is masmbasic.inc available as there is no attachment of it in the forum?

Thanks..newAsm

sinsi

"You are not allowed to access this section"
:(
Light travels faster than sound, that's why some people seem bright until you hear them.

dedndave

newasm - he updated the d/l
at one point, it did not have the masmbasic folder
it is straightened out, now
here is the d/l link...
http://www.masm32.com/board/index.php?action=dlattach;topic=9044.0;id=6739

BlackVortex

Quote from: dedndave on October 07, 2009, 03:16:13 AM
newasm - he updated the d/l
at one point, it did not have the masmbasic folder
it is straightened out, now
here is the d/l link...
http://www.masm32.com/board/index.php?action=dlattach;topic=9044.0;id=6739
Orly ?

"You are not allowed to access this section "

:P

dedndave

i accessed it with no problems
maybe you have violated the terms of the agreement   :lol
or perhaps you have downloaded your daily limit of thunder and glory for today - lol

BlackVortex

It doesn't work for Sinsi either, so ...

sinsi

OK, I had to go to topic 9044 (richmasm), first post and download the attachment from there. link wtf I guess...
http://www.masm32.com/board/index.php?topic=9044.45

edit: I'll admit it - the code with 'Credits' in it made me want to look  :red
But jj, your friend drunk_sinsi is annoyed :8)
Light travels faster than sound, that's why some people seem bright until you hear them.


MichaelW

A direct download link provides no context.
eschew obfuscation

BlackVortex

Quote from: MichaelW on October 07, 2009, 05:24:41 AM
A direct download link provides no context.
And what does a broken direct link provide ?    :P

Anyway, the archive contains documentation, too.

jj2007

Quote from: dedndave on October 07, 2009, 03:16:13 AM
newasm - he updated the d/l
at one point, it did not have the masmbasic folder
it is straightened out, now
here is the d/l link...
http://www.masm32.com/board/index.php?action=dlattach;topic=9044.0;id=6739

Hi Dave et al,

> at one point, it did not have the masmbasic folder
That seems to be a cache problem - you probaby got an old version of the archive. Yesterday night's version has MasmBasic.inc of 7 October, 56851 bytes. Hitting Control F5 usually forces a reload, but I am not sure if that applies to attachments, too. It seems a frequent problem with the Forum software.

> You are not allowed to access this section
I got the same message now that I am logged in on a different PC. It seems the Forum software allows that kind of direct access only with special tricks; so I took the link away (as Michael noted, it might also be confusing), but for legal reasons users will still have to download it together with RichMasm.

@sinsi: drunk_sinsi was not included in the credits because for obvious reasons he was not able to make any valuable contributions to this library:green