The complete code is a bit too long to be displayed here ... download it to have a look.
Here's the ASM bytes (for each of the three Shift operations):
Private Const SHLCode As String = "8A4C240833C0F6C1E075068B442404D3E0C20800" ' shl eax, cl = D3 E0
Private Const SHRCode As String = "8A4C240833C0F6C1E075068B442404D3E8C20800" ' shr eax, cl = D3 E8
Private Const SARCode As String = "8A4C240833C0F6C1E075068B442404D3F8C20800" ' sar eax, cl = D3 F8
|
Author's comments:
' These functions are inline asm hacks for SHL and SHR aka << >>
' in C, C++. They shift using the following ASM code:
' mov eax, [esp+4]
' mov cl, [esp+8]
' shr eax, cl ; or shl eax, cl
' ret 8
' Only the first five bits of the cl register are evaluated for either op code.
' So, as in C, if you do shl 8, 33 its the equivalent of shl 8, 1
' as (33 AND 31) = 1
' or shr 8, -1 is the same as shr 8, 31 as (255 and 31) = 31
' Personally, I think VB is sorely in need of true bit shifting ops,
' but MS assumes we VB programmers are a mindless bunch :(
' NOTE: YOU *MUST* CALL InitFunctionsShift() BEFORE USING THESE FUNCTIONS
|