Author Topic: MasmBasic  (Read 253711 times)

rrr314159

  • Member
  • *****
  • Posts: 1382
Re: MasmBasic
« Reply #225 on: March 03, 2015, 11:49:01 AM »
Do u realize the last 12 posts in this thread are yours? Figured I'd break your streak :)

But also it's interesting you're using float instead of integer in the for-next loop, because I've just done the similar thing with timing macros. I'll soon post a "faster" 32-bit algo in the laboratory - this time using MichaelW's timers, everything "by the book", but with "massively parallel" use of xmm registers. I'd gotten used to returning 64-bits from the rdtsc call and couldn't stand being confined to 32-bits again (1 second vs. 100 years) so wrote a 32-bit version of timers using REAL8 to hold the rdtsc result. Works fine, it's fast enough, this way you can add, average print out etc the timing figures easily.

Anyway, c u later!
I am NaN ;)

jj2007

  • Moderator
  • Member
  • *****
  • Posts: 9733
  • Assembler is fun ;-)
    • MasmBasic
Re: MasmBasic
« Reply #226 on: March 03, 2015, 12:19:40 PM »
Thanks for the heads up ;-)

I posted a float example because that's new - integers always worked.

Re rdtsc, printing a qword is not a big deal:

include \masm32\MasmBasic\MasmBasic.inc      ; download
  Init
  rdtsc
  Print Str$("TSC=%i\n", edx::eax)
  invoke Sleep, 1
  rdtsc
  Print Str$("TSC=%i\n", edx::eax)
  Exit
end start


The problems with rdtsc are elsewhere. M$ suggests QueryPerformanceCounter instead, which is under the hood of NanoTimer().

jj2007

  • Moderator
  • Member
  • *****
  • Posts: 9733
  • Assembler is fun ;-)
    • MasmBasic
Prompt$
« Reply #227 on: March 04, 2015, 10:32:12 AM »
Sometimes I need a prompt asking for input from a console app. Version 4 March has it:

include \masm32\MasmBasic\MasmBasic.inc      ; download
  Init
  Let esi=NoTag$(FileRead$("http://masm32.com/board/index.php?action=unread;all;start=0"))
  Print "[", Prompt$("Type something, please:", esi), "]"
  Exit
end start

See Input$() for comparison.

Other changes: For... Next loops with float counters act now, like their integer equivalents, rejecting if start>end.

P.S.: Version 9 March fixes a minor issue with UnzipFile.
« Last Edit: March 09, 2015, 12:50:17 PM by jj2007 »

jj2007

  • Moderator
  • Member
  • *****
  • Posts: 9733
  • Assembler is fun ;-)
    • MasmBasic
Re: MasmBasic
« Reply #228 on: March 16, 2015, 11:49:08 AM »
Version 16 March 2015 has improvements under the hood. Inter alia, Recall can now read files directly from the Internet, including csv and tab-delimited files. Unix format (i.e. LF only) will automatically be recognised, Unicode files are translated to UTF-8 text arrays.

Attached a gift for the U.S. members: A 100-lines application that
- reads an archive from the Internet
- extracts a database in csv format
- allows the user to enter:
  - either the name of a city, and get its LatLong coordinates
  - or LatLong coordinates, and get the nearest three cities

Let me know if it works.

include \masm32\MasmBasic\MasmBasic.inc      ; download
  SetGlobals firstUse, best, second, third, xc:REAL4, yc:REAL4, xNow, xyMin, OneMio:REAL4=1000000.0, zipfile$="ZipCodes.zip", tmp$="~FrLocal.tmp"
  Init
  .if !Exist(zipfile$)
      void FileRead$("http://www.boutell.com/zipcodes/zipcode.zip")
      .if Exist(tmp$)
            Rename tmp$, zipfile$
            inc firstUse      ; flag fresh download, show the MsgBox
      .endif
  .endif
  .if Exist(zipfile$)
      UnzipInit zipfile$
      ... -> see attachment

jj2007

  • Moderator
  • Member
  • *****
  • Posts: 9733
  • Assembler is fun ;-)
    • MasmBasic
Sex & Crime
« Reply #229 on: March 17, 2015, 04:58:06 PM »
Please install version 17 March of the MasmBasic library.
Older versions have a problem with the translation of *.csv (comma-separated values) into a two-dimensional string array: If the very first column (see Bonaire, Saint below) contained quoted strings with embedded commas, they were interpreted as two columns. This is fixed now, and the snippet below (source and exe attached) will work just fine (as long as WHO provides the database, of course 8)) 

include \masm32\MasmBasic\MasmBasic.inc      ; download
  Init
  Recall "https://extranet.who.int/tme/generateCSV.asp?ds=mdr_estimates", who$(), csv
  Print Str$("%i records downloaded", eax)
  For_ ct=0 To who$(?)-1
      Print CrLf$, who$(ct, 0)
      Print At(33, Locate(y)) Spc2$, who$(ct, 4), Space$(40)
      For_ ecx=8 To 14      ; columns 8...14 contain the data
            Print At(ecx*8-25, Locate(y)) Spc2$, who$(ct, ecx)
      Next
  Next
  Exit
end start


Output:

217 records downloaded
country                            year  e_new_  e_new_  e_new_  e_new_  e_new_  e_new_  source_mdr_ret
Afghanistan                        2013  3.7     2.5     4.9     820     560     1100    Model
Albania                            2013  0.58    0.02    3.2     2       0       10      Surveillance
...
Bonaire, Saint Eustatius and Saba  2013  2.2     1.3     3.1     0       0       0       Surveillance
Bosnia and Herzegovina             2013  0       0       0.57    0       0       6       Surveillance
Botswana                           2013  2.5     1.5     3.5     120     70      160     Survey
Brazil                             2013  1.4     1       1.8     840     600     1100    Survey


P.S.: Just stumbled over a public database on crime records. Interesting, but guess what? The database is neither Windows nor Linux, apparently it's MAC - carriage returns only! So I felt morally obliged to add the Mac format to Recall's autodetect feature. That cost a whopping 40 bytes or so extra but it works like a charm. Go to http://masm32.com/board/index.php?topic=94.0 and re-install MasmBasic, so that you can test the snippet below :biggrin:

include \masm32\MasmBasic\MasmBasic.inc      ; download
  Init
  Recall "http://samplecsvs.s3.amazonaws.com/SacramentocrimeJanuary2006.csv", Crime$(), csv
  For_ ct=0 To Crime$(?)-1
      .if Instr_(Crime$(ct), "card info", 1) || ct==0
            xor esi, esi
            For_ ecx=0 To 8
                  Print At(esi, Locate(y)) Spc2$, Crime$(ct, ecx), Space$(8)
                  add esi, 8
                  .if ecx==1 || ecx==5
                        add esi, 18
                        .if ecx==5
                            add esi, 10
                        .endif
                  .endif
            Next
            Print
      .endif
  Next
  Print Str$("\n%i records received from Sacramento", Crime$(?))
  Exit
end start
« Last Edit: March 18, 2015, 07:20:07 AM by jj2007 »

jcfuller

  • Member
  • **
  • Posts: 182
Re: MasmBasic
« Reply #230 on: March 19, 2015, 12:15:30 AM »
Jochen,
  I figured it was about time I gave masmbasic a try but I am unable to install.
I double click on the exe and I get a window with a title:
"Last chance - show me where macro.asm sits and then a messagebox that says I should google Visual Basic??

James

jj2007

  • Moderator
  • Member
  • *****
  • Posts: 9733
  • Assembler is fun ;-)
    • MasmBasic
Re: MasmBasic
« Reply #231 on: March 19, 2015, 02:10:52 AM »
James,

Sorry for that. To deter the script kiddies, the installer tests if you have Masm32 installed, via the registry. If it doesn't find exactly what it expects, it gives you a "last chance" to select the macros.asm file in your Masm32 installation. It sits in the dedicated Masm32 folder. Please let me know if it works; I am also curious why it doesn't find the registry entries.

Thanks,
Jochen

dedndave

  • Member
  • *****
  • Posts: 8823
  • Still using Abacus 2.0
    • DednDave
Re: MasmBasic
« Reply #232 on: March 19, 2015, 02:23:34 AM »
i might be wrong, but i think the masm32 install only writes to the registry if the user elects to use QE as the default ASM editor

jj2007

  • Moderator
  • Member
  • *****
  • Posts: 9733
  • Assembler is fun ;-)
    • MasmBasic
Re: MasmBasic
« Reply #233 on: March 19, 2015, 02:59:16 AM »
You might be right, Dave :biggrin:

jcfuller

  • Member
  • **
  • Posts: 182
Re: MasmBasic
« Reply #234 on: March 19, 2015, 03:13:01 AM »
It is now available.

James

jj2007

  • Moderator
  • Member
  • *****
  • Posts: 9733
  • Assembler is fun ;-)
    • MasmBasic
Re: MasmBasic
« Reply #235 on: March 19, 2015, 03:36:27 AM »
Great :t

GuiParas equ "Hello James", x650, y20, w200, h200, sWS_CAPTION OR WS_POPUPWINDOW, cblack, b00FFFFD0h
GuiMenu equ @File, &Open, &Save, -, E&xit, @Edit, Undo, Copy, Paste
include \masm32\MasmBasic\Res\MbGui.asm
Event Message
  inc msgCount
  deb 4, "msg", chg:msgCount      ; , wParam, lParam      ; see deb
GuiEnd

jj2007

  • Moderator
  • Member
  • *****
  • Posts: 9733
  • Assembler is fun ;-)
    • MasmBasic
Re: MasmBasic
« Reply #236 on: March 24, 2015, 11:22:08 AM »
Update 24 March 2015:

- gsl interface improved (see original gsl example program):

include \masm32\MasmBasic\MasmBasic.inc
  gsl double gsl_sf_bessel_J0 (double x)      ; double x means a REAL8 is required as input
  Init                  ; ## GNU Scientific Library: Bessel function ##
  Print Str$("Bessel(5)=%Jf \n", gsl_sf_bessel_J0(FP8(5.0)))
  fstp st                  ; see a detailed gsl example here
  Exit
EndOfCode


- SetGlobals understands C-style declarations:

include \masm32\MasmBasic\MasmBasic.inc      ; download
  SetGlobals OWORD xx0, xx1, xx2, xx3, xx4, xx5, xx6, xx7
  Init
  mov eax, 11111111
  movd xmm0, eax
  movaps xx0, xmm0

  add eax, 11111111
  movd xmm1, eax
  movaps xx1, xmm1
  Exit
end start

jj2007

  • Moderator
  • Member
  • *****
  • Posts: 9733
  • Assembler is fun ;-)
    • MasmBasic
Printing a sinus via the FPU, the CRT, the GSL, and Python
« Reply #237 on: April 03, 2015, 10:59:13 AM »
Update 3 April 15: How to steal goodies from other languages... before distributing or selling any of this, study the copyright situation 8)

include \masm32\MasmBasic\MasmBasic.inc
; libgsl.dll download : open Binaries zip, and extract the two files libgsl.dll and libgslcblas.dll to \masm32\MasmBasic\GnuScLib\DLL
  gsl double gsl_sf_sin (double x)      ; define your required gsl function using the syntax of the GNU Scientific Library Reference
  SetGlobals threezero:double=3.0

  Init

  Dll "python34"      ; needs Python 3.4.3 (direct link to MSI)
  Declare void Py_Initialize, C:0
  Declare void PyRun_SimpleString, C:1      ; can be used like the commandline version of Python
  Declare void Py_Finalize, C:0

  Py_Initialize()
  PyRun_SimpleString("print('Printing the sinus of 3.0 in various languages:')")      ; use Python in MasmBasic
  PyRun_SimpleString("import math")      ; the math library needs to be imported first
  PyRun_SimpleString('print("Sinus(3)=", math.sin(3), "   Python 3.4.3")')

  Print Str$("Sinus(3)= %Jf\tGSL, global var\n", gsl_sf_sin(threezero))
  fstp st                  ; since doubles are returned via the FPU, ST(0) must be popped
  Print Str$("Sinus(3)= %Jf\tGSL, immediate\n", gsl_sf_sin(3.0))
  fstp st

  Dll "msvcrt"            ; good ol' CRT
  Declare double sin, C:1
  Print Str$("Sinus(3)= %Jf\tCRT, global var\n", sin(threezero))
  fstp st
  Print Str$("Sinus(3)= %Jf\tCRT, immediate\n", sin(3.0))
  fstp st

  fld FP10(3.0)            ; finally, the traditional way, using the FPU
  fsin 
  Print Str$("Sinus(3)= %Jf\tAssembler/Fpu\n", ST(0))
  fstp st
  PrintLine "Exact:    0.14112000805986722210074480... Wolfram Alpha"      ; link
  Py_Finalize()
  Inkey "--- hit any key ---"
  Exit
EndOfCode


Output:
Code: [Select]
Printing the sinus of 3.0 in various languages:
Sinus(3)= 0.1411200080598672    Python 3.4.3
Sinus(3)= 0.1411200080598672135 GSL, global var
Sinus(3)= 0.1411200080598672135 GSL, immediate
Sinus(3)= 0.1411200080598672135 CRT, global var
Sinus(3)= 0.1411200080598672135 CRT, immediate
Sinus(3)= 0.1411200080598672221 Assembler/Fpu
Exact:    0.14112000805986722210074480... Wolfram Alpha

hutch--

  • Administrator
  • Member
  • ******
  • Posts: 6711
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
Re: MasmBasic
« Reply #238 on: April 03, 2015, 12:49:15 PM »
The only interaction the installer has with the OS apart from disk IO is the VBS script file that gives you the option of putting the editor on the desktop. There is no direct registry writes at all. This is done to ensure the SDK is fully portable.
hutch at movsd dot com
http://www.masm32.com    :biggrin:  :skrewy:

jj2007

  • Moderator
  • Member
  • *****
  • Posts: 9733
  • Assembler is fun ;-)
    • MasmBasic
Re: MasmBasic
« Reply #239 on: April 09, 2015, 08:28:47 AM »
Thanks, Hutch. So the registry entry that I found for qEditor was probably what I created myself when associating .asm with qEditor.

I have changed the installer accordingly. It checks now for the presence of x:\Masm32; if more than one installation exists, it checks the timestamps of x:\Masm32\Examples\*.exe, and picks the drive that has the more recent executables in the examples folder tree. Only GetDriveType = DRIVE_FIXED are checked.

So, hopefully the latest update of today, 9 April will work for everybody with a Masm32 installation. Please let me know if it works now.

There are also some improvements under the hood, notably I managed to speed up Len() a little bit:
Code: [Select]
Comparing Masm32 len() and MasmBasic Len()
Total=401700900  in   31 ms (Len)
Total=401700900  in  217 ms (len)

Total=401700900  in   32 ms (Len)
Total=401700900  in  217 ms (len)

Total=401700900  in   31 ms (Len)
Total=401700900  in  216 ms (len)

Intel(R) Core(TM) i5-2450M CPU @ 2.50GHz

Testbed attached.