Author Topic: MasmBasic  (Read 440008 times)

jj2007

  • Moderator
  • Member
  • *****
  • Posts: 13945
  • Assembly is fun ;-)
    • MasmBasic
Hex$ displays XMM and FPU registers
« Reply #75 on: August 05, 2013, 10:29:52 AM »
MasmBasic version 5 August 2013 is much improved on the deb and Hex$() macros. Example:

include \masm32\MasmBasic\MasmBasic.inc        ; download
        Init
        ; create a WORD array (byte, dword, qword, realX are also valid sizes):
        Dim MyW() As WORD
        mov MyW(0), 100        ; give it a start value
        xor ecx, ecx
        .Repeat
                mov ax, MyW(ecx)
                add ax, cx
                mov MyW(ecx+1), ax
                deb 6, "Fill a WORD array", ecx, MyW(ecx), MyW(ecx+1)        ; print the first 6 iterations to the console
                inc ecx
        .Until ecx>999

        Print Str$("\n%i loops OK\n", ecx)
        Print Str$("MyW(ecx-2)=%i\n", MyW(ecx-2))        ; show the last two values assigned
        Inkey Str$("MyW(ecx-1)=%i\n", MyW(ecx-1))
        Exit
end start


Output:
Fill a WORD array
ecx             0
MyW(ecx)        100
MyW(ecx+1)      100

Fill a WORD array
ecx             1
MyW(ecx)        100
MyW(ecx+1)      101

Fill a WORD array
ecx             2
MyW(ecx)        101
MyW(ecx+1)      103

Fill a WORD array
ecx             3
MyW(ecx)        103
MyW(ecx+1)      106

Fill a WORD array
ecx             4
MyW(ecx)        106
MyW(ecx+1)      110

Fill a WORD array
ecx             5
MyW(ecx)        110
MyW(ecx+1)      115

1000 loops OK
MyW(ecx-2)=38851
MyW(ecx-1)=39849


The Hex$() macro can now handle more sizes, including the 4 DWORDS of xmm registers, and has learned to display exotic formats, such as FPU and XMM registers:

include \masm32\MasmBasic\MasmBasic.inc        ; download
.data
MyByte        db 12h
MyWord        dw 1234h
MyDword        dd 12345678h
MyQword        dq 1234567812345678h
MyReal8        REAL8 1234567812345678r        ; r means the hex representation of a real number
MyPackedQwords dq 11aa22bb33cc44ddh, 55aa66bb77cc88ddh
        Init
        mov ecx, 12345678h
        PrintLine Hex$(cl)        ; reg8, 12 - same for dh, ah etc
        PrintLine Hex$(ch)        ; reg8, 12 - same for dh, ah etc
        PrintLine Hex$(cx)        ; reg16, 1234
        PrintLine Hex$(ecx)        ; reg32, 12345678
        PrintLine Hex$(123)        ; immediate
        PrintLine Hex$(MyByte)        ; global and local variables
        PrintLine Hex$(MyWord)
        PrintLine Hex$(MyDword)
        PrintLine Hex$(MyQword)        ; QWORD will be displayed with one space as 12345678 90123456
        movups xmm1, oword ptr MyPackedQwords
        PrintLine Hex$(xmm1)        ; if QWORD is not enough, get e.g. 11AA22BB 33CC44DD 55AA66BB 77CC88DD
        PrintLine Hex$(MyReal8)        ; same as QWORD
        fldpi
        PrintLine CrLf$, "PI=", Hex$(ST)        ; PI as 10-BYTE hex
        Let esi=CrLf$+"Result = "+Hex$(287454020)+"h"        ; in case you need the trailing h or a leading 0x, use Let or Cat$()
        Inkey esi
        Exit
end start


Output:
78
56
5678
12345678
0000007B
12
1234
12345678
12345678 12345678
11AA22BB 33CC44DD 55AA66BB 77CC88DD
12345678 12345678

PI=4000 C90FDAA2 2168C235

Result = 11223344h


If you find a problem, please let me know.

jj2007

  • Moderator
  • Member
  • *****
  • Posts: 13945
  • Assembly is fun ;-)
    • MasmBasic
Bugfix for displaying Hex$(xmmreg)
« Reply #76 on: August 12, 2013, 01:09:38 PM »
Version 5 August of MasmBasic displayed OWORDs in the incorrect order. The bug is fixed in version 12 August.
The reason, or rather: my bad excuse, is that I try to keep compatibility to good old MASM 6.15 - and the latter doesn't know about OWORDs. My workaround is usual to declare two QWORDs instead:

; MyO   OWORD 00112233445566778899aabbccddeeffh   ; no good for ML 6.15 and lower
; MyO   QWORD 0011223344556677, 8899aabbccddeeffh ; solution #0 - WRONG
MyO     QWORD 8899aabbccddeeffh, 0011223344556677 ; solution #1 - RIGHT


As you can easily guess, I had tested the new Hex$(xmm1) with solution #0 :redface:

Below a simple demo (the deb macro uses Hex$() internally):

include \masm32\MasmBasic\MasmBasic.inc        ; download
.data
O0        OWORD 0FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFh
O1        OWORD 0FFFF99FFFFFFFFFFFFFF11FFFFFFFFFFh
O3        OWORD 0ffeeddccbbaa99887766554433221100h

        Init
        movups xmm0, O0
        movups xmm1, O1
        movups xmm3, O3
        movaps xmm2, xmm0        ; copy for pcmpeqb
        PCMPEQB xmm2, xmm1
        deb 4, "x0/1/2", x:xmm0, x:xmm1, x:xmm2, x:xmm3
        Print CrLf$, "16 bits", Tb$, Tb$, Tb$, "5432109876543210", CrLf$
        PMOVMSKB eax, xmm2        ; show in ax where xmm0 differs to xmm1
        xor ecx, ecx
        not ax        ; we are interested in bits set
        deb 4, "MSKB", b:ax
        bsr ecx, eax
        deb 4, "msb set", ecx
        bsf ecx, eax
        deb 4, "lsb set", ecx
        Inkey
        Exit
end start

Output:
x0/1/2
x:xmm0          FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF
x:xmm1          FFFF99FF FFFFFFFF FFFF11FF FFFFFFFF
x:xmm2          FFFF00FF FFFFFFFF FFFF00FF FFFFFFFF
x:xmm3          FFEEDDCC BBAA9988 77665544 33221100

16 bits                 5432109876543210
MSKB    b:ax            0010000000100000
msb set ecx             13
lsb set ecx             5

Magnum

  • Member
  • *****
  • Posts: 2399
Re: MasmBasic - a fast and easy-to-use library
« Reply #77 on: August 12, 2013, 01:50:17 PM »
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 the latest Masm32 SDK (version 11), MASM (from version 6.15 upwards, see e.g. version 8.0) and JWasm. The usual disclaimers apply - do not use for military purposes, in hospitals and anywhere else where buggy applications could cause damage. You have been warned 8)


I wish you had posted that earlier.

I used it to write a program that monitors C-eye-PAV.

I think you are safe though.

Andy
Take care,
                   Andy

Ubuntu-mate-18.04-desktop-amd64

http://www.goodnewsnetwork.org

jj2007

  • Moderator
  • Member
  • *****
  • Posts: 13945
  • Assembly is fun ;-)
    • MasmBasic
Comparing OWORDs and QWORDs
« Reply #78 on: August 15, 2013, 10:58:39 AM »
Update 15 August (download):

Qcmp, Ocmp
.data        ; for testing
qSmall    qWORD 7700000000000001h
qBig      qWORD 7700000000000003h
oSmall    OWORD 77000000000000000000000000000001h
oBig      OWORD 77000000000000000000000000000003h        ; OWORD for JWasm and higher ML.exe versions
; oBig    qWORD 00000000000000003h, 7700000000000000h        ; 2 QWORDS for ML 6.15
.code
        Qcmp qBig, qSmall        ; compare two global variables
        mov ecx, offset oBig        ; use a pointer ...
        Ocmp ecx, oSmall        ; ... for one (or both) of them
        movups xmm0, OWORD PTR oSmall        ; even ML 6.15 understands that
        oqDeb=1        ; if this flag is set, Qcmp or Ocmp print e.g. "ecx greater xmm0" to console
        Ocmp ecx, xmm0        ; a pointer and an XMM reg (xmm0...xmm2 will be trashed)
        deb 4, "Result", flags        ; CzSo, i.e. Carry? and Sign? set
Rem
        - returns flags as in a cmp eax, edx comparison (control for overflow!)
        - trashes eax and edx, xmm0 and xmm1; do not use edx as input
        - you cannot use both ecx and ebx as input pointers (an error will be thrown)

## for comparing floats (REAL4, REAL8, REAL10): ##
Fcmp
        MyPI_hi        REAL4        3.14160
        ...
        Fcmp MyPI_hi, PI, medium        ; PI is what you think it is
        .if FcmpLesser
                Print Str$("MyPI_hi at %f is lower than the real PI\n", MyPI_hi)
        .elseif Zero?
                Print Str$("MyPI_hi at %f is exact\n", MyPI_hi)
        .else
                Print Str$("MyPI_hi at %f is higher than the real PI\n", MyPI_hi)
        .endif
Rem        - returns Zero? and Sign? flags (and only these are valid): Sign? means "first arg below second arg"
        - you may use FcmpGreater and FcmpLess (aka !Sign? and Sign?)
        - single arg, e.g. Fcmp xmm1, tests for zero
         - see also QCmp and Ocmp for comparing QWORDs and OWORDs
         - almost any number formats can be compared, including xmm registers etc

Magnum

  • Member
  • *****
  • Posts: 2399
Re: MasmBasic - a fast and easy-to-use library
« Reply #79 on: August 15, 2013, 11:43:38 AM »
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 the latest Masm32 SDK (version 11), MASM (from version 6.15 upwards, see e.g. version 8.0) and


When I clicked on version 8, it said off limits.

Andy
Take care,
                   Andy

Ubuntu-mate-18.04-desktop-amd64

http://www.goodnewsnetwork.org

jj2007

  • Moderator
  • Member
  • *****
  • Posts: 13945
  • Assembly is fun ;-)
    • MasmBasic
Re: MasmBasic - a fast and easy-to-use library
« Reply #80 on: August 15, 2013, 04:54:56 PM »
Thanks, Andy - I just corrected the link to Erol's post. Caution, though, when going to the M$ site:

Quote
The Microsoft Macro Assembler 8.0 (MASM) is a tool that consumes x86 assembly language programs and generates corresponding binaries.

Make a backup of your sources ;)

Or, much better idea, use JWasm - fully compatible with Masm32 and MasmBasic, and at least twice as fast as the latest M$ snails. RichMasm has now autodetection for JWasm:
   ; if OPT_Assembler not explicitly set, check if ML is old and JWasm is available
   .if Exist("\Masm32\Bin\ml.exe")
           .if Instr_(GfDate$(-1), "1999")
                   mov ecx, Chr$("\Masm32\bin\JWasm.exe")
                   .if Exist(ecx)
                           invoke lstrcat, edi, offset txOptAss
                   .else
                           MsgBox 0, Cat$("You need"+CrLf$+ecx), "Hi", MB_OK
                   .endif
           .endif
   .endif

dedndave

  • Member
  • *****
  • Posts: 8828
  • Still using Abacus 2.0
    • DednDave
Re: MasmBasic - a fast and easy-to-use library
« Reply #81 on: August 15, 2013, 05:01:13 PM »
PacMasm ?   :biggrin:


jj2007

  • Moderator
  • Member
  • *****
  • Posts: 13945
  • Assembly is fun ;-)
    • MasmBasic
PacMasm
« Reply #82 on: August 15, 2013, 05:20:57 PM »
PacMasm ?   :biggrin:
include \masm32\MasmBasic\MasmBasic.inc        ; download
        Init
        GetFiles \Masm32\*.asm
        push eax
        For_ ebx=0 To eax-1
                Kill Files$(ebx)
        Next

        Inkey Str$("Dave, wifey is waiting, and %i files are gone!!!!", stack)
        Exit
end start  :greensml:

Antariy

  • Member
  • ****
  • Posts: 564
Re: MasmBasic - a fast and easy-to-use library
« Reply #83 on: August 15, 2013, 06:11:27 PM »
:greensml:



C:\MASM32\>ML the_proper_code.asm
Microsoft (R) Macro Assembler Version 6.15.8803
Copyright (C) Microsoft Corp 1981-2000.  All rights reserved.

 Assembling: the_proper_code.asm
 Yum-yum!



C:\MASM32\>ML the_untidy_code.asm
Microsoft (R) Macro Assembler Version 6.15.8803
Copyright (C) Microsoft Corp 1981-2000.  All rights reserved.

 Assembling: the_untidy_code.asm
the_untidy_code.asm(9) : warning A4011: multiple .MODEL directives found : .MODEL ignored
 *sound of belch*


jj2007

  • Moderator
  • Member
  • *****
  • Posts: 13945
  • Assembly is fun ;-)
    • MasmBasic
Re: MasmBasic - a fast and easy-to-use library
« Reply #84 on: August 15, 2013, 06:17:32 PM »
Post the sources, Alex :biggrin:

Gunther

  • Member
  • *****
  • Posts: 4196
  • Forgive your enemies, but never forget their names
Re: MasmBasic - a fast and easy-to-use library
« Reply #85 on: August 16, 2013, 02:18:20 AM »
Jochen,

Post the sources, Alex :biggrin:

he will, he will. Please be patient.  :lol:

Gunther
You have to know the facts before you can distort them.

jj2007

  • Moderator
  • Member
  • *****
  • Posts: 13945
  • Assembly is fun ;-)
    • MasmBasic
Olly
« Reply #86 on: August 18, 2013, 11:11:05 AM »
Update 18 August concerns only MasmBasic's default editor, RichMasm (located in \Masm32\RichMasm\RichMasm.exe after installation):

include \masm32\MasmBasic\MasmBasic.inc        ; download
        Init
;       if RichMasm finds at least one int 3 that is not commented out, the editor
;       will launch \Masm32\OllyDbg\ollydbg.exe for the current exe with arguments
        int 3        ; Hit F9 in Olly, it will stop here
        Print "The commandline args are [", CL$(1), "] and [", CL$(2), "]"
        Exit
end start

RichMasm options for seeing symbols in Olly:
OPT_Assembler   JWasm         ; download - must be present in \bin (ML 6.15 works, too)
OPT_DebugA      /Zi           ; activate symbols
OPT_Linker      link          ; Masm32 standard, i.e. version 6.14, must be present in \bin
OPT_DebugL      /debug        ; for debugging
OPT_Arg1        "Hello coder"
OPT_Arg2        "what's cooking in the Masm32 forum?"


Note that Olly must be present as \Masm32\OllyDbg\ollydbg.exe

When Olly starts a console app, the console window will be in the foreground. This is rarely what you want, therefore RichMasm has now learned to move Olly to the foreground, so that you can directly hit F9 without having to click the bl**dy console away.

jj2007

  • Moderator
  • Member
  • *****
  • Posts: 13945
  • Assembly is fun ;-)
    • MasmBasic
Fearless beta testers wanted!
« Reply #87 on: August 23, 2013, 09:07:14 AM »
Since the zipped package was very close to the Forum's 512k limit, I wrote an installer which pushed it down to 322k. Feedback sought regarding
- the EULA
- the extraction process
- whatever observation you may have 8)

Just open the attachment and double-click on MbSetup.exe
(It's not MSI, sorry, but it seems to do the job, too - source will be available soon)

P.S.: Second version posted, the first one didn't find the image for the title bar :(
P.S.: Third version attached, #2 tried to sell VB to Dave, and I hope that is fixed for the time being ;-)

P.S.: See reply #100 for version #4
« Last Edit: August 24, 2013, 05:57:47 PM by jj2007 »

dedndave

  • Member
  • *****
  • Posts: 8828
  • Still using Abacus 2.0
    • DednDave
Re: MasmBasic - a fast and easy-to-use library
« Reply #88 on: August 23, 2013, 01:08:23 PM »
oops - lol
it says MasmBasic is not for me, then googles VB for me   :lol:
nothing cryptic about that message

i have some of my masm32 subfolders named a little differently
perhaps you could tell us which subfolders must be in place before throwing us to the wolves   :biggrin:

great idea, though
i always wondered if i had it set up correctly, before

jj2007

  • Moderator
  • Member
  • *****
  • Posts: 13945
  • Assembly is fun ;-)
    • MasmBasic
Re: MasmBasic - a fast and easy-to-use library
« Reply #89 on: August 23, 2013, 03:40:05 PM »
oops - lol
it says MasmBasic is not for me, then googles VB for me   :lol:

Soooorry... that means I have to revise the routine that checks if user X is a valid member of the Masm32 community :redface:

What I did is check the registry for the asm_auto_file editor. If there is \Masm32\ in one of the possible entries, you are a good user. Which means you are a bad user, Dave :eusa_naughty:

  call IsMasm32        ; check if user has Masm32 installed
  .if eax
        inc GoodUser
        wLet Button1$="Accept && Install"
        wLet Static$="MasmBasic will be installed to "+wChr$(M32$)+"MasmBasic"
  .else
        wLet Button1$="Continue"        ; will open Google ;-)
        wLet Static$="Bye..."
  .endif

IsMasm32:
        ; If an entry exists in both HKLM\SOFTWARE\Classes and HKEY_CURRENT_USER\SOFTWARE\Classes,
        ; then the value of the entry in HKEY_CURRENT_USER\SOFTWARE\Classes takes precedence (MSDN).
        ; Win7: HKCU & HKCR
        Let edi=GetRegVal("HKCU\SOFTWARE\Classes\asm_auto_file\shell\open\command", 0, "No luck in HKCU...")
        .if !Instr_(edi, "\Masm32\", 1)
                Let edi=GetRegVal("HKLM\SOFTWARE\Classes\asm_auto_file\shell\open\command", 0, "No luck in HKLM...")
        .endif
        .if !Instr_(edi, "\Masm32\", 1)
                Let edi=GetRegVal("HKCR\asm_auto_file\shell\open\command", 0, "No luck in HKCR...")
        .endif
        .if !Instr_(edi, "\Masm32\", 1)
                FileWrite "tmp.asm", "MasmBasic is great"
                lea edi, TmpPath$
                invoke FindExecutable, esi, Chr$("\"), edi
                Kill esi
        .endif
        Clr$ esi
        push Instr_(edi, "\Masm32\", 1)
        .if eax
                or ecx, -1
                .Repeat
                        inc ecx
                .Until byte ptr [edi+ecx]>="A"
                sub edx, ecx
                lea eax, [edi+ecx]
                Let M32$=Left$(eax, edx+7)
        .endif       
        pop eax
        retn
end start