Da hier welche Probleme mit Proceduren-Aufrufen und so weiter in Assembler haben, hab ich hier den Code von PureBasic zu Assembelr (ohne Debugger) übersetzt:
In
PureBasic:
Code: Alles auswählen
Procedure.s MyProcedure(StringParameter.s, LongParameter.l)
Protected sLocalString.s
sLocalString = Mid(StringParameter, 1, LongParameter)
ProcedureReturn sLocalString
EndProcedure
Define Out$ = MyProcedure("Hallo, PureBasic!", 5)
MessageRequester("Title", Out$)
End 1
In
Assembler (mit nem Tool von mir mit den Orginal-Zeilen als Kommentare angegeben werden):
Code: Alles auswählen
;
; PureBasic v4.02 (Windows - x86) generated code
;
; © 2006 Fantaisie Software
;
; The header must remain intact for Re-Assembly
;
; String
; StringExtension
; Requester
; FileSystem
; Date
; Object
; SimpleList
; :System
; KERNEL32
;
format MS COFF
;
extrn _ExitProcess@4
extrn _GetModuleHandleA@4
extrn _HeapCreate@12
extrn _HeapDestroy@4
;
extrn _PB_FreeSimpleLists@0
extrn _PB_InitRequester@0
extrn _PB_InitSimpleList@0
extrn _PB_MessageRequester@8
extrn _PB_Mid@16
extrn _SYS_CopyString@0
extrn _memset
extrn SYS_AllocateString
extrn SYS_FastAllocateString
extrn _SYS_FreeString@4
extrn _PB_StringBase
extrn PB_StringBase
extrn _SYS_InitString@0
;
extrn _PB_StringBasePosition
public _PB_Instance
public _PB_ExecutableType
public _PB_MemoryBase
public PB_Instance
public PB_MemoryBase
public _PB_EndFunctions
public _PB_DEBUGGER_LineNumber
public _PB_DEBUGGER_IncludedFiles
macro pb_public symbol
{
public _#symbol
public symbol
_#symbol:
symbol:
}
macro align value { rb (value-1) - ($-_PB_DataSection + value-1) mod value }
macro 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
CALL _SYS_InitString@0
CALL _PB_InitSimpleList@0
CALL _PB_InitRequester@0
; :
; Procedure.s MyProcedure(StringParameter.s, LongParameter.l)
macro MP0{
_Procedure0:
PUSH dword [esp+12]
POP dword [_PB_StringBasePosition]
PS0=12
XOR eax,eax
PUSH eax
PUSH eax
MOV edx,dword [esp+PS0+0]
LEA ecx,[esp+0]
CALL SYS_FastAllocateString
; Protected sLocalString.s
;
; sLocalString = Mid(StringParameter, 1, LongParameter)
PUSH dword [_PB_StringBasePosition]
PUSH dword [esp+PS0+8]
PUSH dword 1
PUSH dword [esp+12]
CALL _PB_Mid@16
SUB esp,4
LEA ecx,[esp+8]
POP edx
CALL SYS_AllocateString
;
; ProcedureReturn sLocalString
MOV edx,dword [esp+4]
PUSH dword [_PB_StringBasePosition]
CALL _SYS_CopyString@0
POP eax
ADD eax,[PB_StringBase]
JMP _EndProcedure1
; EndProcedure
MOV eax,[_PB_StringBasePosition]
ADD eax,[PB_StringBase]
MOV byte [eax],0
_EndProcedure1:
PUSH dword [esp+4]
CALL _SYS_FreeString@4
PUSH dword [esp]
CALL _SYS_FreeString@4
ADD esp,8
RET 8
}
;
; Define Out$ = MyProcedure("Hallo, PureBasic!", 5)
PUSH dword [_PB_StringBasePosition]
PUSH dword 5
PUSH dword _S1
CALL _Procedure0
LEA ecx,[v_Out$]
POP edx
CALL SYS_AllocateString
;
; MessageRequester("Title", Out$)
PUSH dword [v_Out$]
PUSH dword _S2
CALL _PB_MessageRequester@8
;
; End 1
PUSH dword 1
JMP _PB_EOP
;
_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_FreeSimpleLists@0
RET
;
MP0
;
section '.data' data readable writeable
;
_PB_DataSection:
_PB_DEBUGGER_LineNumber: dd -1
_PB_DEBUGGER_IncludedFiles: dd 0
_PB_ExecutableType: dd 0
public _SYS_StaticStringStart
_SYS_StaticStringStart:
_S1: db "Hallo, PureBasic!",0
_S2: db "Title",0
pb_public PB_NullString
db 0
public _SYS_StaticStringEnd
_SYS_StaticStringEnd:
align 4
align 4
s_s:
dd 0
dd -1
align 4
;
section '.bss' readable writeable
_PB_BSSSection:
bssalign 4
;
I_BSSStart:
_PB_MemoryBase:
PB_MemoryBase: rd 1
_PB_Instance:
PB_Instance: rd 1
;
bssalign 4
PB_DataPointer rd 1
v_Out$ rd 1
bssalign 4
bssalign 4
bssalign 4
bssalign 4
I_BSSEnd:
section '.data' data readable writeable
SYS_EndDataSection: