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

Main Menu


Started by jj2007, May 23, 2012, 10:16:07 PM

Previous topic - Next topic


Quote from: dedndave on June 11, 2015, 08:33:29 AM
you wanna tell us about the bug ?   :biggrin:

It's actually quite weird. There was an access violation in RichMasm, due to a fairly fat bug - sh*t happens. Windows 7-64 has the strange habit to "fix" such problems somehow, so I never noticed (and I should check why I didn't see it on the XP machine). Win 8 made it crash.

First, I thought it had to do with SEH, but the example in \Masm32\MasmBasic\Res\SkelTryCatch.asc works just fine both in Win 8.1 and in Win 7, so I really don't know why the exception made it crash in Win 8.1 ::)

Another problem was RichMasm's habit to be stingy, pardon: parsimonious with the screen real estate: It uses the caption for the menu titles. That works fine from XP to Win7, but Win 8.1 re-introduced a design feature that will certainly be loved by the fans of Windows 3.1: the captions are centered. So to avoid overlap of menus and title, I had to cheat the OS by padding the caption with spaces to the right. To avoid doing that in Win 7, too, I had to get the OS version. I really wonder when they will retire the person who is responsible for the GetVersion mess, it's incredible. Google for GetVersionEx deprecated manifest, and you'll even find postings that make fun of M$. Richmond, still sleeping...?


what i was looking for was code to avoid
i (we) write code, testing under XP
it would be nice if we could learn the pitfalls to avoid to allow the code to run under win8+


Quote from: dedndave on June 12, 2015, 01:23:15 AM
what i was looking for was code to avoid

So far,  the only oddity when passing from Win7-64 to Win 8.1-64 was the access violation in RichMasm, which was swallowed by the OS in Win7. So it seems it's always a good idea to test release code with Olly, because the latter catches the access violations.

A bigger problem was the nasty discovery that the 64-bit OS versions trash xmm regs in 32-bit code, while the 32-bit OS versions leave them intact. In MasmBasic, I eventually solved that with
fxsave MbXs
fxrstor MbXs

pairs. The impact on performance is negligible because it concerns only Win API calls.


MasmBasic update of 29 August 2015:

Switch_, Case_, Default_, Endsw_
The Masm32 Switch macro is more powerful than its C or GfaBasic equivalents, since it can handle even variables or registers in the "cases". Old versions of the MasmBasic Switch_ (note the understroke) could not handle variables, i.e. the cases can be integer constants only. However, under the hood it creates a jump table that is for long lists of cases much faster than the Masm32 macro. Below an example for MasmBasic Switch_:

      include \masm32\MasmBasic\
      Init                  ; ## Switch with jump table ##
      m2m ecx, -5
      PrintLine "------- testing the new MasmBasic Switch_ macro -------"
            Print Str$(ecx), Tb$
            Switch_ ecx
            Case_ -2
                  PrintLine "Case -2"
            Case_ 0
                  PrintLine "Case NULL"
            Case_ 10
                  PrintLine "Case 10"
            Case_ 18
                  PrintLine "Case 18"
            Case_ 14 .. 16
                  PrintLine "Case 14 .. 16"
                  PrintLine "---"
            inc ecx
      .Until signed ecx>20
Rem      Switch_ trashes edx but not eax; do not forget the understroke


For the fans of "real" BASIC, I have added Data and Read statements to MasmBasic. Example:

include \masm32\MasmBasic\      ; download
  Data 123, "Hello World, how are you?", 'single quotes are allowed', My$, sq$, 456
  SetGlobals My$, sq$, c1$, c2$, MyByte, MyDword, MyR4:REAL4, MyR8:REAL8, Last$, MyQ:QWORD
  Data 789, 111, 1234567890123456789, 1234567890.123456789, 12345.6789, 12345.6789
  Data 33333, "Last string item"         ; Data statements can go almost everywhere...
  Read ecx, My$, sq$, c1$, c2$, eax      ; once My$+sq$ are read, c1$ and c2$ can be copied
  Read edx
  Read esi     
  Data 1234567890123456789               ; ... but values must be defined before they are read
  Read xmm0, f:xmm1, MyR8, MyR4, edi, Last$, MyQ
  deb 4, "Read variables:", ecx, eax, $My$, $sq$, $c1$, $c2$, edx, esi, xmm0, f:xmm1, MyR8, MyR4, edi, MyQ, $Last$

Read variables:
ecx             123
eax             456
$My$            Hello World, how are you?
$sq$            single quotes are allowed
$c1$            Hello World, how are you?
$c2$            single quotes are allowed
edx             789
esi             111
xmm0            1234567890123456789
f:xmm1          1234567890.123457
MyR8            12345.67890000000
MyR4            12345.68
edi             33333
MyQ             1234567890123456789
$Last$          Last string item


QSort misbehaved - fixed in version 2 September:

qsmb proc
  push esi
  push esi edi
  push ebx 8)


I rewrote the Gui interface a little bit. Of course, it looks horribly BASIC, but traces of pure assembler indicate what is under the hood. And it also offers some eye candy ;D

Oh, and btw - this window is resizable 8)

Assembling requires version 9/11 of MasmBasic.

GuiParas equ "MasmBasic is easy to use", x50, y50, w1200, h666
GuiMenu equ @File, &Open, &Save, -, E&xit, @Edit, Undo, Copy, Paste
include \masm32\MasmBasic\Res\MbGui.asm

  Dim MySinus() As REAL8
  For_ ct=-400 To 400
      SetFloat MySinus(ct+400)=Sinus(ct)      ; ******* a GUI demo in 30 lines of code *******

Event Menu
  MsgBox 0, Str$("You clicked into menu entry #%i", MenuID), "Hello:", MB_OK

Event Paint
  ArrayPlot hWnd, RgbCol(255, 255, 128)            ; init & set background
  ArrayPlot MySinus(), 0, lines=5                  ; draw the array
  ArrayPlot exit, "Playing with Sinus() plots"     ; finish with a title
  For_ ct=20 To GuiWidth-20 Step 10
      GuiLine 50.0, 8.0, ct, 99.0, RgbCol(255, 160, 160)            ; the 'pink pyramid'
      void Cosinus(ct)
      fimul GuiHeight
      fiadd GuiHeight       ; center
      fmul FP4(0.4)
      push eax              ; create a slot
      fistp stack           ; convert to integer
      pop ecx               ; retrieve as ecx
      GuiText ct+30, ecx+50, Str$(ct), bcol RgbCol(255, 255, 128)
      GuiCircle ct, ecx+60, 1.5, b Rand(0ffffffh), p RgbCol(80, 80, 80)
  GuiEllipse 32.0+9, 20.0, 7.0, 8.0, b RgbCol(255, 128, 128)            ; RGB for n00bs
  GuiEllipse 60.0-9, 20.0, 7.0, 8.0, b 0FF2020h, p 808080h              ; BGR for experts
  GuiTextBox 50.0-60, 40.0, 120, 100, "This is just a simple text box, try to do the same in other programming languages", bcol RgbCol(255, 255, 255)
  GuiCircle 50.0, 40.0+50, 12.0, p 0, b none                  ; none = hollow brush



Somebody complained about RichMasm not being configurable, so in version 18 September I added the option to change the RichEdit control's background colour.

See ColBg in \Masm32\MasmBasic\Res\RichMasm.ini for a list of available background and foreground colours (you may change the ini file, but the next installation will overwrite your changes, so keep a backup please).

To change the background colour for a document, press Ctrl G and enter e.g. udc=2. Available colours:
ColBg=0FFFFE0h ; default, turquois
Bg1=0F0F0F0h ; almost white
Bg2=0C0FFB0h ; greenish
Bg3=0C0C0FFh ; light red
Bg4=0B0FFFFh ; light yellow
Bg5=0FFB0FFh ; pink
Bg6=202020h ; grey; 1=almost black, 0 picks default colour ColBg
BgH=0AAFFFFh ; reserved for hilite colour

ColFg=0 ; default text colour
Fg8=0B0B0B0h ; light gray
Fg16=0A0h ; dark red
Fg24=0A00000h ; dark blue
Fg32=0aaaah ; dark yellow
Fg40=0ffffffh ; white
Fg48=8000h ; green

udc=14 would pick dark grey background with light gray text colour. While the background changes as soon as you hit Enter, the text colour will change only if you select all text and then hit Ctrl E twice.

Among the templates, "Editor with toolbar" has been improved, and the first on top of the list when clicking menu File/New Masm source called "MessageBox only" looks now a bit different, thanks to a radical redesign of RichMasm:


Hi jj!

A lot better.

I don't remember if was posible to open asm files in RichMasm from the explorer. Now it's no posible.

Regards. HSE
Equations in Assembly: SmplMath


Problem could be an obsolete file association, or that RichMasm.exe and your asm file are on different drives. Try finding ???:\Masm32\MasmBasic\RichMasm.exe, then drag an asm file over the exe.

Version 20 September: Problem fixed. RichMasm will work now even if the source is on a different drive.


Equations in Assembly: SmplMath


Quote from: HSE on September 20, 2015, 11:52:16 AM
Perfect now  :t

In this case, I have a special version of the help file for you :greensml:


Better and better!  Thanks

But I use a lot of text coloring, for assembly programming mostly in RadAsm (a more dark version that the released one) . Of course some pure GreyAndBoring for small tests in QEditor.

Testing MasmBasic, RichMasm is always the first option  :biggrin:.
Equations in Assembly: SmplMath


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.


Avast don't like that Setup.exe :(