Theo's Forum

IT-Consultant: Charles Pegge => Assembler => Best place to post any assembler code => Topic started by: Theo Gottwald on December 21, 2009, 07:57:51 AM

Title: Shift BYTE and SHift DWORD Macros
Post by: Theo Gottwald on December 21, 2009, 07:57:51 AM
To get our collection of ASM GEM's forward, here are some SHIFTING Macros.

' #REGISTER:
' ESI - PB  Registervar 1
' EDI - PB Registervar  2

Code: [Select]
' Shift BYTE v by s to left

MACRO FUNCTION SHL_B(V, S)
    MACROTEMP V1
    DIM V1 AS BYTE
    ! pushad
    ! xor eax, eax
    ! xor ecx, ecx
    ! mov al, v
    ! mov cl, s
    ! shl eax, cl
    ! mov v1, al
    ! popad
END MACRO = V1

' Shift BYTE v by s to right

MACRO FUNCTION SHR_B(V, S)
    MACROTEMP V1
    DIM V1 AS BYTE
    ! pushad
    ! xor eax, eax
    ! xor ecx, ecx
    ! mov al, v
    ! mov cl, s
    ! shr eax, cl
    ! mov v1, al
    ! popad
END MACRO = V1

And here the Shift DWORD Macros.

Code: [Select]
' Shift DWORD v by s to left

MACRO FUNCTION SHL_D(V, S)
    MACROTEMP V1
    DIM V1 AS DWORD
    ! pushad
    ! mov eax, v
    ! mov ecx, s
    ! shl eax, cl
    ! mov v1, eax
    ! popad
END MACRO = V1

Code: [Select]
' Shift DWORD v by s to right
MACRO FUNCTION SHR_D(V, S)
    MACROTEMP V1
    DIM V1 AS DWORD
    ! pushad
    ! mov eax, v
    ! mov ecx, s
    ! shr eax, cl
    ! mov v1, eax
    ! popad
END MACRO = V1