Publié : dim. 07/déc./2008 12:44
tu chaume pas dis donc 

Code : Tout sélectionner
* ADDED : Global variables
* ADDED : Used Userlibs
* ADDED : End Function like the Init
* IMPROVED : Sample Total Interface
* DONE : Tests with all Samples
Code : Tout sélectionner
* TO ADD : Parameter with default value
* TO ADD : Parameter with type : linked list
* TO ADD : Parameter with type : tables
* TO IMPROVE : Deleting of content of directories (!now : Deleting recursively main directory)
* TO IMPROVE : Clearing ASM Codes (a lot of newlines)
* TO IMPROVE : Step 2 : in first function, moving asm detection code to second function
* TO DO : Tests with all Samples
Code : Tout sélectionner
Procedure fill(A.l(1), longueur) ; Le 1 représente le nombre de dimensions du tableau
For i = 0 To longueur
A(i) = i
Next i
EndProcedure
Dim A.l(10)
fill(A(), 10) ; Le tableau A() est passé en paramètre
Code : Tout sélectionner
;
; PureBasic 4.30 Beta 5 (Windows - x86) generated code
;
; (c) 2008 Fantaisie Software
;
; The header must remain intact for Re-Assembly
;
; :System
; KERNEL32
; :Import
;
format MS COFF
;
extrn _ExitProcess@4
extrn _GetModuleHandleA@4
extrn _HeapCreate@12
extrn _HeapDestroy@4
;
extrn _memset
extrn SYS_FreeArray
extrn SYS_AllocateArray
public _PB_Instance
public _PB_ExecutableType
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
;
;
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
; :
; Dim MonTableau.l(41)
; MonTableau(0) = 1
; MonTableau(1) = 2
;
;
; Procedure fill(A.l(1), longueur) ; Le 1 représente le nombre de dimensions du tableau
macro MP0{
_Procedure0:
PUSH ebp
PUSH ebx
PS0=20
XOR eax,eax
PUSH eax
PUSH eax
MOV eax,dword [esp+PS0+0]
MOV dword [esp+0],eax
; For i = 0 To longueur
MOV dword [esp+4],0
_For1:
MOV eax,dword [esp+PS0+4]
CMP eax,dword [esp+4]
JL _Next2
; A(i) = i
PUSH dword [esp+4]
MOV ebx,dword [esp+8]
MOV edx,[esp+4]
MOV ebp,dword [edx]
SAL ebx,2
POP eax
MOV dword [ebp+ebx],eax
; Next i
_NextContinue2:
INC dword [esp+4]
JMP _For1
_Next2:
; EndProcedure
XOR eax,eax
_EndProcedure1:
ADD esp,8
POP ebx
POP ebp
RET 8
}
;
; Dim A.l(10)
PUSH dword 5
PUSH dword a_A
PUSH dword 0
MOV edx,dword [a_A]
CALL SYS_FreeArray
MOV eax,11
PUSH dword 4
CALL SYS_AllocateArray
; fill(A(), 10) ; Le tableau A() est passé en paramètre
PUSH dword 10
PUSH dword a_A
CALL _Procedure0
;
;
_PB_EOP_NoValue:
PUSH dword 0
_PB_EOP:
CALL _PB_EndFunctions
PUSH dword [PB_MemoryBase]
CALL _HeapDestroy@4
CALL _ExitProcess@4
_PB_EndFunctions:
RET
;
MP0
;
section '.data' data readable writeable
;
_PB_DataSection:
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
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
PB_DataPointer rd 1
align 4
align 4
align 4
align 4
a_A:
rd 1
rd 1
I_BSSEnd:
section '.data' data readable writeable
SYS_EndDataSection:
Code : Tout sélectionner
section '.bss' readable writeable
_PB_BSSSection:
align 4
;
I_BSSStart:
_PB_MemoryBase:
PB_MemoryBase: rd 1
_PB_Instance:
PB_Instance: rd 1
;
align 4
PB_DataPointer rd 1
align 4
align 4
align 4
align 4
a_A: <-- c'est ici
rd 1 <-- c'est ici
rd 1 <-- c'est ici
I_BSSEnd:
section '.data' data readable writeable
SYS_EndDataSection:
Code : Tout sélectionner
; Procedure fill(A.l(1), longueur) ; Le 1 représente le nombre de dimensions du tableau
macro MP0{
_Procedure0:
PUSH ebp
PUSH ebx
PS0=20
XOR eax,eax
PUSH eax
PUSH eax
MOV eax,dword [esp+PS0+0]
MOV dword [esp+0],eax
; For i = 0 To longueur
MOV dword [esp+4],0
_For1:
MOV eax,dword [esp+PS0+4]
CMP eax,dword [esp+4]
JL _Next2
; A(i) = i
PUSH dword [esp+4]
MOV ebx,dword [esp+8]
MOV edx,[esp+4]
MOV ebp,dword [edx]
SAL ebx,2
POP eax
MOV dword [ebp+ebx],eax
; Next i
_NextContinue2:
INC dword [esp+4]
JMP _For1
_Next2:
; EndProcedure
XOR eax,eax
_EndProcedure1:
ADD esp,8
POP ebx
POP ebp
RET 8
}
- Il est possible de passer directement une ligne complète à l'assembleur sans aucune modification en utilisant le caractère '!' en début de ligne. Ceci permet d'avoir un accès total aux fonctionnalités de l'assembleur. Pour faciliter l'accès aux variables locales, une notation a été mise en place: 'p.v_NomVariable' pour une variable standard et 'p.p_NomPointeur' pour un pointeur.
Exemple:
Procedure Test(*Pointer, Variable)
! MOV dword [p.p_Pointer], 20
! MOV dword [p.v_Variable], 30
Debug *Pointer
Debug Variable
EndProcedure