Author Topic: MasmBasic  (Read 440071 times)

jj2007

  • Moderator
  • Member
  • *****
  • Posts: 13945
  • Assembly is fun ;-)
    • MasmBasic
Fast MemSet and Instr() algos
« Reply #270 on: September 25, 2015, 09:11:53 AM »
Version 25 September 2015 features:

- fast string search:
  .if Instr_(FAST, pBuffer, pPattern, 0)
        Print "substring found"

- fast MemSet:
      MemSet offset somebuffer, 0, 1000                    ; destination, pattern, #bytes
      MemSet offset somebuffer, "x", 1000                  ; 1000 * x
      MemSet offset somebuffer, Mirror$("abcd"), 1000      ; 250 * abcd, slightly faster
      mov eax, Chr$("Masm32 is great ")                    ; string must have (at least) 16 bytes
      movups xmm0, oword ptr [eax]
      mov edx, offset somestring
      MemSet edx, xmm0, 99


The two new commands are on recent CPUs more than twice as fast as their C/C++ equivalents; Instr_() supports also mode 2, i.e. ignore case of the first character (as in "This is OK, this too") without significant speed loss.

TWell

  • Member
  • ****
  • Posts: 743
Re: MasmBasic
« Reply #271 on: September 25, 2015, 04:53:38 PM »
Avast don't like that Setup.exe :(

jj2007

  • Moderator
  • Member
  • *****
  • Posts: 13945
  • Assembly is fun ;-)
    • MasmBasic
Re: MasmBasic
« Reply #272 on: September 25, 2015, 05:40:49 PM »
Avast dislikes many things, just disable it temporarily. I have no time and no money to sue them for damaging the reputation of the library, but false positives are a fat problem. Did you know that we have even a dedicated sub-forum called AV Software sh*t list?

Attached an updated "MasmBasic for C" example. Extract to a folder named \Masm32\MasmBasic\Mb4C and make sure it's on the same drive as Masm32 and Pelles C (this is clumsy, I know, and will change when I find time to fix it).

dedndave

  • Member
  • *****
  • Posts: 8828
  • Still using Abacus 2.0
    • DednDave
Re: MasmBasic
« Reply #273 on: September 26, 2015, 03:15:45 AM »
soooo
should i uninstall an older version first, or will the new one take care of it ?

dedndave

  • Member
  • *****
  • Posts: 8828
  • Still using Abacus 2.0
    • DednDave
Re: MasmBasic
« Reply #274 on: September 26, 2015, 03:37:05 AM »
better question here....

how do i do a clean uninstall of MasmBasic?

jj2007

  • Moderator
  • Member
  • *****
  • Posts: 13945
  • Assembly is fun ;-)
    • MasmBasic
Re: MasmBasic
« Reply #275 on: September 26, 2015, 04:13:34 AM »
should i uninstall an older version first, or will the new one take care of it ?
...
how do i do a clean uninstall of MasmBasic?

The installer will just overwrite any MB files, unless they have been altered after the new version. Normally, you can't do anything wrong with this logic; unless you fumble with MasmBasic.inc, and forget to make a backup. But that would be about as stupid as improving Windows.inc and re-installing Masm32 :biggrin:

Re uninstall: It doesn't write anything to the registry, so it's just the \Masm32\MasmBasic folder. The editor has the habit to save user-written code to \Masm32\MasmBasic\AscUser, so you might check if there is anything valuable in there.

Attached a list of all currently installed files.

dedndave

  • Member
  • *****
  • Posts: 8828
  • Still using Abacus 2.0
    • DednDave
Re: MasmBasic
« Reply #276 on: September 26, 2015, 04:22:19 AM »
thanks Jochen   :t

it's been a while since i updated it
so, i will delete the folder and install "anew"

jj2007

  • Moderator
  • Member
  • *****
  • Posts: 13945
  • Assembly is fun ;-)
    • MasmBasic
Re: MasmBasic
« Reply #277 on: September 26, 2015, 04:46:35 AM »

jj2007

  • Moderator
  • Member
  • *****
  • Posts: 13945
  • Assembly is fun ;-)
    • MasmBasic
Re: MasmBasic
« Reply #278 on: October 01, 2015, 08:52:35 AM »
Version 1 October 15 features the new ultrafast variant of Instr_():

Instr_, Rinstr, wInstr, InstrOr
      Print "The current drive is ", Left$(ThisExe$, Instr_(ThisExe$, "\")-1)
      mov pos, Instr_(1, L$(n), "equ", 1+4)      ; 1=start pos, 1=case-insensitive + 4=full word
Rem   - returns relative pos in edx, absolute in eax
      - if no match is found, zero is returned in edx, and eax points to the start of the 'haystack'; same if 'needle' is empty
      - six syntax variants allowed:
         A: has startpos:      Instr_(1, "Test", "Te", 2)     ; 4 args
         B: no startpos:      Instr_("Test", "Te", 2)         ; 3 args, last one immediate = mode
         C: has startpos:      Instr_(1, "Test", "Te")        ; 3 args, last one not immediate
         D: no startpos:      Instr_("Test", "Te")            ; 2 args
         E: test several patterns:      InstrOr("Test", "Te" or "st", 1)  ; 3 args (startpos is 1)
         F: extra fast mode:      Instr_(FAST, My$(ecx), "Hello", 0)      ; 4 args, no startpos, modes 0+2 only
       - case & mode (bitwise flag):
         0=case-sensitive, +1=insensitive, +2=intellisense (Name=name),
         +4=full word search, +8=include start of line in text block search
         Note: full word search returns failure for chars above ASCII 64 to the left or right
         Example: Nostructfoundhere, this123struct456isfound, this@struct, too

         The FAST option is about twice as fast as CRT strstr, and three times
         as fast when used with string arrays;

         using FAST, binary search in haystacks containing zeros is possible by
         assigning the buffer size to edx:
           mov edx, LastFileSize      ; any info on length of buffer can be used with edx
           Print Str$("Pos in executable: %i", Instr_(FAST, esi, "kernel32", 2 or 64)      ; 2=case-insensitive, 64=len in edx


       - wRinstr is available but only as wRinstr(src, pattern) with a one-byte pattern (e.g. "\")

jj2007

  • Moderator
  • Member
  • *****
  • Posts: 13945
  • Assembly is fun ;-)
    • MasmBasic
Enum$
« Reply #279 on: October 03, 2015, 12:08:29 PM »
MasmBasic version 3 October features Enum$(), the companion to Enum:

Enum            ; create a list of IDs
Enum      IdMenuNew, IdMenuSave, IdMenuCopy, IdTimer
Enum      20:IdEdit, IdButton1, 30:IdButton2, IdStatic, IdFind, IdFindStatic
Remdefault start is 10, but (as shown above) new start values can be specified with nn:

Enum$          ; return numeric constant as text
Case WM_CREATE
  Enum 20:IdEdit, IdButton1, 30:IdButton2, IdStatic, IdFind, IdFindStatic
  ; use with CreateWindowEx
Case WM_COMMAND
  ; ID is loword(wParam), print it as Enum$(ID, list of numeric constants)
  PrintLine "command for control ", Enum$(word ptr wParam, IdEdit, IdButton1, IdButton2, IdStatic, IdFind, IdFindStatic)
  mov ecx, Enum$(uMsg, WM_CREATE, WM_PAINT, WM_SIZE, WM_SIZING, WM_COMMAND)
  .if byte ptr [ecx]!="?"      ; if no matching entry is found, Enum$() returns a question mark
      PrintLine "Message: ", ecx      ; output e.g. Message: WM_PAINT
  .endif


Below and attached a full example showing a practical use of Enum$().

include \masm32\MasmBasic\MasmBasic.inc      ; download
uselib ntdll            ; for RtlGetVersion
  Init                  ; OPT_Assembler JWasm ; ML chokes with version suite string
  sub esp, RTL_OSVERSIONINFOEXW-DWORD
  push RTL_OSVERSIONINFOEXW      ; set size member
  invoke RtlGetVersion, esp
  mov ecx, esp      ; ecx is pointer to RTL_OSVERSIONINFOEXW structure
  ovi equ [ecx.RTL_OSVERSIONINFOEXW]      ; MSDN
  .if eax
      PrintLine "RtlGetVersion failed with ", Err$()
  .else
      PrintLine Str$("RtlGetVersion\t%i.", ovi.dwMajorVersion), Str$(ovi.dwMinorVersion), Str$(" SP %i.", ovi.wServicePackMajor), Str$(ovi.wServicePackMinor), Str$(" build %i", ovi.dwBuildNumber)
      Print "Suite mask", Tb$, Hex$(ovi.wSuiteMask), ": "
      For_ esi=0 To 31      ; see Geoff Chappell: The Product Suite
            xor eax, eax
            bts eax, esi
            and ax, ovi.wSuiteMask      ; extra long line requires JWasm or AsmC
            mov ebx, Enum$(eax, VER_SUITE_BACKOFFICE, VER_SUITE_BLADE, VER_SUITE_COMPUTE_SERVER, VER_SUITE_DATACENTER, VER_SUITE_ENTERPRISE, VER_SUITE_EMBEDDEDNT, VER_SUITE_PERSONAL, VER_SUITE_SINGLEUSERTS, VER_SUITE_SMALLBUSINESS, VER_SUITE_SMALLBUSINESS_RESTRICTED, VER_SUITE_STORAGE_SERVER, VER_SUITE_TERMINAL, VER_SUITE_WH_SERVER)
            .if byte ptr [ebx]!="?"
                  Print Mid$(ebx, 11), " "
            .endif
      Next
      PrintLine CrLf$, "ProductType", Tb$, Mid$(Enum$(ovi.wProductType, VER_NT_WORKSTATION, VER_NT_DOMAIN_CONTROLLER, VER_NT_SERVER), 8)
      lea eax, ovi.szCSDVersion
      wPrintLine "CSDVersion", wTb$, eax, wCrLf$      ; Unicode
  .endif
  add esp, RTL_OSVERSIONINFOEXW

  Inkey CrLf$, "---- hit any key ----"
  Exit
EndOfCode            ; see MSDN


Output for Win7-64:
Code: [Select]
RtlGetVersion   6.1 SP 1.0 build 7601
Suite mask      0300: SINGLEUSERTS PERSONAL
ProductType     WORKSTATION
CSDVersion      Service Pack 1

dedndave

  • Member
  • *****
  • Posts: 8828
  • Still using Abacus 2.0
    • DednDave
Re: MasmBasic
« Reply #280 on: October 04, 2015, 11:37:25 AM »
XP - not much help - lol

i guess that would formatted as "5.1.2600 SP 3.0"

Code: [Select]
RtlGetVersion   5.1 SP 3.0 build 2600
Suite mask      0100: SINGLEUSERTS
ProductType     WORKSTATION
CSDVersion      Service Pack 3

jj2007

  • Moderator
  • Member
  • *****
  • Posts: 13945
  • Assembly is fun ;-)
    • MasmBasic
Choose command
« Reply #281 on: October 06, 2015, 09:32:57 AM »
Update 6 October: Inspired by James Fuller, the Choose command was added to the library:

include \masm32\MasmBasic\MasmBasic.inc      ; download
.data
tx123      db "This is tx123", 0

  Init
  mov ecx, Chr$("ecx is a string")
  Dim My$()
  Let My$(0)="array element 0"
  Let My$(1)="array element 1"
  .While 1
      Inkey "Gimme a letter from a-z: "
      .Break .if eax==VK_ESCAPE
      xchg eax, ecx
      .if Choose(ecx-"a", 100, 101, 102, "abc", 124, 12345.67, 12345678.90123456789, offset tx123, ecx, My$(1), "the letter k")<=ChooseString
            .if eax==ChooseReal
                  Print Str$("You chose the real number %Jf\n", ST(0))
                  fstp st
            .elseif eax==ChooseError
                  PrintLine "You typed the letter ", Chr$(ecx), " - error..."
            .else
                  push eax
                  Print Str$("You chose the integer %i ", eax)
                  pop eax
                  PrintLine " (hex", Hex$(eax), ")"
            .endif
      .else
            PrintLine "You chose the string [", eax, "]"
      .endif
  .Endw
EndOfCode


P.S.: VB Choose Function on MSDN uses a double as the index - funny idea 8)

jj2007

  • Moderator
  • Member
  • *****
  • Posts: 13945
  • Assembly is fun ;-)
    • MasmBasic
Plotting a map
« Reply #282 on: October 11, 2015, 10:35:59 PM »
MasmBasic update of 11 October improves on its GUI interface:

GuiParas equ "Plotting a sinus and a map", x30, y30, w1200, h700, bnone
include \masm32\MasmBasic\Res\MbGui.asm
  ToolTips                  ; initialise the tooltips, they will
  ToolTips end              ; show the country names
  ArrayLoadMap 0, "\masm32\MasmBasic\Res\europe.map"
Event Paint
  ArrayPlot hWnd, RgbCol(144, 240, 255)          ; init with window (or control) handle and background colour
  ArrayPlot 0, RgbCol(127, 127, 127), lines=2    ; display map #0 with grey borders 2px thick
  ArrayPlot exit, "Europe"                       ; finish with a title
  GuiTextBox 35.0, 92.0, 120, 32, "This application is sizeable - try it!!!!", fcol 0ffh, bcol RgbCol(204, 255, 204)
  GuiTextBox 29.0, 63.0, 85, 66, "Move the mouse over a country to see its name", fcol 0, bcol RgbCol(255, 255, 128)
Event Message
  .if uMsg==WM_MOUSEMOVE
      ArrayMapRegion(lParam, 0, hWnd)      ; activate tooltip if mouse enters a region
  .endif
GuiEnd


Screenshot below. It's heavily sized, to save bandwidth - the full version looks better ;-)

dedndave

  • Member
  • *****
  • Posts: 8828
  • Still using Abacus 2.0
    • DednDave
Re: MasmBasic
« Reply #283 on: October 12, 2015, 09:48:59 AM »
i like the idea - but have no idea how it works - lol

i'd like to write a program that generates "great circle" maps (azimuthal equidistant)
they have them - they even have online generators, but i'd like my own
at any rate - no time to play with it for now   :(

dedndave

  • Member
  • *****
  • Posts: 8828
  • Still using Abacus 2.0
    • DednDave
Re: MasmBasic
« Reply #284 on: October 12, 2015, 09:52:08 AM »
here's one, with the center on "some town" in France
they are different for every location in the world - lol

http://www4.plala.or.jp/nomrax/BM/Paris_l.gif

we use them to "aim" our antennas
some guy in France wants to talk to a guy in Alaska, he aims his antenna about 350 degrees