; ********************************************************************************************************************* ; Mnemonic Functions ; Optimized for the Pentium and Pentium MMX ; v0.0.1 ; ; Date Created: 2007-04-29 ; Last Modified: 2007-09-29 BITS 32 ; Uncomment this define if using -1 for boolean values ;%DEFINE BOOLEANVALUE_MINUS1 ; ##################################################################################################################### ; ##################################################################################################################### ; ##################################################################################################################### ; Macros ; ********************************************************************************************************************* ; Created: v0.0.1 ; Last Modified: v0.0.1 ; Reads in a U24 value from a memory location ; EAX = Zero-extended version of the 24bit value ; Lost Regs: None ; Cycles: 4-5 %macro Macro_ReadU24 1 xor eax, eax ; 1 Clear to 0 mov ah, [%1 + 2] ;U*1 Get the high byte mov al, [%1 + 1] ;U*1 Get the middle byte shl eax, 8 ;U!1 Shift into position mov al, [%1] ;U*1 Get the low byte ;= 4-5 cycles %endmacro ; Macro_ReadU24 ; ********************************************************************************************************************* ; Created: v0.0.1 ; Last Modified: v0.0.1 ; Reads in a S24 value from a memory location ; EAX = Sign-extended version of the 24bit value ; Lost Regs: None ; Cycles: 4-5 %macro Macro_ReadS24 1 mov ah, [%1 + 2] ; 1 Get the high byte mov al, [%1 + 1] ;U*1 Get the middle byte shl eax, 16 ;U!1 Shift to the top sar eax, 8 ;U!1 SAR to sign extend mov al, [%1] ;U*1 Get the low byte ;= 4-5 cycles %endmacro ; Macro_ReadS24 ; ********************************************************************************************************************* ; Created: v0.0.1 ; Last Modified: v0.0.1 ; Writes a 32bit value to a U/S24 ; Lost Regs: eax ; Cycles: 3-4 %macro Macro_WriteUS24 1 mov [%1], al ; 1 Store the low byte mov [%1 + 1], ah ;U*1 Store the middle byte shr eax, 8 ;U*1 Shift the high value down mov [%1 + 2], ah ;U*1 Store the high byte ;= 4-5 cycles %endmacro ; Macro_WriteUS24 ; U24 is the same as the US24 %define Macro_WriteU24 Macro_WriteUS24 ; S24 is the same as the U24 %define Macro_WriteS24 Macro_WriteU24 ; ********************************************************************************************************************* ; Created: v0.0.1 ; Last Modified: v0.0.1 ; Divide AL by an 8bit immediate ; Returns: ah = AL / IMM8, al = AL % IMM8 ; Lost Regs: None ; Cycles: 18 %macro Macro_DivideImmediate8 1 db 0D4h db %1 %endmacro ; Macro_DivideImmediate8 ; ##################################################################################################################### ; ##################################################################################################################### ; ##################################################################################################################### SECTION .text ; @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ ; @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ ; General Functions ; These functions are not tied to specific mnemonics, but exist to make mnemonic code easier ; ********************************************************************************************************************* ; Created: v0.0.1 ; Last Modified: v0.0.1 ; General function to retrieve a U24 as a 32bit value ; In: EDX -> 24bit value to retrieve ; Out: EAX = Zero-extended version of the 24bit value ; Lost Regs: None ; Cycles: 7 ALIGN 16 General_ReadU24: Macro_ReadU24 edx ; 5 Read in the value ret ;--2 ;= 7 cycles .EndFunc ; General_ReadU24 ; ********************************************************************************************************************* ; Created: v0.0.1 ; Last Modified: v0.0.1 ; General function to retrieve a S24 as a 32bit value ; In: EDX -> 24bit value to retrieve ; Out: EAX = Sign Extended version of the 24bit value ; Lost Regs: None ; Cycles: 7 ALIGN 16 General_ReadS24: Macro_ReadS24 edx ; 5 Read in the value ret ;--2 ;= 7 cycles .EndFunc ; General_ReadS24 ; ********************************************************************************************************************* ; Created: v0.0.1 ; Last Modified: v0.0.1 ; General function to store a 32bit value as a U/S24 ; In: EAX = 32bit value, EDX -> 24bit value to store to ; Out: Nothing ; Lost Regs: eax ; Cycles: 6 ALIGN 16 General_WriteUS24: Macro_WriteUS24 edx ; 4 ret ;--2 ;= 6 cycles .EndFunc ; General_WriteUS24 ; ********************************************************************************************************************* ; Created: v0.0.1 ; Last Modified: v0.0.1 ; Converts a 24bit value to a boolean value ; In: EDX -> 24bit value to convert ; Out: AL = Boolean Value ; Lost Regs: eax ; Cycles: 11 ALIGN 16 TypeCast_US24ToBoolean: push ecx ;U 1 Preserve ECX xor ecx, ecx ;U 1 Clear to zero mov cl, [edx] ;U*1 Get the low byte or cl, [edx + 1] ;U*2 OR with the middle byte or cl, [edx + 2] ;U*2 OR with the high byte %ifdef BOOLEANVALUE_MINUS1 add ecx, -1 ;U*1 Add -1. This will set carry if it is non-zero sbb al, al ;U!1 -1 if carry, 0 if no carry %else xor eax, eax ; V1 Clear to zero add ecx, -1 ;U 1 Add -1. This will set carry if it is non-zero adc al, al ;U!1 1 if carry, 0 if no carry %endif pop ecx ; V1 Restore ECX ret ;--2 ;= 11 cycles .EndFunc ; TypeCast_US24ToBoolean ; ********************************************************************************************************************* ; Created: v0.0.1 ; Last Modified: v0.0.1 ; Converts a 24bit register value to a boolean value ; In: EAX = 24bit value to convert ; Out: AL = Boolean Value ; Lost Regs: eax ; Cycles: 7/8 ALIGN 16 TypeCast_US24ToBoolean_R: or ah, al ;U 1 Combine the low byte and middle byte shr eax, 8 ;U!1 Shift to access the high byte or ah, al ;U*1 Combine in the high byte %ifdef BOOLEANVALUE_MINUS1 add ah, -1 ;U*1 Add -1. This will set carry if it is non-zero sbb al, al ;U!1 -1 if carry, 0 if no carry %else xor al, al ;U*1 Clear to zero add ah, -1 ;U*1 Add -1. This will set carry if it is non-zero adc al, al ;U!1 1 if carry, 0 if no carry %endif ret ;--2 ;= 7/8 cycles .EndFunc ; TypeCast_US24ToBoolean_R ; ********************************************************************************************************************* ; Created: v0.0.1 ; Last Modified: v0.0.1 ; Converts a 128bit value to a boolean value ; In: EDX -> 128bit value to convert ; Out: AL = Boolean Value ; Lost Regs: eax ; Cycles: 9 ALIGN 16 TypeCast_US128ToBoolean: push ecx ;U 1 Preserve ECX mov eax, DWORD [edx] ; V1 Get the low 32 bits or eax, DWORD [edx + 4] ;U 2 OR in the second 32 bits mov ecx, DWORD [edx + 8] ; V1 Get the third 32 bits or eax, ecx ;U 1 Merge them mov ecx, DWORD [edx + 12] ; V1 Get the last 32 bits or ecx, eax ;U 1 Merge them %ifdef BOOLEANVALUE_MINUS1 add ecx, -1 ;U*1 Add -1. This will set carry if it is non-zero sbb al, al ;U!1 -1 if carry, 0 if no carry %else xor eax, eax ; V1 Clear to zero add ecx, -1 ;U 1 Add -1. This will set carry if it is non-zero adc al, al ;U!1 1 if carry, 0 if no carry %endif pop ecx ; V1 Restore ECX ret ;--2 ;= 9 cycles .EndFunc ; TypeCast_US128ToBoolean ; ********************************************************************************************************************* ; Created: v0.0.1 ; Last Modified: v0.0.1 ; Converts a 256bit value to a boolean value ; In: EDX -> 256bit value to convert ; Out: AL = Boolean Value ; Lost Regs: eax ; Cycles: 13 ALIGN 16 TypeCast_US256ToBoolean: push ecx ;U 1 Preserve ECX mov ecx, DWORD [edx] ; V1 Get the lower 32 bits or ecx, DWORD [edx + 4] ;U 2 OR in the second 32 bits mov eax, DWORD [edx + 8] ; V1 Get the third 32 bits or ecx, eax ;U 1 Merge them mov eax, DWORD [edx + 12] ; V1 Get the fourth 32 bits or ecx, eax ;U 1 Merge them mov eax, DWORD [edx + 12] ; V1 Get the fifth 32 bits or ecx, eax ;U 1 Merge them mov eax, DWORD [edx + 12] ; V1 Get the sixth 32 bits or ecx, eax ;U 1 Merge them mov eax, DWORD [edx + 12] ; V1 Get the seventh 32 bits or ecx, eax ;U 1 Merge them mov eax, DWORD [edx + 12] ; V1 Get the last 32 bits or ecx, eax ;U 1 Merge them %ifdef BOOLEANVALUE_MINUS1 add ecx, -1 ;U*1 Add -1. This will set carry if it is non-zero sbb al, al ;U!1 -1 if carry, 0 if no carry %else xor eax, eax ; V1 Clear to zero add ecx, -1 ;U 1 Add -1. This will set carry if it is non-zero adc al, al ;U!1 1 if carry, 0 if no carry %endif pop ecx ; V1 Restore ECX ret ;--2 ;= 13 cycles .EndFunc ; TypeCast_US256ToBoolean ; @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ ; @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ ; Add Mnemonic Functions ; ********************************************************************************************************************* ; Created: v0.0.1 ; Last Modified: v0.0.1 ; Adds a signed 16bit value to a 24bit value ; In: EDX -> 24bit memory value, AX = 16bit Value ; Out: EAX = 24bit Register Value after Add ; Lost Regs: eax ; Cycles: 13 ALIGN 16 Mnemonic_Add_US24AndS16: push ecx ;U 1 Preserve ECX ; Prepare both values mov ecx, eax ; V1 Set ECX to hold our 16bit value mov ah, [edx + 2] ;U 1 Get the high byte of the 24bit value shl ecx, 16 ;U!1 Move the 16bit value to the top 2 bytes mov al, [edx + 1] ; V1 Get the middle byte shl eax, 16 ;U!1 Shift to the top sar ecx, 16 ;U!1 Sign extend mov al, [edx] ; V1 Get the low byte add eax, ecx ;U 1 Add the values together Macro_WriteUS24 edx ;U*5 Store the result pop ecx ; V1 Restore ECX ret ;--2 ;= 13 cycles .EndFunc ; Mnemonic_Add_US24AndS16 ; ********************************************************************************************************************* ; Created: v0.0.1 ; Last Modified: v0.0.1 ; Adds a U/S24-256 value to a 24bit value ; In: EDX -> 24bit memory value, EAX = Low 32 bits of the U/S24-256 value ; Out: EAX = 24bit value after Add ; Lost Regs: eax ; Cycles: 14 ALIGN 16 Mnemonic_Add_US24AndUS24Plus: push ecx ;U 1 Preserve ECX ; Prepare both values mov ecx, eax ; V1 Set ECX to hold the value to add mov ah, [edx + 2] ;U 1 Get the high byte of the 24bit value mov al, [edx + 1] ;U*1 Get the middle byte shl eax, 8 ;U!1 Shift it up mov al, [edx] ;U*1 Get the low byte add eax, ecx ;U*1 Add the values together Macro_WriteUS24 edx ;U*5 Store the result pop ecx ; V1 Restore ECX ret ;--2 ;= 14 cycles .EndFunc ; Mnemonic_Add_US24AndUS24Plus ; @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ ; @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ ; And Mnemonic Functions ; ********************************************************************************************************************* ; Created: v0.0.1 ; Last Modified: v0.0.1 ; Ands a U/S24-256 value to a 24bit value ; In: EDX -> 24bit memory value, EAX = Low 32 bits of the U/S24-256 value ; Out: EAX = 24bit value after And ; Lost Regs: eax ; Cycles: 14 ALIGN 16 Mnemonic_And_US24AndUS24Plus: push ecx ;U 1 Preserve ECX ; Prepare both values mov ecx, eax ; V1 Set ECX to hold the value to and mov ah, [edx + 2] ;U 1 Get the high byte of the 24bit value mov al, [edx + 1] ;U*1 Get the middle byte shl eax, 8 ;U!1 Shift it up mov al, [edx] ;U*1 Get the low byte and eax, ecx ;U*1 And the values together Macro_WriteUS24 edx ;U*5 Store the result pop ecx ; V1 Restore ECX ret ;--2 ;= 14 cycles .EndFunc ; Mnemonic_And_US24AndUS24Plus ; ********************************************************************************************************************* ; Created: v0.0.1 ; Last Modified: v0.0.1 ; Ands a U/S24-256 memory value to a 24bit register value ; In: EDX -> 24bit memory value, EAX = Low 32 bits of the U/S24-256 value ; Out: EAX = 24bit value after And ; Lost Regs: eax ; Cycles: 11 ALIGN 16 Mnemonic_And_S24AndUS24_R: push ecx ;U 1 Preserve ECX xor ecx, ecx ;U 1 Clear to zero mov ch, [edx + 2] ;U*1 Get the high byte of the 24bit value mov cl, [edx + 1] ;U*1 Get the middle byte shl ecx, 8 ;U!1 Shift it up mov cl, [edx] ;U*1 Get the low byte and eax, ecx ;U*1 And the values together shl eax, 8 ;U!1 Shift it up sar eax, 8 ;U!1 SAR to sign extend pop ecx ; V1 Restore ECX ret ;--2 ;= 11 cycles .EndFunc ; Mnemonic_And_S24AndUS24_R ; @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ ; @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ ; Compare Mnemonic Functions ; ********************************************************************************************************************* ; Created: v0.0.1 ; Last Modified: v0.0.1 ; Compares an unsigned 8bit value to an unsigned 24bit value ; In: EDX -> 24bit memory value, AL = 8bit Value ; Out: Nothing (flags are set) ; Lost Regs: eax ; Cycles: 9 ALIGN 16 Mnemonic_Compare_U24ToU8: push ecx ;U 1 Preserve ECX xor ecx, ecx ; V1 Clear to zero mov cl, al ;U 1 Move our 8bit value into ECX Macro_ReadU24 edx ;U*4 Read the 24bit value into EAX cmp ecx, edx ; V1 Do the compare pop ecx ;U 1 Restore ECX ret ;--2 ;= 9 cycles .EndFunc ; Mnemonic_Compare_U24ToU8 ; ********************************************************************************************************************* ; Created: v0.0.1 ; Last Modified: v0.0.1 ; Compares a signed 8bit value to an unsigned 24bit value ; In: EDX -> 24bit memory value, AL = 8bit Value ; Out: Nothing (flags are set) ; Lost Regs: eax ; Cycles: 10 ALIGN 16 Mnemonic_Compare_U24ToS8: push ecx ;U 1 Preserve ECX mov cl, al ; V1 Move our 8bit value into ECX shl ecx, 24 ;U!1 Shift it to the high byte Macro_ReadU24 edx ;U*4 Read the 24bit value into EAX sar ecx, 24 ;U!1 SAR to sign extend cmp ecx, edx ; V1 Do the compare pop ecx ;U 1 Restore ECX ret ;--2 ;= 10 cycles .EndFunc ; Mnemonic_Compare_U24ToS8 ; ********************************************************************************************************************* ; Created: v0.0.1 ; Last Modified: v0.0.1 ; Compares an unsigned 8bit value to a signed 24bit value ; In: EDX -> 24bit memory value, AL = 8bit Value ; Out: Nothing (flags are set) ; Lost Regs: eax ; Cycles: 9 ALIGN 16 Mnemonic_Compare_S24ToU8: push ecx ;U 1 Preserve ECX xor ecx, ecx ; V1 Clear to zero mov cl, al ;U 1 Move our 8bit value into ECX Macro_ReadS24 edx ;U*4 Read the 24bit value into EAX cmp ecx, edx ; V1 Do the compare pop ecx ;U 1 Restore ECX ret ;--2 ;= 9 cycles .EndFunc ; Mnemonic_Compare_S24ToU8 ; ********************************************************************************************************************* ; Created: v0.0.1 ; Last Modified: v0.0.1 ; Compares a signed 8bit value to a signed 24bit value ; In: EDX -> 24bit memory value, AL = 8bit Value ; Out: Nothing (flags are set) ; Lost Regs: eax ; Cycles: 10 ALIGN 16 Mnemonic_Compare_S24ToS8: push ecx ;U 1 Preserve ECX mov cl, al ; V1 Move our 8bit value into ECX shl ecx, 24 ;U!1 Shift it to the high byte Macro_ReadS24 edx ;U*4 Read the 24bit value into EAX sar ecx, 24 ;U!1 SAR to sign extend cmp ecx, edx ; V1 Do the compare pop ecx ;U 1 Restore ECX ret ;--2 ;= 10 cycles .EndFunc ; Mnemonic_Compare_S24ToS8 ; ********************************************************************************************************************* ; Created: v0.0.1 ; Last Modified: v0.0.1 ; Compares an unsigned 16bit value to an unsigned 24bit value ; In: EDX -> 24bit memory value, AX = 16bit Value ; Out: Nothing (flags are set) ; Lost Regs: eax ; Cycles: 10 ALIGN 16 Mnemonic_Compare_U24ToU16: push ecx ;U 1 Preserve ECX xor ecx, ecx ; V1 Clear to zero mov cx, ax ;U 1+1 Move our 16bit value into ECX Macro_ReadU24 edx ;U*4 Read the 24bit value into EAX cmp ecx, edx ; V1 Do the compare pop ecx ;U 1 Restore ECX ret ;--2 ;= 10 cycles .EndFunc ; Mnemonic_Compare_U24ToU16 ; ********************************************************************************************************************* ; Created: v0.0.1 ; Last Modified: v0.0.1 ; Compares a signed 16bit value to an unsigned 24bit value ; In: EDX -> 24bit memory value, AX = 16bit Value ; Out: Nothing (flags are set) ; Lost Regs: eax ; Cycles: 11 ALIGN 16 Mnemonic_Compare_U24ToS16: push ecx ;U 1 Preserve ECX mov cx, ax ; V1+1 Move our 16bit value into ECX shl ecx, 16 ;U!1 Shift it to the high byte Macro_ReadU24 edx ;U*4 Read the 24bit value into EAX sar ecx, 16 ;U!1 SAR to sign extend cmp ecx, edx ; V1 Do the compare pop ecx ;U 1 Restore ECX ret ;--2 ;= 11 cycles .EndFunc ; Mnemonic_Compare_U24ToS16 ; ********************************************************************************************************************* ; Created: v0.0.1 ; Last Modified: v0.0.1 ; Compares an unsigned 16bit value to a signed 24bit value ; In: EDX -> 24bit memory value, AX = 16bit Value ; Out: Nothing (flags are set) ; Lost Regs: eax ; Cycles: 10 ALIGN 16 Mnemonic_Compare_S24ToU16: push ecx ;U 1 Preserve ECX xor ecx, ecx ; V1 Clear to zero mov cx, ax ;U 1+1 Move our 16bit value into ECX Macro_ReadS24 edx ;U*4 Read the 24bit value into EAX cmp ecx, edx ; V1 Do the compare pop ecx ;U 1 Restore ECX ret ;--2 ;= 10 cycles .EndFunc ; Mnemonic_Compare_S24ToU16 ; ********************************************************************************************************************* ; Created: v0.0.1 ; Last Modified: v0.0.1 ; Compares a signed 16bit value to a signed 24bit value ; In: EDX -> 24bit memory value, AL = 16bit Value ; Out: Nothing (flags are set) ; Lost Regs: eax ; Cycles: 11 ALIGN 16 Mnemonic_Compare_S24ToS16: push ecx ;U 1 Preserve ECX mov cx, ax ; V1+1 Move our 16bit value into ECX shl ecx, 16 ;U!1 Shift it to the high byte Macro_ReadS24 edx ;U*4 Read the 24bit value into EAX sar ecx, 16 ;U!1 SAR to sign extend cmp ecx, edx ; V1 Do the compare pop ecx ;U 1 Restore ECX ret ;--2 ;= 11 cycles .EndFunc ; Mnemonic_Compare_S24ToS16 ; ********************************************************************************************************************* ; Created: v0.0.1 ; Last Modified: v0.0.1 ; Compares an unsigned 24bit value to an unsigned 8bit value ; In: EDX -> 24bit memory value, AL = 8bit Value ; Out: Nothing (flags are set) ; Lost Regs: eax ; Cycles: 9 ALIGN 16 Mnemonic_Compare_U8ToU24: push ecx ;U 1 Preserve ECX xor ecx, ecx ; V1 Clear to zero mov cl, al ;U 1 Move our 8bit value into ECX Macro_ReadU24 edx ;U*4 Read the 24bit value into EAX cmp edx, ecx ; V1 Do the compare pop ecx ;U 1 Restore ECX ret ;--2 ;= 9 cycles .EndFunc ; Mnemonic_Compare_U8ToU24 ; ********************************************************************************************************************* ; Created: v0.0.1 ; Last Modified: v0.0.1 ; Compares an unsigned 24bit value to a signed 8bit value ; In: EDX -> 24bit memory value, AL = 8bit Value ; Out: Nothing (flags are set) ; Lost Regs: eax ; Cycles: 10 ALIGN 16 Mnemonic_Compare_S8ToU24: push ecx ;U 1 Preserve ECX mov cl, al ; V1 Move our 8bit value into ECX shl ecx, 24 ;U!1 Shift it to the high byte Macro_ReadU24 edx ;U*4 Read the 24bit value into EAX sar ecx, 24 ;U!1 SAR to sign extend cmp edx, ecx ; V1 Do the compare pop ecx ;U 1 Restore ECX ret ;--2 ;= 10 cycles .EndFunc ; Mnemonic_Compare_S8ToU24 ; ********************************************************************************************************************* ; Created: v0.0.1 ; Last Modified: v0.0.1 ; Compares a signed 24bit value to an unsigned 8bit value ; In: EDX -> 24bit memory value, AL = 8bit Value ; Out: Nothing (flags are set) ; Lost Regs: eax ; Cycles: 9 ALIGN 16 Mnemonic_Compare_U8ToS24: push ecx ;U 1 Preserve ECX xor ecx, ecx ; V1 Clear to zero mov cl, al ;U 1 Move our 8bit value into ECX Macro_ReadS24 edx ;U*4 Read the 24bit value into EAX cmp edx, ecx ; V1 Do the compare pop ecx ;U 1 Restore ECX ret ;--2 ;= 9 cycles .EndFunc ; Mnemonic_Compare_U8ToS24 ; ********************************************************************************************************************* ; Created: v0.0.1 ; Last Modified: v0.0.1 ; Compares a signed 24bit value to a signed 8bit value ; In: EDX -> 24bit memory value, AL = 8bit Value ; Out: Nothing (flags are set) ; Lost Regs: eax ; Cycles: 10 ALIGN 16 Mnemonic_Compare_S8ToS24: push ecx ;U 1 Preserve ECX mov cl, al ; V1 Move our 8bit value into ECX shl ecx, 24 ;U!1 Shift it to the high byte Macro_ReadS24 edx ;U*4 Read the 24bit value into EAX sar ecx, 24 ;U!1 SAR to sign extend cmp edx, ecx ; V1 Do the compare pop ecx ;U 1 Restore ECX ret ;--2 ;= 10 cycles .EndFunc ; Mnemonic_Compare_S8ToS24 ; ********************************************************************************************************************* ; Created: v0.0.1 ; Last Modified: v0.0.1 ; Compares an unsigned 24bit value to an unsigned 16bit value ; In: EDX -> 24bit memory value, AX = 16bit Value ; Out: Nothing (flags are set) ; Lost Regs: eax ; Cycles: 10 ALIGN 16 Mnemonic_Compare_U16ToU24: push ecx ;U 1 Preserve ECX xor ecx, ecx ; V1 Clear to zero mov cx, ax ;U 1+1 Move our 16bit value into ECX Macro_ReadU24 edx ;U*4 Read the 24bit value into EAX cmp edx, ecx ; V1 Do the compare pop ecx ;U 1 Restore ECX ret ;--2 ;= 10 cycles .EndFunc ; Mnemonic_Compare_U16ToU24 ; ********************************************************************************************************************* ; Created: v0.0.1 ; Last Modified: v0.0.1 ; Compares an unsigned 24bit value to a signed 16bit value ; In: EDX -> 24bit memory value, AX = 16bit Value ; Out: Nothing (flags are set) ; Lost Regs: eax ; Cycles: 11 ALIGN 16 Mnemonic_Compare_S16ToU24: push ecx ;U 1 Preserve ECX mov cx, ax ; V1+1 Move our 16bit value into ECX shl ecx, 16 ;U!1 Shift it to the high byte Macro_ReadU24 edx ;U*4 Read the 24bit value into EAX sar ecx, 16 ;U!1 SAR to sign extend cmp edx, ecx ; V1 Do the compare pop ecx ;U 1 Restore ECX ret ;--2 ;= 11 cycles .EndFunc ; Mnemonic_Compare_S16ToU24 ; ********************************************************************************************************************* ; Created: v0.0.1 ; Last Modified: v0.0.1 ; Compares a signed 16bit value to an unsigned 24bit value ; In: EDX -> 24bit memory value, AX = 16bit Value ; Out: Nothing (flags are set) ; Lost Regs: eax ; Cycles: 10 ALIGN 16 Mnemonic_Compare_U16ToS24: push ecx ;U 1 Preserve ECX xor ecx, ecx ; V1 Clear to zero mov cx, ax ;U 1+1 Move our 16bit value into ECX Macro_ReadS24 edx ;U*4 Read the 24bit value into EAX cmp edx, ecx ; V1 Do the compare pop ecx ;U 1 Restore ECX ret ;--2 ;= 10 cycles .EndFunc ; Mnemonic_Compare_U16ToS24 ; ********************************************************************************************************************* ; Created: v0.0.1 ; Last Modified: v0.0.1 ; Compares a signed 24bit value to a signed 16bit value ; In: EDX -> 24bit memory value, AL = 16bit Value ; Out: Nothing (flags are set) ; Lost Regs: eax ; Cycles: 11 ALIGN 16 Mnemonic_Compare_S16ToS24: push ecx ;U 1 Preserve ECX mov cx, ax ; V1+1 Move our 16bit value into ECX shl ecx, 16 ;U!1 Shift it to the high byte Macro_ReadS24 edx ;U*4 Read the 24bit value into EAX sar ecx, 16 ;U!1 SAR to sign extend cmp edx, ecx ; V1 Do the compare pop ecx ;U 1 Restore ECX ret ;--2 ;= 11 cycles .EndFunc ; Mnemonic_Compare_S16ToS24 ; ********************************************************************************************************************* ; Created: v0.0.1 ; Last Modified: v0.0.1 ; Compares an unsigned 24bit value to an unsigned 24bit value ; In: EDX -> 24bit memory to compare to, EAX -> 24bit value to compare from (cmp [edx], [eax]) ; Out: Nothing (flags are set) ; Lost Regs: eax ; Cycles: 14 ALIGN 16 Mnemonic_Compare_U24ToU24: push ecx ;U 1 Preserve ECX mov ecx, eax ; V1 Move the pointer the value to compare from Macro_ReadU24 ecx ;U 5 Read in the value mov ecx, eax ;U*1 Move the 24bit value into ECX Macro_ReadU24 edx ;U*4 Read cmp eax, ecx ;U*1 Do the compare pop ecx ; V1 Restore ECX ret ;--2 ;= 14 cycles .EndFunc ; Mnemonic_Compare_U24ToU24 ; ********************************************************************************************************************* ; Created: v0.0.1 ; Last Modified: v0.0.1 ; Compares a signed 24bit value to an unsigned 24bit value ; In: EDX -> 24bit memory to compare to, EAX -> 24bit value to compare from (cmp [edx], [eax]) ; Out: Nothing (flags are set) ; Lost Regs: eax ; Cycles: 14 ALIGN 16 Mnemonic_Compare_S24ToU24: push ecx ;U 1 Preserve ECX mov ecx, eax ; V1 Move the pointer the value to compare from Macro_ReadS24 ecx ;U 5 Read in the value mov ecx, eax ;U*1 Move the 24bit value into ECX Macro_ReadU24 edx ;U*4 Read cmp eax, ecx ;U*1 Do the compare pop ecx ; V1 Restore ECX ret ;--2 ;= 14 cycles .EndFunc ; Mnemonic_Compare_S24ToU24 ; ********************************************************************************************************************* ; Created: v0.0.1 ; Last Modified: v0.0.1 ; Compares an unsigned 24bit value to a signed 24bit value ; In: EDX -> 24bit memory to compare to, EAX -> 24bit value to compare from (cmp [edx], [eax]) ; Out: Nothing (flags are set) ; Lost Regs: eax ; Cycles: 14 ALIGN 16 Mnemonic_Compare_U24ToS24: push ecx ;U 1 Preserve ECX mov ecx, eax ; V1 Move the pointer the value to compare from Macro_ReadU24 ecx ;U 5 Read in the value mov ecx, eax ;U*1 Move the 24bit value into ECX Macro_ReadS24 edx ;U*4 Read cmp eax, ecx ;U*1 Do the compare pop ecx ; V1 Restore ECX ret ;--2 ;= 14 cycles .EndFunc ; Mnemonic_Compare_U24ToS24 ; ********************************************************************************************************************* ; Created: v0.0.1 ; Last Modified: v0.0.1 ; Compares a signed 24bit value to a signed 24bit value ; In: EDX -> 24bit memory to compare to, EAX -> 24bit value to compare from (cmp [edx], [eax]) ; Out: Nothing (flags are set) ; Lost Regs: eax ; Cycles: 14 ALIGN 16 Mnemonic_Compare_S24ToS24: push ecx ;U 1 Preserve ECX mov ecx, eax ; V1 Move the pointer the value to compare from Macro_ReadS24 ecx ;U 5 Read in the value mov ecx, eax ;U*1 Move the 24bit value into ECX Macro_ReadS24 edx ;U*4 Read cmp eax, ecx ;U*1 Do the compare pop ecx ; V1 Restore ECX ret ;--2 ;= 14 cycles .EndFunc ; Mnemonic_Compare_S24ToS24 ; ********************************************************************************************************************* ; Created: v0.0.1 ; Last Modified: v0.0.1 ; Compares an unsigned 24bit value to a 24bit register value ; In: EDX -> 24bit memory to compare from, EAX = 24bit value to compare to (cmp eax, [edx]) ; Out: Nothing (flags are set) ; Lost Regs: eax ; Cycles: 9 ALIGN 16 Mnemonic_Compare_U24ToUS24_R: push ecx ;U 1 Preserve ECX mov ecx, eax ; V1 Move the register value into ECX Macro_ReadU24 edx ;U 5 Read in the memory value cmp ecx, eax ;U*1 Do the compare pop ecx ; V1 Restore ECX ret ;--2 ;= 9 cycles .EndFunc ; Mnemonic_Compare_U24ToUS24_R ; ********************************************************************************************************************* ; Created: v0.0.1 ; Last Modified: v0.0.1 ; Compares a signed 24bit value to a 24bit register value ; In: EDX -> 24bit memory to compare from, EAX = 24bit value to compare to (cmp eax, [edx]) ; Out: Nothing (flags are set) ; Lost Regs: eax ; Cycles: 9 ALIGN 16 Mnemonic_Compare_S24ToUS24_R: push ecx ;U 1 Preserve ECX mov ecx, eax ; V1 Move the register value into ECX Macro_ReadS24 edx ;U 5 Read in the memory value cmp ecx, eax ;U*1 Do the compare pop ecx ; V1 Restore ECX ret ;--2 ;= 9 cycles .EndFunc ; Mnemonic_Compare_S24ToUS24_R ; ********************************************************************************************************************* ; Created: v0.0.1 ; Last Modified: v0.0.1 ; Compares a 24bit register value to an unsigned 24bit value ; In: EDX -> 24bit memory to compare to, EAX = 24bit value to compare from (cmp [edx], eax) ; Out: Nothing (flags are set) ; Lost Regs: eax ; Cycles: 9 ALIGN 16 Mnemonic_Compare_US24RegToU24: push ecx ;U 1 Preserve ECX mov ecx, eax ; V1 Move the register value into ECX Macro_ReadU24 edx ;U 5 Read in the memory value cmp eax, ecx ;U*1 Do the compare pop ecx ; V1 Restore ECX ret ;--2 ;= 9 cycles .EndFunc ; Mnemonic_Compare_US24RegToU24 ; ********************************************************************************************************************* ; Created: v0.0.1 ; Last Modified: v0.0.1 ; Compares a 24bit register value to a signed 24bit value ; In: EDX -> 24bit memory to compare to, EAX = 24bit value to compare from (cmp [edx], eax) ; Out: Nothing (flags are set) ; Lost Regs: eax ; Cycles: 9 ALIGN 16 Mnemonic_Compare_US24RegToS24: push ecx ;U 1 Preserve ECX mov ecx, eax ; V1 Move the register value into ECX Macro_ReadS24 edx ;U 5 Read in the memory value cmp eax, ecx ;U*1 Do the compare pop ecx ; V1 Restore ECX ret ;--2 ;= 9 cycles .EndFunc ; Mnemonic_Compare_US24RegToS24 ; ********************************************************************************************************************* ; Created: v0.0.1 ; Last Modified: v0.0.1 ; Compares a 32bit value to an unsigned 24bit value ; In: EDX -> 24bit memory to compare to, EAX = 32bit value to compare from (cmp [edx], eax) ; Out: Nothing (flags are set) ; Lost Regs: eax ; Cycles: 9 ALIGN 16 Mnemonic_Compare_US32ToU24: push ecx ;U 1 Preserve ECX mov ecx, eax ; V1 Move the 32bit value into ECX Macro_ReadU24 edx ;U 5 Read in the memory value cmp eax, ecx ;U*1 Do the compare pop ecx ; V1 Restore ECX ret ;--2 ;= 9 cycles .EndFunc ; Mnemonic_Compare_US32ToU24 ; ********************************************************************************************************************* ; Created: v0.0.1 ; Last Modified: v0.0.1 ; Compares a 32bit value to a signed 24bit value ; In: EDX -> 24bit memory to compare to, EAX = 32bit value to compare from (cmp [edx], eax) ; Out: Nothing (flags are set) ; Lost Regs: eax ; Cycles: 9 ALIGN 16 Mnemonic_Compare_US32ToS24: push ecx ;U 1 Preserve ECX mov ecx, eax ; V1 Move the 32bit value into ECX Macro_ReadS24 edx ;U 5 Read in the memory value cmp eax, ecx ;U*1 Do the compare pop ecx ; V1 Restore ECX ret ;--2 ;= 9 cycles .EndFunc ; Mnemonic_Compare_US32ToS24 ; ********************************************************************************************************************* ; Created: v0.0.1 ; Last Modified: v0.0.1 ; Compares an unsigned 24bit value to a 32bit value ; In: EDX -> 24bit memory to compare from, EAX = 32bit value to compare to (cmp eax, [edx]) ; Out: Nothing (flags are set) ; Lost Regs: eax ; Cycles: 9 ALIGN 16 Mnemonic_Compare_U24ToUS32: push ecx ;U 1 Preserve ECX mov ecx, eax ; V1 Move the 32bit value into ECX Macro_ReadU24 edx ;U 5 Read in the memory value cmp ecx, eax ;U*1 Do the compare pop ecx ; V1 Restore ECX ret ;--2 ;= 9 cycles .EndFunc ; Mnemonic_Compare_U24ToUS32 ; ********************************************************************************************************************* ; Created: v0.0.1 ; Last Modified: v0.0.1 ; Compares a signed 24bit value to a 32bit value ; In: EDX -> 24bit memory to compare from, EAX = 32bit value to compare to (cmp eax, [edx]) ; Out: Nothing (flags are set) ; Lost Regs: eax ; Cycles: 9 ALIGN 16 Mnemonic_Compare_S24ToUS32: push ecx ;U 1 Preserve ECX mov ecx, eax ; V1 Move the 32bit value into ECX Macro_ReadS24 edx ;U 5 Read in the memory value cmp ecx, eax ;U*1 Do the compare pop ecx ; V1 Restore ECX ret ;--2 ;= 9 cycles .EndFunc ; Mnemonic_Compare_S24ToUS32 ; @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ ; @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ ; Complement Mnemonic Functions ; ********************************************************************************************************************* ; Created: v0.0.1 ; Last Modified: v0.0.1 ; NOTs a 128bit value in memory ; In: EDX -> 128bit value to convert ; Out: Nothing ; Lost Regs: eax ; Cycles: 9 ALIGN 16 Mnemonic_Complement_US128: push ecx ;U 1 Preserve ECX mov eax, [edx + 8] ; V1 Get the third dword mov ecx, [edx + 12] ;U 1 Get the high dword xor eax, -1 ; V1 Swap the third dword's bits xor ecx, -1 ;U 1 Swap the high dword's bits mov [edx + 8], eax ; V1 Store the third dword mov [edx + 12], ecx ;U 1 Store the high dword mov eax, [edx] ; V1 Get the low dword mov ecx, [edx + 4] ;U 1 Get the second dword xor eax, -1 ; V1 Swap the low dword's bits xor ecx, -1 ;U 1 Swap the second dword's bits mov [edx], eax ; V1 Store the low dword mov [edx + 4], ecx ;U 1 Store the second dword pop ecx ; V1 Restore ECX ret ;--2 ;= 9 cycles .EndFunc ; Mnemonic_Complement_US128 ; ********************************************************************************************************************* ; Created: v0.0.1 ; Last Modified: v0.0.1 ; NOTs a 256bit value in memory ; In: EDX -> 256bit value to convert ; Out: Nothing ; Lost Regs: eax, edx ; Cycles: 15 ALIGN 16 Mnemonic_Complement_US256: push ecx ;U 1 Preserve ECX mov eax, [edx + 24] ; V1 Get the seventh dword mov ecx, [edx + 28] ;U 1 Get the high dword xor eax, -1 ; V1 Swap the seventh dword's bits xor ecx, -1 ;U 1 Swap the high dword's bits mov [edx + 24], eax ; V1 Store the seventh dword mov [edx + 28], ecx ;U 1 Store the high dword mov eax, [edx + 16] ; V1 Get the fifth dword mov ecx, [edx + 20] ;U 1 Get the sixth dword xor eax, -1 ; V1 Swap the fifth dword's bits xor ecx, -1 ;U 1 Swap the sixth dword's bits mov [edx + 16], eax ; V1 Store the fifth dword mov [edx + 20], ecx ;U 1 Store the sixth dword mov eax, [edx + 8] ; V1 Get the third dword mov ecx, [edx + 12] ;U 1 Get the fourth dword xor eax, -1 ; V1 Swap the third dword's bits xor ecx, -1 ;U 1 Swap the fourth dword's bits mov [edx + 8], eax ; V1 Store the third dword mov [edx + 12], ecx ;U 1 Store the fourth dword mov eax, [edx] ; V1 Get the low dword mov ecx, [edx + 4] ;U 1 Get the second dword xor eax, -1 ; V1 Swap the low dword's bits xor ecx, -1 ;U 1 Swap the second dword's bits mov [edx], eax ; V1 Store the low dword mov [edx + 4], ecx ;U 1 Store the second dword pop ecx ; V1 Restore ECX ret ;--2 ;= 15 cycles .EndFunc ; Mnemonic_Complement_US256 ; @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ ; @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ ; Decrement Mnemonic Functions ; ********************************************************************************************************************* ; Created: v0.0.1 ; Last Modified: v0.0.1 ; Decrements a 128bit memory value ; In: EDX -> 128bit value to decrement ; Out: Nothing ; Lost Regs: eax ; Cycles: 4-14 ALIGN 16 Mnemonic_Dec_US128: mov eax, DWORD [edx] ;U 1 Get the low 32 bits sub eax, 1 ; V1 Decrement mov DWORD [edx], eax ;U 1 Store the low 32 bits jnc > .l1 ;!V1 Exit if carry is not set push ecx ;U 1 Preserve ECX mov ecx, DWORD [edx + 4] ; V1 Get the second 32 bits sbb ecx, 0 ;U!1 Subtract with borrow mov eax, DWORD [edx + 8] ; V1 Get the third 32 bits mov DWORD [edx + 4], ecx ;U 1 Store the second 32 bits mov ecx, DWORD [edx + 12] ; V1 Get the high 32 bits sbb eax, 0 ;U!1 Subtract with borrow sbb ecx, 0 ;U!1 Subtract with borrow mov DWORD [edx + 8], eax ; V1 Store the third 32 bits mov DWORD [edx + 12], ecx ;U 1 Store the last 32 bits pop ecx ; V1 Restore ECX .l1: ret ;--2 ;= 4-10(14) cycles .EndFunc ; Mnemonic_Dec_US128 ; ********************************************************************************************************************* ; Created: v0.0.1 ; Last Modified: v0.0.1 ; Decrements a 256bit memory value ; In: EDX -> 256bit value to decrement ; Out: Nothing ; Lost Regs: eax ; Cycles: 4-20 ALIGN 16 Mnemonic_Dec_US256: mov eax, DWORD [edx] ;U 1 Get the low 32 bits sub eax, 1 ; V1 Decrement mov DWORD [edx], eax ;U 1 Store the low 32 bits jnc > .l1 ;!V1 If carry is not set, then exit push ecx ;U 1 Preserve ECX mov ecx, DWORD [edx + 4] ; V1 Get the second 32 bits sbb ecx, 0 ;U!1 Subtract with borrow mov eax, DWORD [edx + 8] ; V1 Get the third 32 bits mov DWORD [edx + 4], ecx ;U 1 Store the second 32 bits mov ecx, DWORD [edx + 12] ; V1 Get the fourth 32 bits sbb eax, 0 ;U!1 Subtract with borrow sbb ecx, 0 ;U!1 Subtract with borrow mov DWORD [edx + 8], eax ; V1 Store the third 32 bits mov DWORD [edx + 12], ecx ;U 1 Store the fourth 32 bits mov eax, DWORD [edx + 16] ; V1 Get the fifth 32 bits sbb eax, 0 ;U!1 Subtract with borrow mov ecx, DWORD [edx + 20] ; V1 Get the sixth 32 bits sbb ecx, 0 ;U!1 Subtract with borrow mov DWORD [edx + 16], eax ; V1 Store the fifth 32 bits mov DWORD [edx + 20], ecx ;U 1 Store the sixth 32 bits mov eax, DWORD [edx + 24] ; V1 Get the seventh 32 bits sbb eax, 0 ;U!1 Subtract with borrow mov ecx, DWORD [edx + 28] ; V1 Get the last 32 bits sbb ecx, 0 ;U!1 Subtract with borrow mov DWORD [edx + 24], eax ; V1 Store the seventh 32 bits mov DWORD [edx + 28], ecx ;U 1 Store the last 32 bits pop ecx ; V1 Restore ECX .l1: ret ;--2 ;= 4-16(20) cycles .EndFunc ; Mnemonic_Dec_US256 ; @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ ; @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ ; Increment Mnemonic Functions ; ********************************************************************************************************************* ; Created: v0.0.1 ; Last Modified: v0.0.1 ; Increments a 128bit memory value ; In: EDX -> 128bit value to increment ; Out: Nothing ; Lost Regs: eax ; Cycles: 4-14 ALIGN 16 Mnemonic_Inc_US128: mov eax, DWORD [edx] ;U 1 Get the low 32 bits add eax, 1 ; V1 Increment mov DWORD [edx], eax ;U 1 Store the low 32 bits jnc > .l1 ;!V1 Exit if carry is not set push ecx ;U 1 Preserve ECX mov ecx, DWORD [edx + 4] ; V1 Get the second 32 bits adc ecx, 0 ;U!1 Add with carry mov eax, DWORD [edx + 8] ; V1 Get the third 32 bits mov DWORD [edx + 4], ecx ;U 1 Store the second 32 bits mov ecx, DWORD [edx + 12] ; V1 Get the high 32 bits adc eax, 0 ;U!1 Add with carry adc ecx, 0 ;U!1 Add with carry mov DWORD [edx + 8], eax ; V1 Store the third 32 bits mov DWORD [edx + 12], ecx ;U 1 Store the last 32 bits pop ecx ; V1 Restore ECX .l1: ret ;--2 ;= 4-10(14) cycles .EndFunc ; Mnemonic_Inc_US128 ; ********************************************************************************************************************* ; Created: v0.0.1 ; Last Modified: v0.0.1 ; Increments a 256bit memory value ; In: EDX -> 256bit value to increment ; Out: Nothing ; Lost Regs: eax ; Cycles: 4-20 ALIGN 16 Mnemonic_Inc_US256: mov eax, DWORD [edx] ;U 1 Get the low 32 bits add eax, 1 ; V1 Increment mov DWORD [edx], eax ;U 1 Store the low 32 bits jnc > .l1 ;!V1 If carry is not set, then exit push ecx ;U 1 Preserve ECX mov ecx, DWORD [edx + 4] ; V1 Get the second 32 bits adc ecx, 0 ;U!1 Add with carry mov eax, DWORD [edx + 8] ; V1 Get the third 32 bits mov DWORD [edx + 4], ecx ;U 1 Store the second 32 bits mov ecx, DWORD [edx + 12] ; V1 Get the fourth 32 bits adc eax, 0 ;U!1 Add with carry adc ecx, 0 ;U!1 Add with carry mov DWORD [edx + 8], eax ; V1 Store the third 32 bits mov DWORD [edx + 12], ecx ;U 1 Store the fourth 32 bits mov eax, DWORD [edx + 16] ; V1 Get the fifth 32 bits adc eax, 0 ;U!1 Add with carry mov ecx, DWORD [edx + 20] ; V1 Get the sixth 32 bits adc ecx, 0 ;U!1 Add with carry mov DWORD [edx + 16], eax ; V1 Store the fifth 32 bits mov DWORD [edx + 20], ecx ;U 1 Store the sixth 32 bits mov eax, DWORD [edx + 24] ; V1 Get the seventh 32 bits adc eax, 0 ;U!1 Add with carry mov ecx, DWORD [edx + 28] ; V1 Get the last 32 bits adc ecx, 0 ;U!1 Add with carry mov DWORD [edx + 24], eax ; V1 Store the seventh 32 bits mov DWORD [edx + 28], ecx ;U 1 Store the last 32 bits pop ecx ; V1 Restore ECX .l1: ret ;--2 ;= 4-16(20) cycles .EndFunc ; Mnemonic_Inc_US256 ; @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ ; @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ ; RotateLeft Mnemonic Functions ; ********************************************************************************************************************* ; Created: v0.0.1 ; Last Modified: v0.0.1 ; Rotates a 24bit value in memory right by the amount specified ; In: EDX -> 24bit memory value, AL = amount to rotate ; Out: Nothing ; Lost Regs: EAX = 24bit Register Value after Rotate ; Cycles: 34-65 ALIGN 16 Mnemonic_ROL_US24: push ecx ;U 1 Preserve ECX push ebx ; V1 Preserve EBX Macro_DivideImmediate8 24 ;--18 AL = AL % 24 mov cl, al ;U 1 Get the amount to shift Macro_ReadU24 edx ;U*4 Read in the 24bit value (sign is ignored) ; While (CL >= 8) { .l1: cmp cl, 8 ; 1 jb > .l2 ;!V1(+4?) ; value <<= 8; shl eax, 8 ;U!1 ; value = (value | (value >> 24)) & 0xFFFFFF; ; CL -= 8; mov ebx, eax ;U*1 and eax, 0FFFFFFh ; V1 shr ebx, 24 ;U!1 sub cl, 8 ; V1 or eax, ebx ;U 1 ; } jmp < .l1 ;!V1 .l2: ;= 5-10 cycles per loop, 1-5 for last loop (when exiting) ; If (CL) { test cl, cl ;U 1 jz > .l3 ; V1 ; value <<= CL; shl eax, cl ;--4 ; value |= value >> 24; // We don't need to keep the high byte clear here mov ebx, eax ;U*1 shr ebx, 24 ;U!1 or eax, ebx ;U*1 ; } .l3: Macro_WriteUS24 edx ;U*5 Store the 24bit value pop ebx ; V1 Restore EBX pop ecx ;U 1 Restore ECX ret ;--2 ;= 34-65 cycles .EndFunc ; Mnemonic_ROL_US24 ; ********************************************************************************************************************* ; Created: v0.0.1 ; Last Modified: v0.0.1 ; Rotates an unsigned 24bit value right by the amount specified ; In: EDX = 24bit value to rotate, AL = amount to rotate ; Out: EAX = 24bit Register Value after Rotate ; Lost Regs: None ; Cycles: 23-56 ALIGN 16 Mnemonic_ROL_U24_R: push ecx ;U 1 Preserve ECX push ebx ; V1 Preserve EBX Macro_DivideImmediate8 24 ;--18 AL = AL % 24 mov cl, al ;U 1 Get the amount to shift mov eax, edx ; V1 Put our value in EAX ; While (CL >= 8) { .l1: cmp cl, 8 ;U 1 jb > .l2 ;!V1(+4?) ; value <<= 8; shl eax, 8 ;U!1 ; value = (value | (value >> 24)) & 0xFFFFFF; ; CL -= 8; mov ebx, eax ;U*1 and eax, 0FFFFFFh ; V1 shr ebx, 24 ;U!1 sub cl, 8 ; V1 or eax, ebx ;U 1 ; } jmp < .l1 ;!V1 .l2: ;= 5-10 cycles per loop, 1-5 for last loop (when exiting) ; If (CL) { test cl, cl ;U 1 jz > .l3 ; V1 ; value <<= CL; shl eax, cl ;--4 ; value |= value >> 24; // We don't need to keep the high byte clear here mov ebx, eax ;U*1 shr ebx, 24 ;U!1 or eax, ebx ;U*1 ; } .l3: pop ebx ;U 1 Restore EBX pop ecx ; V1 Restore ECX ret ;--2 ;= 23-56 cycles .EndFunc ; Mnemonic_ROL_U24_R ; ********************************************************************************************************************* ; Created: v0.0.1 ; Last Modified: v0.0.1 ; Rotates a signed 24bit value right by the amount specified ; In: EDX = 24bit value to rotate, AL = amount to rotate ; Out: EAX = 24bit Register Value after Rotate ; Lost Regs: None ; Cycles: 24-57 ALIGN 16 Mnemonic_ROL_S24_R: push ecx ;U 1 Preserve ECX push ebx ; V1 Preserve EBX Macro_DivideImmediate8 24 ;--18 AL = AL % 24 mov cl, al ;U 1 Get the amount to shift mov eax, edx ; V1 Put our value in EAX ; While (CL >= 8) { .l1: cmp cl, 8 ;U 1 jb > .l2 ;!V1(+4?) ; value <<= 8; shl eax, 8 ;U!1 ; value = (value | (value >> 24)) & 0xFFFFFF; ; CL -= 8; mov ebx, eax ;U*1 and eax, 0FFFFFFh ; V1 shr ebx, 24 ;U!1 sub cl, 8 ; V1 or eax, ebx ;U 1 ; } jmp < .l1 ;!V1 .l2: ;= 5-10 cycles per loop, 1-5 for last loop (when exiting) ; If (CL) { test cl, cl ;U 1 jz > .l3 ; V1 ; value <<= CL; shl eax, cl ;--4 ; value |= value >> 24; // We don't need to keep the high byte clear here mov ebx, eax ;U*1 shr ebx, 24 ;U!1 or eax, ebx ;U*1 ; } .l3: shl eax, 8 ;U!1 Shift to the high byte pop ebx ; V1 Restore EBX sar eax, 8 ;U!1 SAR to sign extend pop ecx ; V1 Restore ECX ret ;--2 ;= 24-57 cycles .EndFunc ; Mnemonic_ROL_S24_R ; @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ ; @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ ; RotateRight Mnemonic Functions ; ********************************************************************************************************************* ; Created: v0.0.1 ; Last Modified: v0.0.1 ; Rotates a 24bit value in memory right by the amount specified ; In: EDX -> 24bit memory value, AL = amount to rotate ; Out: Nothing ; Lost Regs: EAX = 24bit Register Value after Rotate ; Cycles: 34-68 ALIGN 16 Mnemonic_ROR_US24: push ecx ;U 1 Preserve ECX push ebx ; V1 Preserve EBX Macro_DivideImmediate8 24 ;--18 AL = AL % 24 mov cl, al ;U 1 Get the amount to shift Macro_ReadU24 edx ;U*4 Read in the 24bit value (sign is ignored) ; While (CL >= 8) { .l1: cmp cl, 8 ; 1 jb > .l2 ;!V1(+4?) ; value >>>= 8; ror eax, 8 ;U!1 ; value = (value & 0xFFFFFF) | ((value >> 8) & 0xFF0000); ; CL -= 8; mov ebx, eax ;U*1 and eax, 0FFFFFFh ; V1 shr ebx, 8 ;U!1 sub cl, 8 ; V1 and ebx, 0FF0000h ;U 1 or eax, ebx ;U*1 ; } jmp < .l1 ;!V1 .l2: ;= 6-11 cycles per loop, 1-5 for last loop (when exiting) ; If (CL) { test cl, cl ;U 1 jz > .l3 ; V1 ; value >>>= CL; ror eax, cl ;--4 ; value |= (value >> 8) & 0xFF0000; // We don't need to clear the high byte here mov ebx, eax ;U*1 shr ebx, 8 ;U!1 and ebx, 0FF0000h ;U*1 or eax, ebx ;U*1 ; } .l3: Macro_WriteUS24 edx ;U*5 Store the 24bit value pop ebx ; V1 Restore EBX pop ecx ;U 1 Restore ECX ret ;--2 ;= 34-68 cycles .EndFunc ; Mnemonic_ROR_US24 ; ********************************************************************************************************************* ; Created: v0.0.1 ; Last Modified: v0.0.1 ; Rotates an unsigned 24bit value right by the amount specified ; In: EDX = 24bit value to rotate, AL = amount to rotate ; Out: EAX = 24bit Register Value after Rotate ; Lost Regs: None ; Cycles: 24-60 ALIGN 16 Mnemonic_ROR_U24_R: push ecx ;U 1 Preserve ECX push ebx ; V1 Preserve EBX Macro_DivideImmediate8 24 ;--18 AL = AL % 24 mov cl, al ;U 1 Get the amount to shift mov eax, edx ; V1 Put our value in EAX and eax, 0FFFFFFh ;U 1 Clear the high byte ; While (CL >= 8) { .l1: cmp cl, 8 ; 1 jb > .l2 ;!V1(+4?) ; value >>>= 8; ror eax, 8 ;U!1 ; value = (value & 0xFFFFFF) | ((value >> 8) & 0xFF0000); ; CL -= 8; mov ebx, eax ;U*1 and eax, 0FFFFFFh ; V1 shr ebx, 8 ;U!1 sub cl, 8 ; V1 and ebx, 0FF0000h ;U 1 or eax, ebx ;U*1 ; } jmp < .l1 ;!V1 .l2: ;= 6-11 cycles per loop, 1-5 for last loop (when exiting) ; If (CL) { test cl, cl ;U 1 jz > .l3 ; V1 ; value >>>= CL; ror eax, cl ;--4 ; value |= (value >> 8) & 0xFF0000; // We don't need to clear the high byte here mov ebx, eax ;U*1 shr ebx, 8 ;U!1 and ebx, 0FF0000h ;U*1 or eax, ebx ;U*1 ; } .l3: pop ebx ;U 1 Restore EBX pop ecx ; V1 Restore ECX ret ;--2 ;= 24-60 cycles .EndFunc ; Mnemonic_ROR_U24_R ; ********************************************************************************************************************* ; Created: v0.0.1 ; Last Modified: v0.0.1 ; Rotates a signed 24bit value right by the amount specified ; In: EDX = 24bit value to rotate, AL = amount to rotate ; Out: EAX = 24bit Register Value after Rotate ; Lost Regs: None ; Cycles: 25-61 ALIGN 16 Mnemonic_ROR_S24_R: push ecx ;U 1 Preserve ECX push ebx ; V1 Preserve EBX Macro_DivideImmediate8 24 ;--18 AL = AL % 24 mov cl, al ;U 1 Get the amount to shift mov eax, edx ; V1 Put our value in EAX and eax, 0FFFFFFh ;U 1 Clear the high byte ; While (CL >= 8) { .l1: cmp cl, 8 ; 1 jb > .l2 ;!V1(+4?) ; value >>>= 8; ror eax, 8 ;U!1 ; value = (value & 0xFFFFFF) | ((value >> 8) & 0xFF0000); ; CL -= 8; mov ebx, eax ;U*1 and eax, 0FFFFFFh ; V1 shr ebx, 8 ;U!1 sub cl, 8 ; V1 and ebx, 0FF0000h ;U 1 or eax, ebx ;U*1 ; } jmp < .l1 ;!V1 .l2: ;= 6-11 cycles per loop, 1-5 for last loop (when exiting) ; If (CL) { test cl, cl ;U 1 jz > .l3 ; V1 ; value >>>= CL; ror eax, cl ;--4 ; value |= (value >> 8) & 0xFF0000; // We don't need to clear the high byte here mov ebx, eax ;U*1 shr ebx, 8 ;U!1 and ebx, 0FF0000h ;U*1 or eax, ebx ;U*1 ; } .l3: shl eax, 8 ;U!1 Shift it to the high byte pop ebx ; V1 Restore EBX sar eax, 8 ;U!1 SAR to sign extend pop ecx ; V1 Restore ECX ret ;--2 ;= 25-61 cycles .EndFunc ; Mnemonic_ROR_S24_R ; @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ ; @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ ; ShiftLeft Mnemonic Functions ; ********************************************************************************************************************* ; Created: v0.0.1 ; Last Modified: v0.0.1 ; Shifts a 24bit value in memory by the amount specified ; In: EDX -> 24bit memory value, AL = amount to shift ; Out: EAX = 24bit Register Value after Shift ; Lost Regs: eax ; Cycles: 17 ALIGN 16 Mnemonic_SHL_US24: push ecx ;U 1 Preserve ECX mov cl, al ; V1 Get the amount to shift Macro_ReadU24 edx ;U 5 Read in the 24bit value (sign is ignored) shl eax, cl ;--4 Shift left Macro_WriteUS24 edx ;U 5 Store the 24bit value pop ecx ; V1 Restore ECX ret ;--2 ;= 17 cycles .EndFunc ; Mnemonic_SHL_US24 ; ********************************************************************************************************************* ; Created: v0.0.1 ; Last Modified: v0.0.1 ; Shifts an unsigned 24bit value left by the amount specified ; In: EAX = 24bit memory value, DL = amount to shift ; Out: EAX = 24bit Register Value after shift ; Lost Regs: None ; Cycles: 8 ALIGN 16 Mnemonic_SHL_U24_R: push ecx ;U 1 Preserve ECX mov cl, dl ; V1 Get the amount to shift shl eax, cl ;--4 Shift! and eax, 0FFFFFFh ;U 1 Clear the high byte pop ecx ; V1 Restore ECX ret ;--2 ;= 8 cycles .EndFunc ; Mnemonic_SHL_U24_R ; ********************************************************************************************************************* ; Created: v0.0.1 ; Last Modified: v0.0.1 ; Shifts a signed 24bit value left by the amount specified ; In: EAX = 24bit memory value, DL = amount to shift ; Out: EAX = 24bit Register Value after shift ; Lost Regs: None ; Cycles: 9 ALIGN 16 Mnemonic_SHL_S24_R: push ecx ;U 1 Preserve ECX mov cl, dl ; V1 Get the amount to shift add cl, 8 ;U 1 Add 8 bits to the shift shl eax, cl ;--4 Shift! sar eax, 8 ;U!1 SAR back down to sign extend pop ecx ; V1 Restore ECX ret ;--2 ;= 9 cycles .EndFunc ; Mnemonic_SHL_S24_R ; @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ ; @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ ; ShiftRight Mnemonic Functions ; ********************************************************************************************************************* ; Created: v0.0.1 ; Last Modified: v0.0.1 ; Shifts a 24bit value in memory right by the amount specified ; In: EDX -> 24bit memory value, AL = amount to shift ; Out: Nothing ; Lost Regs: EAX = 24bit Register Value after shift ; Cycles: 18 ALIGN 16 Mnemonic_SHR_U24: push ecx ;U 1 Preserve ECX push ebx ; V1 Preserve EBX mov cl, al ;U 1 Get the amount to shift Macro_ReadU24 edx ;U*4 Read in the 24bit value (sign is ignored) shr eax, cl ;--4 Shift! Macro_WriteUS24 edx ;U*5 Store the 24bit value pop ebx ; V1 Restore EBX pop ecx ;U 1 Restore ECX ret ;--2 ;= 18 cycles .EndFunc ; Mnemonic_SHR_U24 ; ********************************************************************************************************************* ; Created: v0.0.1 ; Last Modified: v0.0.1 ; Shifts a 24bit value in memory right arithmetically by the amount specified ; In: EDX -> 24bit memory value, AL = amount to shift ; Out: Nothing ; Lost Regs: EAX = 24bit Register Value after shift ; Cycles: 17 ALIGN 16 Mnemonic_SAR_S24: push ecx ;U 1 Preserve ECX mov cl, al ; V1 Get the amount to shift Macro_ReadS24 edx ;U 5 Read in the 24bit value sar eax, cl ;--4 Shift! Macro_WriteUS24 edx ;U*5 Store the 24bit value pop ecx ; V1 Restore ECX ret ;--2 ;= 17 cycles .EndFunc ; Mnemonic_SAR_S24 ; ********************************************************************************************************************* ; Created: v0.0.1 ; Last Modified: v0.0.1 ; Shifts an unsigned 24bit value right by the amount specified ; In: EAX = 24bit memory value, DL = amount to shift ; Out: EAX = 24bit Register Value after shift ; Lost Regs: None ; Cycles: 8 ALIGN 16 Mnemonic_SHR_U24_R: push ecx ;U 1 Preserve ECX mov cl, dl ; V1 Get the amount to shift shr eax, cl ;--4 Shift! pop ecx ;U 1 Restore ECX ret ;--2 ;= 8 cycles .EndFunc ; Mnemonic_SHR_U24_R ; ********************************************************************************************************************* ; Created: v0.0.1 ; Last Modified: v0.0.1 ; Shifts a signed 24bit value right arithmetically by the amount specified ; In: EAX = 24bit memory value, DL = amount to shift ; Out: EAX = 24bit Register Value after shift ; Lost Regs: None ; Cycles: 10 ALIGN 16 Mnemonic_SAR_S24_R: push ecx ;U 1 Preserve ECX shl eax, 8 ;U!1 Shift the value to the high byte mov cl, dl ; V1 Get the amount to shift add cl, 8 ;U 1 Add 8 bits to the shift sar eax, cl ;--4 Shift! pop ecx ;U 1 Restore ECX ret ;--2 ;= 10 cycles .EndFunc ; Mnemonic_SAR_S24_R ; @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ ; @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ ; Subtract Mnemonic Functions ; ********************************************************************************************************************* ; Created: v0.0.1 ; Last Modified: v0.0.1 ; Subtracts a signed 16bit value from a 24bit value ; In: EDX -> 24bit memory value, AX = 16bit Value ; Out: EAX = 24bit Register Value after Subtract ; Lost Regs: eax ; Cycles: 13 ALIGN 16 Mnemonic_Subtract_US24AndS16: push ecx ;U 1 Preserve ECX ; Prepare both values mov ecx, eax ; V1 Set ECX to hold our 16bit value shl ecx, 16 ;U!1 Move the 16bit value to the top 2 bytes mov ah, [edx + 2] ; V1 Get the high byte of the 24bit value sar ecx, 16 ;U!1 Sign extend mov al, [edx + 1] ; V1 Get the middle byte shl eax, 16 ;U!1 Shift to the top mov al, [edx] ;U*1 Get the low byte sub eax, ecx ;U*1 Subtract Macro_WriteUS24 edx ;U*5 Store the result pop ecx ; V1 Restore ECX ret ;--2 ;= 13 cycles .EndFunc ; Mnemonic_Subtract_US24AndS16 ; ********************************************************************************************************************* ; Created: v0.0.1 ; Last Modified: v0.0.1 ; Subtracts a U/S24-256 value from a 24bit value ; In: EDX -> 24bit memory value, EAX = Low 32 bits of the U/S24-256 value ; Out: EAX = 24bit Register Value after Subtract ; Lost Regs: eax ; Cycles: 14 ALIGN 16 Mnemonic_Subtract_US24AndUS24Plus: push ecx ;U 1 Preserve ECX ; Prepare both values mov ecx, eax ; V1 Set ECX to hold the value to subtract mov ah, [edx + 2] ;U 1 Get the high byte of the 24bit value mov al, [edx + 1] ;U*1 Get the middle byte shl eax, 16 ;U!1 Shift to the top mov al, [edx] ;U*1 Get the low byte sub eax, ecx ;U*1 Subtract Macro_WriteUS24 edx ;U*5 Store the result pop ecx ; V1 Restore ECX ret ;--2 ;= 14 cycles .EndFunc ; Mnemonic_Subtract_US24AndUS24Plus ; @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ ; @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ ; SwitchEndian Mnemonic Functions ; ********************************************************************************************************************* ; Created: v0.0.1 ; Last Modified: v0.0.1 ; Switches the bytes of an unsigned 24bit value in a register ; In: EAX = 24bit Register Value ; Out: EAX = 24bit Register Value after byte swap ; Lost Regs: edx ; Cycles: 8 ALIGN 16 Mnemonic_SwitchEndian_U24_R: mov edx, eax ;U 1 Get a copy of the value shr eax, 8 ;U!1 Shift to get at the high byte mov dh, ah ;U*1 Get the high byte mov ah, dl ;U*1 Store the low byte into the high byte shl eax, 8 ;U*1 Shift the value back mov al, dh ;U*1 Store the high byte into the low byte ret ;--2 ;= 8 cycles .EndFunc ; Mnemonic_SwitchEndian_U24_R ; ********************************************************************************************************************* ; Created: v0.0.1 ; Last Modified: v0.0.1 ; Switches the bytes of a signed 24bit value in a register ; In: EAX = 24bit Register Value ; Out: EAX = 24bit Register Value after byte swap ; Lost Regs: edx ; Cycles: 9 ALIGN 16 Mnemonic_SwitchEndian_S24_R: mov edx, eax ;U 1 Get a copy of the value shr eax, 8 ;U!1 Shift to get at the high byte mov dh, ah ;U*1 Get the high byte mov ah, dl ;U*1 Store the low byte into the high byte shl eax, 16 ;U*1 Shift the value back and up to the high byte sar eax, 8 ;U*1 SAR down to sign extend mov al, dh ;U*1 Store the high byte into the low byte ret ;--2 ;= 9 cycles .EndFunc ; Mnemonic_SwitchEndian_S24_R ; ********************************************************************************************************************* ; Created: v0.0.1 ; Last Modified: v0.0.1 ; Switches the bytes of a 48bit value in memory ; In: EDX -> 48bit Value ; Out: Nothing ; Lost Regs: al ; Cycles: 12 ; 1 2 3 4 5 6 ; 6 5 4 3 2 1 ALIGN 16 Mnemonic_SwitchEndian_US48: push ecx ;U 1 Preserve ECX ; Swap bytes 2 and 5 mov al, BYTE [edx + 1] ; V1 Get byte 2 mov cl, BYTE [edx + 4] ;U 1 Get byte 5 mov BYTE [edx + 4], al ;U*1 Store byte 2 into byte 5 mov BYTE [edx + 1], cl ;U*1 Store byte 5 into byte 2 ; Swap bytes 3 and 4 mov al, BYTE [edx + 2] ; V1 Get byte 3 mov cl, BYTE [edx + 3] ;U 1 Get byte 4 mov BYTE [edx + 3], al ;U*1 Store byte 3 into byte 4 mov BYTE [edx + 2], cl ;U*1 Store byte 4 into byte 3 ; Swap bytes 1 and 6 mov al, BYTE [edx] ; V1 Get byte 1 mov cl, BYTE [edx + 5] ;U 1 Get byte 6 mov BYTE [edx + 5], al ;U*1 Store byte 1 into byte 6 mov BYTE [edx], cl ; V1 Store byte 6 into byte 1 pop ecx ;U 1 Restore ECX ret ;--2 ;= 12 cycles .EndFunc ; Mnemonic_SwitchEndian_US48 ; ********************************************************************************************************************* ; Created: v0.0.1 ; Last Modified: v0.0.1 ; Switches the bytes of a U48 value in a register ; In: DX:EAX = U48 Register Value ; Out: DX:EAX = U48 Register Value after byte swap ; Lost Regs: None ; Cycles: 12 ; dh dl ahh ahl ah al ; 1 2 3 4 5 6 ; 6 5 4 3 2 1 ALIGN 16 Mnemonic_SwitchEndian_U48_R: rol eax, 16 ;U!1 Rotate to access the middle 16 bits push ecx ; V1 Preserve ECX mov cl, ah ;U 1 Get the fourth byte mov ch, al ;U*1 Get the third byte mov ax, cx ;U*1+1 Store them back in reverse rol eax, 16 ;U!1 Rotate EAX back mov cl, dh ; V1 Get the high byte mov ch, al ;U 1 Get the low byte mov dh, ch ; V1 Store the low byte into the high byte mov al, cl ;U 1 Store the high byte into the low byte mov ch, dl ; V1 Get the fifth byte mov cl, ah ;U 1 Get the second byte mov ah, ch ; V1 Store the fifth byte into the second byte mov dl, cl ;U 1 Store the second byte into the fifth byte pop ecx ; V1 Restore ECX ret ;--2 ;= 12 cycles .EndFunc ; Mnemonic_SwitchEndian_U48_R ; ********************************************************************************************************************* ; Created: v0.0.1 ; Last Modified: v0.0.1 ; Switches the bytes of an S48 value in a register ; In: DX:EAX = S48 Register Value ; Out: DX:EAX = S48 Register Value after byte swap ; Lost Regs: None ; Cycles: 14 ; dh dl ahh ahl ah al ; 1 2 3 4 5 6 ; 6 5 4 3 2 1 ALIGN 16 Mnemonic_SwitchEndian_S48_R: rol eax, 16 ;U!1 Rotate to access the middle 16 bits push ecx ; V1 Preserve ECX mov cl, ah ;U 1 Get the fourth byte mov ch, al ;U*1 Get the third byte mov ax, cx ;U*1+1 Store them back in reverse rol eax, 16 ;U!1 Rotate EAX back mov cl, dh ; V1 Get the high byte mov ch, al ;U 1 Get the low byte mov dh, ch ; V1 Store the low byte into the high byte mov al, cl ;U 1 Store the high byte into the low byte mov ch, dl ; V1 Get the fifth byte mov cl, ah ;U 1 Get the second byte mov ah, ch ; V1 Store the fifth byte into the second byte mov dl, cl ;U 1 Store the second byte into the fifth byte pop ecx ; V1 Restore ECX shl edx, 16 ;U!1 Shift it to the high 16 bits sar edx, 16 ;U!1 SAR back to sign extend ret ;--2 ;= 14 cycles .EndFunc ; Mnemonic_SwitchEndian_S48_R ; ********************************************************************************************************************* ; Created: v0.0.1 ; Last Modified: v0.0.1 ; Switches the bytes of a 64bit value in memory ; In: EDX -> 64bit Value ; Out: Nothing ; Lost Regs: eax ; Cycles: 8 ALIGN 16 Mnemonic_SwitchEndian_US64: push ecx ;U 1 Preserve ECX mov eax, DWORD [edx] ; V1 Get the first 32 bits mov ecx, DWORD [edx + 4] ;U 1 Get the last 32 bits bswap eax ;--1 Swap the bytes in the first 32 bits bswap ecx ;--1 Swap the bytes in the last 32 bits mov [edx + 4], eax ;U 1 Store the swapped first 32 bits as the last 32 bits mov [edx], ecx ; V1 Store the swapped last 32 bits as the first 32 bits pop ecx ;U 1 Restore ECX ret ;--2 ;= 8 cycles .EndFunc ; Mnemonic_SwitchEndian_US64 ; ********************************************************************************************************************* ; Created: v0.0.1 ; Last Modified: v0.0.1 ; Switches the bytes of a 128bit value in memory ; In: EDX -> 128bit Value ; Out: Nothing ; Lost Regs: eax ; Cycles: 12 ALIGN 16 Mnemonic_SwitchEndian_US128: push ecx ;U 1 Preserve ECX mov eax, DWORD [edx] ; V1 Get the first 32 bits mov ecx, DWORD [edx + 12] ;U 1 Get the last 32 bits bswap eax ;--1 Swap the bytes in the first 32 bits bswap ecx ;--1 Swap the bytes in the last 32 bits mov [edx + 12], eax ;U 1 Store the swapped first 32 bits as the last 32 bits mov [edx], ecx ; V1 Store the swapped last 32 bits as the first 32 bits mov eax, DWORD [edx + 4] ;U 1 Get the second 32 bits mov ecx, DWORD [edx + 8] ; V1 Get the third 32 bits bswap eax ;--1 Swap the bytes in the second 32 bits bswap ecx ;--1 Swap the bytes in the third 32 bits mov [edx + 8], eax ;U 1 Store the swapped second 32 bits as the third 32 bits mov [edx + 4], ecx ; V1 Store the swapped third 32 bits as the second 32 bits pop ecx ;U 1 Restore ECX ret ;--2 ;= 12 cycles .EndFunc ; Mnemonic_SwitchEndian_US128 ; ********************************************************************************************************************* ; Created: v0.0.1 ; Last Modified: v0.0.1 ; Switches the bytes of a 256bit value in memory ; In: EDX -> 256bit Value ; Out: Nothing ; Lost Regs: eax ; Cycles: 20 ALIGN 16 Mnemonic_SwitchEndian_US256: push ecx ;U 1 Preserve ECX mov eax, DWORD [edx] ; V1 Get the first 32 bits mov ecx, DWORD [edx + 28] ;U 1 Get the last 32 bits bswap eax ;--1 Swap the bytes in the first 32 bits bswap ecx ;--1 Swap the bytes in the last 32 bits mov [edx + 28], eax ;U 1 Store the swapped first 32 bits as the last 32 bits mov [edx], ecx ; V1 Store the swapped last 32 bits as the first 32 bits mov eax, DWORD [edx + 4] ;U 1 Get the second 32 bits mov ecx, DWORD [edx + 24] ; V1 Get the seventh 32 bits bswap eax ;--1 Swap the bytes in the second 32 bits bswap ecx ;--1 Swap the bytes in the seventh 32 bits mov [edx + 24], eax ;U 1 Store the swapped second 32 bits as the seventh 32 bits mov [edx + 4], ecx ; V1 Store the swapped seventh 32 bits as the second 32 bits mov eax, DWORD [edx + 8] ;U 1 Get the third 32 bits mov ecx, DWORD [edx + 20] ; V1 Get the sixth 32 bits bswap eax ;--1 Swap the bytes in the third 32 bits bswap ecx ;--1 Swap the bytes in the sixth 32 bits mov [edx + 20], eax ;U 1 Store the swapped third 32 bits as the sixth 32 bits mov [edx + 8], ecx ; V1 Store the swapped sixth 32 bits as the third 32 bits mov eax, DWORD [edx + 12] ;U 1 Get the fourth 32 bits mov ecx, DWORD [edx + 16] ; V1 Get the fifth 32 bits bswap eax ;--1 Swap the bytes in the fourth 32 bits bswap ecx ;--1 Swap the bytes in the fifth 32 bits mov [edx + 16], eax ;U 1 Store the swapped fourth 32 bits as the fifth 32 bits mov [edx + 12], ecx ; V1 Store the swapped fifth 32 bits as the fourth 32 bits pop ecx ;U 1 Restore ECX ret ;--2 ;= 20 cycles .EndFunc ; Mnemonic_SwitchEndian_US256 ; @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ ; @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ ; Test Mnemonic Functions ; ********************************************************************************************************************* ; Created: v0.0.1 ; Last Modified: v0.0.1 ; Tests a 24bit memory value, setting S and Z properly ; In: EDX -> 24bit value to test ; Out: Nothing ; Lost Regs: al ; Cycles: 7-12 ALIGN 16 Mnemonic_Test_US24: mov al, BYTE [edx] ;U 1 Get the low byte test BYTE [edx + 1], al ;U*2 Test it against the middle byte jz > .l1 ;!V1(+4?) If they're zero, test the high byte only mov al, BYTE [edx + 2] ;U 1 Get the high byte or al, 1 ;U*1 Or 1 with the value to force the zero flag to be clear ; Sign will be set if the high bit was set jmp > .l2 ;!V1(+4?) Exit cause we're done .l1: ; If we get here, the low 16 bits were zero mov al, BYTE [edx + 2] ;U 1 Get the high byte test al, al ;U*1 Test the high byte .l2: ret ;--2 ;= 7-8(11-12) cycles (7|11/8|12) .EndFunc ; Mnemonic_Test_US24 ; ********************************************************************************************************************* ; Created: v0.0.1 ; Last Modified: v0.0.1 ; Tests a 24bit register value, setting S and Z properly ; In: EAX = 24bit value to test ; Out: Nothing ; Lost Regs: eax ; Cycles: 5-10 ALIGN 16 Mnemonic_Test_US24_R: or ah, al ;U 1 Combine the low 16 bits jz > .l1 ;!V1(+4?) If they're zero, test the high byte only shr eax, 8 ;U!1 Shift the high byte down or ah, 1 ;U*1 Or 1 with the value to force the zero flag to be clear ; Sign will be set if the high bit was set jmp > .l2 ;!V1(+4?) Exit cause we're done .l1: ; If we get here, the low 16 bits were zero shr eax, 8 ;U!1 Shift the high byte down test ah, ah ;U*1 Test the high byte .l2: ret ;--2 ;= 5-6(9-10) cycles (5|9/6|10) .EndFunc ; Mnemonic_Test_US24_R ; ##################################################################################################################### ; ##################################################################################################################### ; ##################################################################################################################### SECTION .data ; ##################################################################################################################### ; ##################################################################################################################### ; ##################################################################################################################### SECTION .bss