Charvista, in general, I like your use of alloc to make them nestable. On the other hand, have you looked at the asm? It's LOOOOOOONG! So maybe not great for time sensitive code. This is your sample, with no edits:
Code:
;
; PureBasic 4.60 (Windows - x86) generated code
;
; (c) 2011 Fantaisie Software
;
; The header must remain intact for Re-Assembly
;
; Memory
; :System
; KERNEL32
; :Import
;
format MS COFF
;
;
extrn _PB_AllocateMemory@4
extrn _PB_FreeMemory@4
extrn _PB_FreeMemorys@0
extrn _PB_InitMemory@0
extrn _PB_PeekD@4
extrn _PB_PokeD@12
extrn _ExitProcess@4
extrn _GetModuleHandleA@4
extrn _HeapCreate@12
extrn _HeapDestroy@4
extrn _memset
public _PB_Instance
public _PB_ExecutableType
public _PB_OpenGLSubsystem
public _PB_MemoryBase
public PB_Instance
public PB_MemoryBase
public _PB_EndFunctions
macro pb_public symbol
{
public _#symbol
public symbol
_#symbol:
symbol:
}
macro pb_align value { rb (value-1) - ($-_PB_DataSection + value-1) mod value }
macro pb_bssalign value { rb (value-1) - ($-_PB_BSSSection + value-1) mod value }
public PureBasicStart
;
section '.code' code readable executable align 8
;
;
PureBasicStart:
;
PUSH dword I_BSSEnd-I_BSSStart
PUSH dword 0
PUSH dword I_BSSStart
CALL _memset
ADD esp,12
PUSH dword 0
CALL _GetModuleHandleA@4
MOV [_PB_Instance],eax
PUSH dword 0
PUSH dword 4096
PUSH dword 0
CALL _HeapCreate@12
MOV [PB_MemoryBase],eax
CALL _PB_InitMemory@0
;
;==================================================================
; Macro Loop(Var,Starting,Ending,Increment=1)
;==================================================================
; Macro EndLoop(Var)
;==================================================================
; Example
; Loop(i.d,1,5.5,1.5)
PUSH dword 9
CALL _PB_AllocateMemory@4
MOV dword [p_Starti],eax
FLD qword [D1]
SUB esp,8
FSTP qword [esp]
PUSH dword [p_Starti]
CALL _PB_PokeD@12
PUSH dword 9
CALL _PB_AllocateMemory@4
MOV dword [p_Endi],eax
FLD qword [D2]
SUB esp,8
FSTP qword [esp]
PUSH dword [p_Endi]
CALL _PB_PokeD@12
PUSH dword 9
CALL _PB_AllocateMemory@4
MOV dword [p_Incri],eax
FLD qword [D3]
SUB esp,8
FSTP qword [esp]
PUSH dword [p_Incri]
CALL _PB_PokeD@12
FLD qword [D1]
FSTP qword [v_i]
_Repeat1:
; Loop(j.d,16,4,-3.5)
PUSH dword 9
CALL _PB_AllocateMemory@4
MOV dword [p_Startj],eax
FLD qword [D4]
SUB esp,8
FSTP qword [esp]
PUSH dword [p_Startj]
CALL _PB_PokeD@12
PUSH dword 9
CALL _PB_AllocateMemory@4
MOV dword [p_Endj],eax
FLD qword [D5]
SUB esp,8
FSTP qword [esp]
PUSH dword [p_Endj]
CALL _PB_PokeD@12
PUSH dword 9
CALL _PB_AllocateMemory@4
MOV dword [p_Incrj],eax
FLD qword [D6]
SUB esp,8
FSTP qword [esp]
PUSH dword [p_Incrj]
CALL _PB_PokeD@12
FLD qword [D4]
FSTP qword [v_j]
_Repeat2:
; Debug "("+StrD(i,2)+", "+StrD(j,2)+")"
; EndLoop(j)
PUSH dword [p_Startj]
CALL _PB_PeekD@4
FSTP qword [v_Startingj]
PUSH dword [p_Endj]
CALL _PB_PeekD@4
FSTP qword [v_Endingj]
PUSH dword [p_Incrj]
CALL _PB_PeekD@4
FSTP qword [v_Incrementj]
FLD qword [v_j]
FADD qword [v_Incrementj]
FADD qword [D7]
FSTP qword [v_j]
FLD qword [v_Startingj]
FLD qword [v_Endingj]
FSUB qword [v_Startingj]
FADD qword [D7]
FDIV qword [v_Incrementj]
FMUL qword [v_Incrementj]
FADDP st1,st0
FADD qword [D7]
FSTP qword [v_Qend]
FLD qword [v_j]
FSTP qword [v_a]
FLD qword [v_Qend]
FSTP qword [v_b]
FLD qword [v_Incrementj]
FCOMP qword [D7]
FNSTSW ax
TEST ah,1h
JE _EndIf4
FLD qword [v_Qend]
FSTP qword [v_a]
FLD qword [v_j]
FSTP qword [v_b]
_EndIf4:
FLD qword [v_a]
FLD qword [v_b]
FCOMPP
FNSTSW ax
TEST ah,1h
JE _Repeat2
_Until2:
PUSH dword [p_Incrj]
CALL _PB_FreeMemory@4
PUSH dword [p_Startj]
CALL _PB_FreeMemory@4
PUSH dword [p_Endj]
CALL _PB_FreeMemory@4
; EndLoop(i)
PUSH dword [p_Starti]
CALL _PB_PeekD@4
FSTP qword [v_Startingi]
PUSH dword [p_Endi]
CALL _PB_PeekD@4
FSTP qword [v_Endingi]
PUSH dword [p_Incri]
CALL _PB_PeekD@4
FSTP qword [v_Incrementi]
FLD qword [v_i]
FADD qword [v_Incrementi]
FADD qword [D7]
FSTP qword [v_i]
FLD qword [v_Startingi]
FLD qword [v_Endingi]
FSUB qword [v_Startingi]
FADD qword [D7]
FDIV qword [v_Incrementi]
FMUL qword [v_Incrementi]
FADDP st1,st0
FADD qword [D7]
FSTP qword [v_Qend]
FLD qword [v_i]
FSTP qword [v_a]
FLD qword [v_Qend]
FSTP qword [v_b]
FLD qword [v_Incrementi]
FCOMP qword [D7]
FNSTSW ax
TEST ah,1h
JE _EndIf6
FLD qword [v_Qend]
FSTP qword [v_a]
FLD qword [v_i]
FSTP qword [v_b]
_EndIf6:
FLD qword [v_a]
FLD qword [v_b]
FCOMPP
FNSTSW ax
TEST ah,1h
JE _Repeat1
_Until1:
PUSH dword [p_Incri]
CALL _PB_FreeMemory@4
PUSH dword [p_Starti]
CALL _PB_FreeMemory@4
PUSH dword [p_Endi]
CALL _PB_FreeMemory@4
;
; Debug "last i = " + StrD(i)
; Debug "last j = " + StrD(j)
;==================================================================
_PB_EOP_NoValue:
PUSH dword 0
_PB_EOP:
CALL _PB_EndFunctions
PUSH dword [PB_MemoryBase]
CALL _HeapDestroy@4
CALL _ExitProcess@4
_PB_EndFunctions:
CALL _PB_FreeMemorys@0
RET
;
;
section '.data' data readable writeable
;
_PB_DataSection:
_PB_OpenGLSubsystem: db 0
pb_public PB_DEBUGGER_LineNumber
dd -1
pb_public PB_DEBUGGER_IncludedFiles
dd 0
pb_public PB_DEBUGGER_FileName
db 0
_PB_ExecutableType: dd 0
align 4
D1: dd 0,1072693248
D2: dd 0,1075183616
D3: dd 0,1073217536
D4: dd 0,1076887552
D5: dd 0,1074790400
D6: dd 0,-1072955392
D7: dd 0,0
align 4
s_s:
dd 0
dd -1
align 4
;
section '.bss' readable writeable
_PB_BSSSection:
align 4
;
I_BSSStart:
_PB_MemoryBase:
PB_MemoryBase: rd 1
_PB_Instance:
PB_Instance: rd 1
;
align 4
v_i rq 1
v_j rq 1
v_Startingj rq 1
v_Endingj rq 1
v_Incrementj rq 1
v_Qend rq 1
v_a rq 1
v_b rq 1
v_Startingi rq 1
v_Endingi rq 1
v_Incrementi rq 1
PB_DataPointer rd 1
p_Starti rd 1
p_Endi rd 1
p_Incri rd 1
p_Startj rd 1
p_Endj rd 1
p_Incrj rd 1
align 4
align 4
align 4
align 4
I_BSSEnd:
section '.data' data readable writeable
SYS_EndDataSection:
That's 25 instructions to get started, and 49 at the end (minus a few labels). That's a lot of overhead for a loop...mine is 10 instructions total (plus labels):
Code:
; ForStart(x, 1, 3.5)
MOV dword [v_x],1065353216
_While1:
FLD dword [v_x]
FCOMP dword [F1]
FNSTSW ax
TEST ah,41h
JE _Wend1
; Debug x
; ForEnd(x, 0.5)
FLD dword [v_x]
FADD dword [F2]
FSTP dword [v_x]
JMP _While1
_Wend1:
;
; Debug "last x " + Str(x)