The MASM Forum Archive 2004 to 2012
Welcome, Guest. Please login or register.
November 23, 2019, 02:06:47 AM

Login with username, password and session length
Search:     Advanced search
128553 Posts in 15254 Topics by 684 Members
Latest Member: mottt
* Home Help Search Login Register
+  The MASM Forum Archive 2004 to 2012
|-+  General Forums
| |-+  The Workshop
| | |-+  MasmBasic
« previous next »
Pages: [1] 2 3 ... 21 Print
Author Topic: MasmBasic  (Read 143429 times)
jj2007
Member
*****
Gender: Male
Posts: 6011



MasmBasic
« on: October 06, 2009, 08:24:57 PM »

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 Cool

So what exactly is MasmBasic?

Quote
include \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 BigGrin) 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:

Quote
include \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:
Quote
Converting 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

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

Let me know who is missing BigGrin

Alphabetical list of available commands (March 2012 - many string functions now have a wide aka Unicode variant):
Quote
App16, 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
« Last Edit: May 23, 2012, 02:03:16 PM by jj2007 » Logged

dedndave
Member
*****
Posts: 12523


Re: MasmBasic
« Reply #1 on: October 06, 2009, 09:02:10 PM »

very nice Jochen - i wondered what you were working on - lol   ThumbsUp
let me play with it a while
Logged
hutch--
Administrator
Member
*****
Posts: 12013


Mnemonic Driven API Grinder


Re: MasmBasic
« Reply #2 on: October 06, 2009, 11:00:02 PM »

JJ,

Looks good.  ThumbsUp

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

Regards,



Download site for MASM32
http://www.masm32.com
jj2007
Member
*****
Gender: Male
Posts: 6011



Re: MasmBasic
« Reply #3 on: October 06, 2009, 11:23:36 PM »

JJ,

Looks good.  ThumbsUp

Thanks BigGrin

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

newAsm
Member
**
Posts: 49


Re: MasmBasic
« Reply #4 on: October 07, 2009, 02:40:34 AM »

Hi jj2007,

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

Thanks..newAsm
Logged
sinsi
Member
*****
Gender: Male
Posts: 1758


RIP Bodie 1999-2011


Re: MasmBasic
« Reply #5 on: October 07, 2009, 02:59:16 AM »

"You are not allowed to access this section"
Sad
Logged

Light travels faster than sound, that's why some people seem bright until you hear them.
dedndave
Member
*****
Posts: 12523


Re: MasmBasic
« Reply #6 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
Logged
BlackVortex
Member
*****
Posts: 983



Re: MasmBasic
« Reply #7 on: October 07, 2009, 03:19:11 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 "

 Tongue
Logged
dedndave
Member
*****
Posts: 12523


Re: MasmBasic
« Reply #8 on: October 07, 2009, 03:20:47 AM »

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
Logged
BlackVortex
Member
*****
Posts: 983



Re: MasmBasic
« Reply #9 on: October 07, 2009, 04:42:16 AM »

It doesn't work for Sinsi either, so ...
Logged
sinsi
Member
*****
Gender: Male
Posts: 1758


RIP Bodie 1999-2011


Re: MasmBasic
« Reply #10 on: October 07, 2009, 05:03:55 AM »

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  redface
But jj, your friend drunk_sinsi is annoyed Cool
Logged

Light travels faster than sound, that's why some people seem bright until you hear them.
BlackVortex
Member
*****
Posts: 983



Re: MasmBasic
« Reply #11 on: October 07, 2009, 05:09:03 AM »

Logged
MichaelW
Global Moderator
Member
*****
Gender: Male
Posts: 5161


Re: MasmBasic
« Reply #12 on: October 07, 2009, 05:24:41 AM »

A direct download link provides no context.
Logged

eschew obfuscation
BlackVortex
Member
*****
Posts: 983



Re: MasmBasic
« Reply #13 on: October 07, 2009, 06:01:39 AM »

A direct download link provides no context.
And what does a broken direct link provide ?    Tongue

Anyway, the archive contains documentation, too.
Logged
jj2007
Member
*****
Gender: Male
Posts: 6011



Re: MasmBasic
« Reply #14 on: October 07, 2009, 08:16:46 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
Logged

Pages: [1] 2 3 ... 21 Print 
« previous next »
Jump to:  

Powered by MySQL Powered by PHP The MASM Forum Archive 2004 to 2012 | Powered by SMF 1.0.12.
© 2001-2005, Lewis Media. All Rights Reserved.
Valid XHTML 1.0! Valid CSS!