How to make a new programming language with MASM32v10?

Started by FritzGamaliel, March 26, 2010, 04:56:19 AM

Previous topic - Next topic

FritzGamaliel

We must followed MASM32v10' grammar if we want to create a program in MASM32v10.

Example:
if we want to do:    number1 + number2  ----> result
We must call a function:
invoke add,ADDR number1,ADDR number2,ADDR result
But, I want to know how to make that line same with the code below:
number1 + number2 = result




And, I want to know how MASM32v10 create it's grammar(example: invoke followed by functionname and parameters)
and it's skeleton(.data, .data?, .code):
;=================================
include myFile.inc

.data

.data?

.code
start:
     invoke functionname,ADDR par1,ADDR par2,ADDR par3             ======> MASM32'grammar
end start
;=================================


Thank you
Fritz

donkey

MASM32 is a collection of libraries, example code, macros and equates, it is not a programming language. MASM, the assembler distributed with MASM32 is the Microsoft Macro Assembler (ml.exe) and its syntax (grammar) for the most part comes from Intel and Microsoft. If you would like to know how to write a compiler you can start with a primer, this one isn't bad Crenshaw. There is also the ability in MASM to mimic a compiler using high level macros, there are a few examples of macros that do this in the MASM32 examples in the distribution package.
"Ahhh, what an awful dream. Ones and zeroes everywhere...[shudder] and I thought I saw a two." -- Bender
"It was just a dream, Bender. There's no such thing as two". -- Fry
-- Futurama

Donkey's Stable

jj2007


You mean something like this: Let My$(123)=MyOther$(ebx) ?
Almost everything is possible with macros. Have a look at the attachment, it's all Pure MasmTM (although it will also assemble with JWasm)


MichaelW

How about a simple BASIC done in MASM:

http://ppanks76.tripod.com/mbi.html?201026

I seem to recall Franck Charlet posting his version on the old forum, but it does not appear to be in the archive.

eschew obfuscation

jj2007

Quote from: MichaelW on March 26, 2010, 08:01:46 AM
How about a simple BASIC done in MASM:

http://ppanks76.tripod.com/mbi.html?201026

I seem to recall Franck Charlet posting his version on the old forum, but it does not appear to be in the archive.


Michael,

I found one version with source code on my hard disk - I hope I don't violate any copyrights if I post it here. The MiniBas.asm is slightly adapted to make it run on Masm32 v10. Extract to some folder, go there, assemble & run, then use
Load castle
Run

to see what it can do:
MINI-BASIC ASCII Art

|---| |---| |---|                 |---| |---| |---|
|   ---   ---   |                 |   ---   ---   |
\              /                  \               /
|            |                    |             |
|            | |---| |---| |---|  |             |
|            |--   ---   ---    --|             |
|                                               |
|                                               |
|                                               |
|             /------------------\              |
|             |[][][][][][][][][]|              |
|             |[][][][][][][][][]|              |
|             |[][][][][][][][][]|              |
|             |[][][][][][][][][]|              |
|             |[][][][][][][][][]|              |
-------------------------------------------------
Castle by dunric


MiniBasic is a nice demo, but what you get is a crippled programming language. That's why I chose to do it the other way round: MasmBasic is not a programming language but rather a library with 70+ commands that looks like Basic and feels like Basic but has in addition everything, virtually everything that Windows (32-bit) can offer - because you never left assembler. Call it an "inline Basic"...

MichaelW

Franck Charlet's MBasic is a great deal less "crippled".

Version 1.8 is supposed to be available here:

http://pagesperso-orange.fr/franck.charlet/misc.html

But the download was not working when I tried.

Version 1.0 is here:

http://www.exmortis.narod.ru/src_inter_eng.html
eschew obfuscation

jj2007

Quote from: MichaelW on March 26, 2010, 10:04:56 AM
Franck Charlet's MBasic is a great deal less "crippled".

Yes, I found it in the meantime, and it is indeed less "crippled". Especially the math functions are quite impressive. But it is still "only" a BASIC language, not assembler... MasmBasic is both ;-)

Attached the download with some tests of mine. The original version does not assemble, there is an odd error maybe deliberately introduced to keep noobs at large...

EDIT: More tests added. For an interpreter, MBasic is indeed very fast.

FritzGamaliel

The first thing I want to know is:
how to make the code below:
invoke add,ADDR number1,ADDR number2,ADDR result   ==========>MASM32v10' grammar (invoke' keyword followed by functionName)

same with:
number1 + number2 = result   ==========> my' grammar

Thank you
Fritz


jj2007

Quote from: FritzGamaliel on March 26, 2010, 10:48:39 AM
number1 + number2 = result   ==========> my' grammar

Not possible with macros. You need at least one initial keyword, e.g.
Let number1 + number2 = result

dedndave

        mov     eax,number1
        add     eax,number2
        mov     result,eax


:P

qWord

Quote from: jj2007 on March 26, 2010, 11:01:58 AMYou need at least one initial keyword
by choosing a keyword that is nearly not visible you can do such stuff  :toothy
_ macro expr:=< >
    pos1 INSTR 1,<&expr>,<=>
    pos2 INSTR 1,<&expr>,<+>
    pos3 INSTR 1,<&expr>,<->
    pos4 INSTR 1,<&expr>,<*>
    pos5 INSTR 1,<&expr>,</>
    IF pos1 EQ 0 OR (pos2 EQ 0 AND pos3 EQ 0 AND pos4 EQ 0 AND pos5 EQ 0)
        .err <invalid expression>
        EXITM
    ENDIF
    pos2 = pos2 OR pos3 OR pos4 OR pos5   ;-)
    larg SUBSTR <&expr>,1,pos2-1
    rarg SUBSTR <&expr>,pos2+1,pos1-pos2-1
    res  SUBSTR <&expr>,pos1+1
    IF pos2 NE 0
        mov eax,larg
        add eax,rarg
        mov res,eax
    ELSEIF pos3 NE 0
        mov eax,larg
        sub eax,rarg
        mov res,eax
    ELSEIF pos4 NE 0
        mov eax,larg
        mul rarg
        mov res,eax
    ELSEIF pos5 NE 0       
        mov eax,larg
        xor edx,edx
        div rarg
        mov res,eax
    ENDIF   
endm


_ edx+ecx = ebx
FPU in a trice: SmplMath
It's that simple!

jj2007

Quote from: qWord on March 26, 2010, 12:57:23 PM
by choosing a keyword that is nearly not visible you can do such stuff  :toothy

You cheat :green

include \masm32\include\masm32rt.inc

Calc MACRO args
LOCAL posplus, posequ, dest, sources, src
  posequ INSTR <args>, <=>
  dest SUBSTR <args>, posequ+1
  sources SUBSTR <args>, 1, posequ-1
  posplus INSTR sources, <+>
  if posplus
src SUBSTR sources, 1, posplus-1
sources SUBSTR sources, posplus+1
push src
While posplus
posplus INSTR sources, <+>
if posplus
src SUBSTR sources, 1, posplus-1
sources SUBSTR sources, posplus+1
else
src SUBSTR sources, 1
endif
if ((opattr(src)) and 127) eq 48 ;; register?
add [esp], src
else
mov eax, src
add [esp], eax
endif
Endm
  else
push sources
  endif
  pop dest
ENDM

.data
result dd 0
number1 dd 111
number2 dd 222
number3 dd 333

.code
start:
Calc number1 + number2 + number3 + number3 = result
; Calc number1 = result ; works, too
print "The result is "
inkey str$(result)
exit

end start

qWord

writing macros is cheating  :green

BTW: the stack usage is an nice idea
FPU in a trice: SmplMath
It's that simple!

jj2007

Quote from: qWord on March 26, 2010, 02:20:24 PM
writing macros is cheating  :green
Nooooo... :red

Quote
BTW: the stack usage is an nice idea

Thanks :bg
That's how I do the offsets in the for loop:
QuoteFor_ n=0 To eax-1
      dec eax ; no problem
   Next

FritzGamaliel

But we still use FileName.asm
Can we use new file' type
Example:
FileName.myType

Then, we create our grammar?

Thank you
Fritz.