JECXZ - "error: jump out of range" !?
Posted: Thu Jan 22, 2004 3:55 am
I've 99% ported a compression/decompression algorithm known as SuperTiny over from Powerbasic to Purebasic (im slowly but surely porting all my crypto code over as my recent posts show!), but I'm encountering a couple of ASM problems that I wasnt having with Powerbasic.
If you try to compile the code below you'll get an error regarding the JECXZ line saying that the jump is out of range, yet virtually the same code compiles fine under Powerbasic. So is this a bug in the assembler, or ... ? Does anyone know any workarounds?
Under Powerbasic it compiles to this:
00401206 E3 28 JECXZ SHORT 00401230
Many thanks in advance for any help
If you try to compile the code below you'll get an error regarding the JECXZ line saying that the jump is out of range, yet virtually the same code compiles fine under Powerbasic. So is this a bug in the assembler, or ... ? Does anyone know any workarounds?
Under Powerbasic it compiles to this:
00401206 E3 28 JECXZ SHORT 00401230
Code: Select all
Procedure.l Compress(ptrInData.l, LenInData.l, ptrOutData.l, ptrTmpData.l)
PUSHAD
PUSH ptrTmpData
PUSH LenInData
PUSH ptrInData
PUSH ptrOutData
CALL l_cstart
JMP l_cend
CStart:
SUB edx, edx
XCHG eax, edx
PUSHAD
MOV ebp, esp
AND ecx, eax
MOV edi, [ebp+0x30]
CLD
MOV ch, 0x40
PUSH edi
REP stosd
SUB edx, 0x2864E25C
MOV esi, [ebp+0x28]
JNZ l_pack0
DEC edx
pack0:
PUSH ecx
SUB ax, 0x0AEB6
MOV edi, [ebp+0x24]
POP ebx
!stosw
XCHG eax, edx
POP ebp
!stosd
PUSH edi
XCHG eax, edx
PUSH esp
pack1:
TEST cl, 7
!lodsb
JNZ l_pack3
XCHG edx, [esp]
ADC ah, dl
POP edx
XCHG edi, [esp]
ROR edx, 1
MOV [edi], ah
JC l_pack2
XOR edx, 0x2C047C3E
pack2:
POP edi
MOV ah, 0x0FF
PUSH edi
XOR edx, 0x76C52B8D
INC edi
PUSH edx
pack3:
CMP al, [ebx+ebp]
JZ l_pack5
ROR edx, 1
MOV [ebx+ebp], al
JNC l_pack4
XOR edx, 0x2C047C3E
pack4:
MOV bh, al
XOR edx, 0x5AC157B3
ADC al, dl
!stosb
MOV al, bh
STC
pack5:
INC ecx
MOV bh, bl
RCL ah, 1
CMP ecx, [esp+0x34]
MOV bl, al
JC l_pack1
ROR ah, cl
POP ebx
ADD ah, bl
POP esi
MOV ebp, esp
SUB edi, [ebp+0x24]
MOV [ebp+0x14], edx
XCHG ah, [esi]
ADD [ebp+0x1C], edi
POPAD
RET 0x10
CEnd:
POPAD
EndProcedure
Procedure.l Decompress(ptrInData.l, LenInData.l, ptrOutData.l, ptrTmpData.l)
PUSHAD
PUSH ptrTmpData
PUSH LenInData
PUSH ptrInData
PUSH ptrOutData
CALL l_decstart
JMP l_decend
DecStart:
SUB eax, eax
PUSHAD
MOV ebp, esp
AND ecx, eax
MOV edi, [ebp+0x30]
CLD
MOV ch, 0x40
PUSH edi
REP stosd
MOV esi, [ebp+0x28]
XCHG ebx, eax
ADD ecx, [ebp+0x2C]
!lodsw
MOV edi, [ebp+0x24]
ADD ecx,-6
POP ebp
!lodsd
XCHG eax, edx
unpack0:
DB 0xF6 ;TEST BYTE PTR [ESP+1C], 7
DB 0x44
DB 0x24
DB 0x1C
DB 0x07
JNZ l_unpack2
ROR edx, 1
JECXZ l_unpack5
JNC l_unpack1
XOR edx, 0x2C047C3E
unpack1:
!lodsb
DEC ecx
XOR edx, 0x5AC157B3
SBB al, dl
MOV ah, al
unpack2:
SHL ah, 1
DB 0xFE ;INC BYTE PTR [ESP+1C]
DB 0x44
DB 0x24
DB 0x1C
JNC l_unpack4
ROR edx, 1
JECXZ l_unpack5
JC l_unpack3
XOR edx, 0x2C047C3E
unpack3:
!lodsb
DEC ecx
XOR edx, 0x76C52B8D
SBB al, dl
MOV [ebx+ebp], al
unpack4:
MOV al, [ebx+ebp]
MOV bh, bl
!stosb
MOV bl, al
JMP l_unpack0
DEC edx
PUSH ecx
unpack5:
SUB edi, [esp+0x24]
MOV [esp+0x1C], edi
POPAD
RET 0x10
DecEnd:
POPAD
EndProcedure
;Dim sInData AS STRING, sOutData AS STRING, sTmpData AS STRING * 65535, OutSize AS DWORD
sTmpData.s = Space(1000)
sTmpData = ReplaceString(sTmpData, " ", Chr(0), 1, 1)
;// Data to compress
sInData.s = "testingtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtesting"
;// Compress it ...
sOutData.s = Space(Len(sInData))
sOutData.s = ReplaceString(sOutData, " ", Chr(0), 1, 1)
OutSize.l = Compress(@sInData, Len(sInData), @sOutData, @sTmpData)
If OutSize > Len(sInData)
Debug "Unable to compress this data (probably not enough repetition)."
;End
EndIf
Debug "Original size = " + StrU(Len(sInData), #LONG) + " bytes"
Debug "Compressed size = " + StrU(OutSize,#LONG) + " bytes"
Many thanks in advance for any help