Page 3 of 5 FirstFirst 12345 LastLast
Results 21 to 30 of 44

Thread: Dynamic assembly machine code in thinBasic

  1. #21

    Re: Dynamic assembly machine code in thinBasic

    Here is another example. This one uses a loop.

    [code=thinbasic]
    ' Array filled with PI
    '----------------------------------------------
    dim sgl(16) as single
    '----------------------------------------------
    sASM = MC_Eval$ "
    b8 #sgl ' address to eax
    b9 NL16 ' mov ecx,16 16 repeats
    ' do '
    d9 eb ' fldpi load pi
    d9 18 ' fstp [eax] store 32bit float and pop
    05 NL4 ' add eax,4 next element
    49 ' dec ecx
    7f f4 ' jg do repeat 12 bytes back
    ' '
    b8 NL2 ' mov eax,2 retval 2 in eax
    C3
    "
    '----------------------------------------------
    '---Get the address of the ASM string
    psASM = strPTR(sASM) ' address of code
    '---Fire the direct call using dynamic asm
    CALL DWORD psASM to RetVal ' make the call and get the return value

    '---Show return value
    MsgBox 0, sgl(1)+" "+sgl(16)
    [/code]

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

    Re: Dynamic assembly machine code in thinBasic

    Hi Charles,

    pure magic with that PI


    Thanks,
    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

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

    Re: Dynamic assembly machine code in thinBasic

    Pure magic for sure. Try to substitute 16 with 16 millions

    [code=thinbasic]
    ' Array filled with PI
    '----------------------------------------------
    dim sgl(16000000) as single
    '----------------------------------------------
    sASM = MC_Eval$ "
    b8 #sgl ' address to eax
    b9 NL16000000 ' mov ecx,16 16 repeats
    ' do '
    d9 eb ' fldpi load pi
    d9 18 ' fstp [eax] store 32bit float and pop
    05 NL4 ' add eax,4 next element
    49 ' dec ecx
    7f f4 ' jg do repeat 12 bytes back
    ' '
    b8 NL2 ' mov eax,2 retval 2 in eax
    C3
    "
    '----------------------------------------------
    '---Get the address of the ASM string
    psASM = strPTR(sASM) ' address of code
    '---Fire the direct call using dynamic asm
    CALL DWORD psASM to RetVal ' make the call and get the return value

    '---Show return value
    MsgBox 0, sgl(1)+" "+sgl(16000000)
    [/code]

    Speed is ... inconsistent.
    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

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

    Re: Dynamic assembly machine code in thinBasic

    Updated thinCore.dll. New DLL is attached to the following post http://community.thinbasic.com/index...11307#msg11307
    Just download and substitute thinCore.dll you have into \thinBasic\ directory.

    Added MC_Exec(StringMachineCode) function in substitution to CALL DWORD ...
    With MC_Exec there is no need to calculate pointer to string to be passed to CALL DWORD ... statement. Just pass the machine code string and you will get back return LONG.

    So previous code can be rewritte to:
    [code=thinbasic]
    ' Array filled with PI
    '----------------------------------------------
    dim sgl(16) as single
    '----------------------------------------------
    sASM = MC_Eval "
    b8 #sgl ' address to eax
    b9 NL16 ' mov ecx,16 16 repeats
    ' do '
    d9 eb ' fldpi load pi
    d9 18 ' fstp [eax] store 32bit float and pop
    05 NL4 ' add eax,4 next element
    49 ' dec ecx
    7f f4 ' jg do repeat 12 bytes back
    ' '
    b8 NL2 ' mov eax,2 retval 2 in eax
    C3
    "
    '----------------------------------------------
    '---Invoke the machine code string
    RetVal = MC_Exec(sASM)
    '---No need to calculate STRPTR(sASM) to be used into CALL DWORD ...
    '----------------------------------------------

    '---Show return value
    MsgBox 0, RetVal & $crlf & sgl(1)+" "+sgl(16)
    [/code]

    As usual, update will be present in next preview release.

    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

  5. #25

    Re: Dynamic assembly machine code in thinBasic

    Yes, Ive just tested out to 160million, it is the operating system, memory management and various other processes that are able to interrupt the procedings. These will inevitably cause irregular timings. But if the script is run several times, it settles to a fairly stable figure. - about 0.625 seconds for 160 million elements on my PC.

    When the FPU instructions are removed (not forgetting to adjust the loop jump), the time drops to 0.115 secs. The FPU is thorough but slow as you will see with trig functions. In fact you can do a lot of useful work on the CPU while the FPU is thinking about the next cosine, so even at the single core level timing is not entirely predictable. Even individual CPU registers can compute in parallel.

    PS thanks for the Exec function!

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

    Re: Dynamic assembly machine code in thinBasic

    A pleasure Charles.

    I've updated again thinCore.dll here: http://community.thinbasic.com/index...11307#msg11307

    In case of MC_Eval found some parsing error, no runtime errors are generated but &HC3 string will be returned as suggested.
    If machine string will be equal to &HC3, MC_Exec will not get back any value but just zero will be returned.

    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

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

    Re: Dynamic assembly machine code in thinBasic

    Thanks for improvements Eros,

    sadly ( or luckily ? ) I could not get any inconsistent results, just lightning fast execution on high numbers of iterations.


    Bye,
    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

  8. #28
    thinBasic MVPs
    Join Date
    May 2007
    Location
    UK
    Posts
    1,427
    Rep Power
    159

    Re: Dynamic assembly machine code in thinBasic

    I may have missed it but can you modify the string while the script is executing then call it get the value back modify it again and call it....you get the idea is it fixed as soon as the script is executed.

    Home Desktop : Windows 7 - Intel Pentium (D) - 3.0 Ghz - 2GB - Geforce 6800GS
    Home Laptop : WinXP Pro SP3 - Intel Centrino Duo - 1.73 Ghz - 2 GB - Intel GMA 950
    Home Laptop : Windows 10 - Intel(R) Core(TM) i5-4210U CPU @ 1.70GHz, 2401 Mhz, 2 Core(s), 4 Logical Processor(s) - 4 GB - Intel HD 4400
    Work Desktop : Windows 10 - Intel I7 - 4 Ghz - 8GB - Quadro Fx 370

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

    Re: Dynamic assembly machine code in thinBasic

    Abraxas, is it a question?
    Sorry I do not understand if you are asking a confirmation or not.

    If it is aquestion, yes. You can change (or create) the string dynamically outside MC_Eval.
    Then call MC_Eval to get back a binary form of the string.
    Than call MC_Exec

    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

  10. #30
    thinBasic MVPs
    Join Date
    May 2007
    Location
    UK
    Posts
    1,427
    Rep Power
    159

    Re: Dynamic assembly machine code in thinBasic

    yes it was a question, just badly worded

    you answer it it anyway and it was the answer I wanted.

    thanks

    Home Desktop : Windows 7 - Intel Pentium (D) - 3.0 Ghz - 2GB - Geforce 6800GS
    Home Laptop : WinXP Pro SP3 - Intel Centrino Duo - 1.73 Ghz - 2 GB - Intel GMA 950
    Home Laptop : Windows 10 - Intel(R) Core(TM) i5-4210U CPU @ 1.70GHz, 2401 Mhz, 2 Core(s), 4 Logical Processor(s) - 4 GB - Intel HD 4400
    Work Desktop : Windows 10 - Intel I7 - 4 Ghz - 8GB - Quadro Fx 370

Page 3 of 5 FirstFirst 12345 LastLast

Similar Threads

  1. DEP and machine code
    By Petr Schreiber in forum Machine Code
    Replies: 4
    Last Post: 13-03-2008, 22:13

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
  •