Results 1 to 2 of 2

Thread: Exciting new feature: Emit()

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Jul 2010
    Location
    NYC
    Posts
    6,256

    Exciting new feature: Emit()

    Thought this new feature worth highlighting for those that don't follow tB Discord or language design forum regularly.

    twinBASIC now supports Naked functions and Emit(), which emits assembly code directly into the compiled exe.

    For example, the current InterlockedIncrement intrinsic from my WinDevLib project, currently linked in as a static library (since it's not exported from 64bit kernel32.dll).

    Code:
    Public Function InlineInterlockedIncrement CDecl Naked(Addend As Long) As Long
    #If Win64 Then
        Emit(&Hb8, &H01, &H00, &H00, &H00)        ' mov    eax,0x1
        Emit(&Hf0, &H0f, &Hc1, &H41, &H00)        ' lock xadd DWORD PTR [rcx+0x4],eax
        Emit(&Hff, &Hc0)                          ' inc    eax
        Emit(&Hc3)                                ' ret 
    #Else
        Emit(&H8b, &H4c, &H24, &H04)       ' mov     ecx, DWORD PTR _Addend$[esp-4]
        Emit(&Hb8, &H01, &H00, &H00, &H00) ' mov     eax, 1
        Emit(&Hf0, &H0f, &Hc1, &H01)       ' lock xadd DWORD PTR [ecx], eax
        Emit(&H40)                         ' inc     eax
        Emit(&Hc3)                         ' ret     0
    #End If
    End Function
    For more info and examples, see the recent comments to this post: https://github.com/twinbasic/lang-design/issues/65
    Last edited by fafalone; Sep 14th, 2024 at 03:41 AM.

  2. #2

    Thread Starter
    PowerPoster
    Join Date
    Jul 2010
    Location
    NYC
    Posts
    6,256

    Re: Exciting new feature: Emit()

    There's now also EmitAny() to use on other size data types (Integer, Long, and LongLong), and StackOffset() to get the stack offset of parameters and local variables.

Tags for this Thread

Posting Permissions

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



Click Here to Expand Forum to Full Width