Page 1 of 6 123 ... LastLast
Results 1 to 10 of 56

Thread: Oxygen Module for Structured Machine Code Programming

  1. #1

    Oxygen Module for Structured Machine Code Programming

    Updated 17 Mar 2008 13:20 gmt
    New zip:
    Oxygen with integrated thinBasic # variables
    No longer case sensitive.
    New thinCore interface for FreeBasic (work in progress)


    This is my first thinBasic module.

    It is based on my O2 (alias Oxygen) project which supports block structured machine code. It is intended to be used in conjunction with MC_Eval and MC_Exec. The O2 notation uses the same quote mark for comments as ThinBasic and does not use double quotes to delineate its own string literals. This enables Oxygen scripts to be incorporated, without any modifications into thinBasic multi-line strings. Oxygen Strings are 'glued' onto the end of MC_Eval strings to bind to thinBasic variables etc. The example included shows how this is done.


    I reproduce it here:
    [code=thinbasic]
    uses "Oxygen"
    dim vv as long = 5
    dim sMC as string=MC_Eval ("
    b9 #vv
    8b 09
    ")+Oxygen_Eval("

    '--------------'
    ' TESTS
    '
    ' 12:10 14 Mar 2008
    '
    '--------------'
    ' nested loops
    '--------------'

    33 d2
    (
    b8 nl10
    (
    42
    48 7f repeat
    )
    49
    7f repeat
    )
    eb gEnd ' jump over some string data
    [ this is a string ]

    .End_of_Prog

    8b c2
    c3
    ")
    Dim RetVal as long
    RetVal=MC_Exec(sMC)
    msgbox 0, Hex$(RetVal)

    [/code]

    Since Oxygen_Eval returns a BSTR, which PB uses for its dynamic strings, I hope I am right in assuming the returned string will be correctly disposed of by thinBasic when it is no longer needed ?

    The Zip below includes source code, docs and the dll module which has no other dependencies. But I need to produce lots of examples to fully demonstrate its use.
    Attached Files Attached Files

  2. #2
    thinBasic MVPs kryton9's Avatar
    Join Date
    Nov 2006
    Location
    Naples, Florida & Duluth, Georgia
    Age
    67
    Posts
    3,869
    Rep Power
    404

    Re: Oxygen Module for Structured Machine Code Programming

    It almost gave the correct answer to the meaning of life (hitchhikers guide to the galaxy) 42, I got 32, but if that is in hex I guess it is 50 in decimal.
    Acer Notebook: Win 10 Home 64 Bit, Core i7-4702MQ @ 2.2Ghz, 12 GB RAM, nVidia GTX 760M and Intel HD 4600
    Raspberry Pi 3: Raspbian OS use for Home Samba Server and Test HTTP Server

  3. #3

    Re: Oxygen Module for Structured Machine Code Programming

    Hi Charles,

    first of all, thank you for your support of thinBasic. Every new module makes the package more powerful and one day it will help someone. I also vote for some example and docu as I can't get my head right now around it.

    Cheers
    Michael

  4. #4

    Re: Oxygen Module for Structured Machine Code Programming


    Here is the instruction set so far. I will refrain from adding more and see what can be done using the set in its present state.

       ------------------------------------------------------------------------
        INSTRUCTION SET
       ------------------------------------------------------------------------
       all instructions are case sensitive (lowercase) except for hexadecimal
       all words are delimited by white space or comment mark
        '    comment to end of line
        [..]   string literal (the square brackets are nestable)
        .label  forward labels (only the first 2 letters are significant)
        :    make entry in jump table
        $    make space (value in hexadecimal)
        $$    make space & align to nearest 4 bytes
        2 digits 0-9 a-f hexadecimal byte (these are not case sensitive)
        3 digits 0-7 octal byte 
        g     short forward relative jump (but not into an inner block)
        gl    long forward relative jump (ditto)
        (     start of block
        )     end of block
        x     short jump exit from block
        xl     long jump exit from block
        r     short jump repeat from start of block
        rl     long jump repeat from start of block
        h     hexadecimal numbers: (not case sensitive)
        hw       word:  2 byte integer
        hl      long:  4 byte integer
        n     decimal numbers:
        nb      byte  1 byte
        nw      word:  2 byte integer
        nl      long:  4 byte integer
        nq       quad:  8 byte integer
        ns       single: 4 byte floating point
        nd      double: 8 byte floating point
       
       ------------------------------------------------------------------------
    

  5. #5
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,777
    Rep Power
    10

    Re: Oxygen Module for Structured Machine Code Programming

    Thanks a lot Charles!
    Machine code is not my "core business" (I still cannot understand it very well) but I appreciate a lot your efforts. Hope it will move some passion.

    Quote Originally Posted by Charles Pegge
    Since Oxygen_Eval returns a BSTR, which PB uses for its dynamic strings, I hope I am right in assuming the returned string will be correctly disposed of by thinBasic when it is no longer needed ?
    Yes, thinCore should dispose allocated BSTR.
    I will check asap and if not I will fix it.

    Ciao
    Eros
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

  6. #6
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,128
    Rep Power
    732

    Re: Oxygen Module for Structured Machine Code Programming

    Thanks Charles,

    so far it looks like a very nice addition!


    Petr
    Learn 3D graphics with ThinBASIC, learn TBGL!
    Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB

  7. #7

    Re: Oxygen Module for Structured Machine Code Programming

    I am delighted to say that creating a thinBasic module was painless.

    I followed Eros sample code very closely, and got the Oxygen module working without any hitches. I wasn't certain how Freebasic would read a BSTR into its own dynamic string structure so I wrote a low level string copy which interprets the BSTR structure precisely rather than casting it as a Zstring (Asciiz in PB terms). It could be done with PEEKS and POKES but I used a short piece of ASM.

    The reason that FreeBasic does not use BSTR for its dynamic strings, is that they are Microsoft platform dependent, so it has its own system that will also work under Linux.

    Anyway here is the interface function, most of which deals with the BSTR to FB dynamic string transfer

    FreeBasic [code=thinbasic]
    Function Oxygen() AS BSTR

    Dim ParensPresent As Long

    ParensPresent = thinBasic_CheckOpenParens_Optional

    Dim codBSTR As BSTR '---OLE string will be used to return value to thinCore

    dim srcBSTR As BSTR
    dim src as string
    dim cod as string
    dim ert as long
    dim i as long
    dim j as any ptr

    thinBasic_ParseString(srcBSTR)
    asm
    mov eax,[srcBSTR]
    mov ecx,[eax-4]
    mov [i],ecx
    end asm
    if i>0 then
    ' copy to freebasic dynamic string then compile
    src=string$(i,chr$(0))
    j=strptr(src)
    asm
    mov esi,[srcBSTR]
    mov edi,[j]
    mov ecx,[i] 'length of data
    nexch:
    mov al,[esi] ' src
    mov [edi],al ' dest
    inc esi
    inc edi
    dec ecx
    jnz nexch
    end asm
    cod=Hexlink( src,ert,i ) ' the Oxygen compiler linker
    end if

    codBSTR = SysAllocStringByteLen( strptr(cod), Len(cod) )

    If ParensPresent = TB_TRUE Then thinBasic_CheckCloseParens_Mandatory

    Function = codBSTR

    End Function

    [/code]

  8. #8

    Re: Oxygen Module for Structured Machine Code Programming

    Hi Charles,

    first of all thank you very much for starting the new thinbasic Oxygen module.
    It seems a very interesting module that opens many others way of development that will make sure ThinBasic able to better meet what the user needs .

    Regards,
    Roberto
    http://www.thinbasic.com

  9. #9

    Re: Oxygen Module for Structured Machine Code Programming

    Thank you all

    When there are updates, I will replace the Oxygen zip file attached to the first post on this thread. and I'll post examples with the other MC_Evals on the machine code board;
    http://community.thinbasic.com/index.php?board=151.0

    thinBasic_Oxygen will be synchronised with its stand alone counterpart that works directly from the console.
    available here:

    http://www.jose.it-berater.org/smffo...php?topic=1618

  10. #10

    Re: Oxygen Module for Structured Machine Code Programming

    Ok thanks for details, it will be really great if you can also add a step up from machine code to assembler code.

    Roberto
    http://www.thinbasic.com

Page 1 of 6 123 ... LastLast

Similar Threads

  1. Oxygen module source code on thinSVN server
    By ErosOlmi in forum thinSVN
    Replies: 8
    Last Post: 20-04-2009, 07:05

Members who have read this thread: 0

There are no members to list at the moment.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •