Page 2 of 2 FirstFirst 12
Results 11 to 19 of 19

Thread: Is there a bit-shift function?

  1. #11

    Re: Is there a bit-shift function?

    Wow...

    I haven't even gotten that far yet.

    I don't think that has enough wide-range use to take up valuable function in the core. (Seems like it might just add dead weight. Being unused by a majority of users.)

    But those codes would make great samples or snippets in the help-files.

    (Again, I am lost on the machine codes, but I would assume they are the fastest.)

  2. #12

    Re: Is there a bit-shift function?

    Quote Originally Posted by ISAWHIM
    I don't think that has enough wide-range use to take up valuable function in the core. (Seems like it might just add dead weight. Being unused by a majority of users.)
    Oxygen is not part of the core. It is a module developed by Charles. So it doesn't add weight but gives raw execution power to the people who need it and know how to use it. I'm very happy that Charles keeps going on with the development. I'm pretty sure that our current thinStudio project will use it.

  3. #13

    Re: Is there a bit-shift function?

    ??? what is thinStudio...

    (I was talking about the round-about bit-shift being low use. Since the function is so small, just adding one of those would do the trick. I am not sure what is involved in making a whole new function. Seems it would take more than the sample-codes, for data-checking of passed values, to determine how to shift in a round-about method.)

    That would make a neat Obfuscate trick. (Keeping the decrypted code in memory, but shifted so it only makes sense to the thinBASIC program. Where it would normally keep the translated code in raw form in memory. Might not work for all the code in memory, but I am sure that some of it could be bit-shifted until needed. Using a bit-mask would help too. Then they could not do a RAM-DUMP, and see our source. Well, they could, but it would take longer. Mess with them, use random bit-shifting and random bit-masks.)

    (Not sure if that is within the scope of this project.)

    I do know I would use it...
    If it did STRING, and/or FILE. (Again, If it did one, a little code on our end, could make it work for both.)

  4. #14

    Re: Is there a bit-shift function?

    Quote Originally Posted by ISAWHIM
    ??? what is thinStudio...

    (I was talking about the round-about bit-shift being low use. Since the function is so small, just adding one of those would do the trick. I am not sure what is involved in making a whole new function. Seems it would take more than the sample-codes, for data-checking of passed values, to determine how to shift in a round-about method.)
    Ahh, ok. I thought you ment the Oxygen assembler module. Sorry, my fault.

    thinStudio is a group of thinBasic user/developer who work on a game for a contest on a different website right now.

  5. #15

    Re: Is there a bit-shift function?


    Using the latest thinBasic 1.7 with the latest Oxygen. It is possible to write assembled functions like this:

    [code=thinbasic]

    uses "OXYGEN"

    dim v1,v2 as long

    o2_buf 1 : o2_asmo " mov eax,[esp+4] : mov ecx,[esp+8] : rol eax,cl : ret 8 "
    declare function ROL (byval v as long, byval n as long ) as long at o2_buf 1


    o2_buf 2 : o2_asmo " mov eax,[esp+4] : mov ecx,[esp+8] : ror eax,cl : ret 8 "
    declare function ROR (byval v as long, byval n as long ) as long at o2_buf 2


    if len(o2_error) then msgbox 0,o2_error()+o2_view (src) : stop

    v1=ROR 1,2 ' rotate number, places to the right
    v2=ROL 1,2 ' rotate number, places to the left

    msgbox 0,"&h"+hex$(v1)+$cr+"&h"+hex$(v2)

    [/code]

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

    Re: Is there a bit-shift function?

    Prynhawn da Charles,

    I have never been interested in using Oxygen because I never liked the instruction set (nothing personal to you charles) but that last example was an interesting Idea.

    If I can pick certain commands and wrap them in a function thats quite useful, i wouldnt want the extra speed that Oxygen offers just some of its commands.

    thanks for that.
    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

  7. #17

    Re: Is there a bit-shift function?

    Hi Michael, Croeso!

    If all goes well, Oxygen will support Basic syntax in a few week's time. Assembler is quite a lot to learn. But I have grown up with it.


    Here is a bit rotation procedure for a whole string of any length:


    [code=thinbasic]

    uses "OXYGEN"

    dim src as string
    dim s as string

    src= "
    push edi
    mov edi,[esp+8]
    mov edi,[edi]
    mov edx,[edi-4] ' length
    mov eax,edx
    (
    dec edx ' does not affect carry flag
    jl exit ' start with the final byte and work back
    rcr byte [edi+edx],1 ' rotate carry right
    repeat
    )
    ' insert final carried bit
    (
    jae exit ' no carry
    cmp eax,0
    jle exit ' null string
    or byte [edi+eax-1],0x80
    )
    pop edi
    ret 4
    "

    o2_buf 1 : o2_asmo src : declare sub RORS ( s as string ) at o2_buf 1

    if len(o2_error) then msgbox 0,o2_error()+o2_view (src) : stop

    s="bit rotate the whole string one place to the right"

    RORS s

    msgbox 0,s

    [/code]

  8. #18

    Re: Is there a bit-shift function?

    To verify correct operation here is RORS and its complementary twin ROLS cancelling each other out:

    [code=thinbasic]

    uses "OXYGEN"

    dim src as string
    dim s as string

    src= "
    push edi
    mov edi,[esp+8]
    mov edi,[edi]
    mov edx,[edi-4] ' length
    mov eax,edx
    (
    dec edx ' does not affect carry flag
    jl exit ' start with the final byte and work back
    rcr byte [edi+edx],1 ' rotate carry right
    repeat
    )
    ' insert final carried bit
    (
    jae exit ' no carry
    cmp eax,0
    jle exit ' null string
    or byte [edi+eax-1],0x80
    )
    pop edi
    ret 4
    "

    o2_buf 1 : o2_asmo src : declare sub RORS ( s as string ) at o2_buf 1

    src= "
    push edi
    mov edi,[esp+8]
    mov edi,[edi]
    mov edx,[edi-4] ' length
    mov eax,edx
    (
    dec edx ' does not affect carry flag
    jl exit ' start with the first byte and work forward
    rcl byte [edi],1 ' rotate carry left
    inc edi
    repeat
    )
    ' insert final carried bit
    (
    jae exit ' no carry
    cmp eax,0
    jle exit ' null string
    sub edi,eax
    or byte [edi],0x1
    )
    pop edi
    ret 4
    "

    o2_buf 2 : o2_asmo src : declare sub ROLS ( s as string ) at o2_buf 2



    if len(o2_error) then msgbox 0,o2_error()+o2_view (src) : stop

    s="bit rotate the whole string one place to the right"

    RORS s
    ROLS s

    msgbox 0,s

    [/code]

  9. #19

    Re: Is there a bit-shift function?



    By using an outer loop the string bits can be rotated several places in one call

    [code=thinbasic]

    uses "OXYGEN"

    dim src as string
    dim s as string

    src= "
    push edi
    mov ecx,[esp+12]
    (
    dec ecx
    jl exit
    mov edi,[esp+8]
    mov edi,[edi]
    mov edx,[edi-4] ' length
    mov eax,edx
    (
    dec edx ' does not affect carry flag
    jl exit ' start with the final byte and work back
    rcr byte [edi+edx],1 ' rotate carry right
    repeat
    )
    ' insert final carried bit
    (
    jae exit ' no carry
    cmp eax,0
    jle exit ' null string
    or byte [edi+eax-1],0x80
    )
    repeat
    )
    pop edi
    ret 4
    "

    o2_buf 1 : o2_asmo src : declare sub RORSN ( s as string, byval n as long ) at o2_buf 1

    src= "
    push edi
    mov ecx,[esp+12]
    (
    dec ecx
    jl exit
    mov edi,[esp+8]
    mov edi,[edi]
    mov edx,[edi-4] ' length
    mov eax,edx
    (
    dec edx ' does not affect carry flag
    jl exit
    rcl byte [edi],1 ' rotate carry left
    inc edi
    repeat
    )
    ' insert final carried bit
    (
    jae exit ' no carry
    cmp eax,0
    jle exit ' null string
    sub edi,eax
    or byte [edi],0x1
    )
    repeat
    )
    pop edi
    ret 4
    "

    o2_buf 2 : o2_asmo src : declare sub ROLSN ( s as string, byval n as long ) at o2_buf 2



    if len(o2_error) then msgbox 0,o2_error()+o2_view (src) : stop

    s="bit rotate the whole string one place to the right"

    RORSN s,5
    ROLSN s,5

    msgbox 0,s

    [/code]

Page 2 of 2 FirstFirst 12

Similar Threads

  1. For SHIFT keyword
    By ErosOlmi in forum Samples for help file
    Replies: 0
    Last Post: 26-05-2007, 10:25

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
  •