News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

Inline assembly and FreeBASIC

Started by Vortex, Today at 04:48:07 AM

Previous topic - Next topic

Vortex

Hello,

A quick example of using inline assembly with FreeBASIC :

Function LowerCase Naked (s As String) As ZString Ptr

     Asm

.data


lcase_table:

    .byte 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
    .byte 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
    .byte 0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0
    .byte 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
    .byte 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
    .byte 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
    .byte 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
    .byte 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0

.text

    mov     rdx,QWORD PTR [rcx]
    mov     r10,OFFSET lcase_table
    sub     rdx,1

_loop:

    add     rdx,1
    movzx   rax,BYTE PTR [rdx]
    movzx   r8,BYTE PTR [r10+rax]
    shl     r8,5
    add     BYTE PTR [rdx],r8b
    jnz     _loop
    mov     rax,QWORD PTR [rcx]
    ret
      
    End Asm
   
End Function


Dim As String t="THIS is a TEST."

Print *Lowercase(t)