2016 Update
This commit is contained in:
parent
948b86eafa
commit
dcf5d15da3
7965 changed files with 139854 additions and 31002 deletions
33
Task/Machine-code/PicoLisp/machine-code.l
Normal file
33
Task/Machine-code/PicoLisp/machine-code.l
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
(setq P
|
||||
(struct (native "@" "malloc" 'N 39) 'N
|
||||
# Align
|
||||
144 # nop
|
||||
144 # nop
|
||||
|
||||
# Prepare stack
|
||||
106 12 # pushq $12
|
||||
184 7 0 0 0 # mov $7, %eax
|
||||
72 193 224 32 # shl $32, %rax
|
||||
80 # pushq %rax
|
||||
|
||||
# Rosetta task code
|
||||
139 68 36 4 3 68 36 8
|
||||
|
||||
# Get result
|
||||
76 137 227 # mov %r12, %rbx
|
||||
137 195 # mov %eax, %ebx
|
||||
72 193 227 4 # shl $4, %rbx
|
||||
128 203 2 # orb $2, %bl
|
||||
|
||||
# Clean up stack
|
||||
72 131 196 16 # add $16, %rsp
|
||||
|
||||
# Return
|
||||
195 ) # ret
|
||||
foo (>> 4 P) )
|
||||
|
||||
# Execute
|
||||
(println (foo))
|
||||
|
||||
# Free memory
|
||||
(native "@" "free" NIL P)
|
||||
|
|
@ -1,22 +1,29 @@
|
|||
CompilerIf #PB_Compiler_Processor <> #PB_Processor_x86
|
||||
CompilerError "Code requires a 32-bit processor."
|
||||
CompilerEndIf
|
||||
|
||||
|
||||
; Machine code using the Windows API
|
||||
|
||||
Procedure MachineCodeVirtualAlloc(a,b)
|
||||
*vm = VirtualAlloc_(#Null,?ecode-?scode,#MEM_COMMIT,#PAGE_EXECUTE_READWRITE)
|
||||
If(*vm)
|
||||
CopyMemory_(*vm,?scode,?ecode-?scode)
|
||||
CopyMemory(?scode, *vm, ?ecode-?scode)
|
||||
eax_result=CallFunctionFast(*vm,a,b)
|
||||
VirtualFree_(*vm,0,#MEM_RELEASE)
|
||||
ProcedureReturn eax_result
|
||||
EndIf
|
||||
EndProcedure
|
||||
|
||||
rv=MachineCodeVirtualAlloc(7,12)
|
||||
MessageRequester("MachineCodeVirtualAlloc",str(rv)+space(50),#PB_MessageRequester_Ok)
|
||||
rv=MachineCodeVirtualAlloc( 7, 12)
|
||||
MessageRequester("MachineCodeVirtualAlloc",Str(rv)+Space(50),#PB_MessageRequester_Ok)
|
||||
|
||||
#HEAP_CREATE_ENABLE_EXECUTE=$00040000
|
||||
|
||||
Procedure MachineCodeHeapCreate(a,b)
|
||||
hHeap=HeapCreate_(#HEAP_CREATE_ENABLE_EXECUTE,?ecode-?scode,?ecode-?scode)
|
||||
If(hHeap)
|
||||
CopyMemory_(hHeap,?scode,?ecode-?scode)
|
||||
CopyMemory(?scode, hHeap, ?ecode-?scode)
|
||||
eax_result=CallFunctionFast(hHeap,a,b)
|
||||
HeapDestroy_(hHeap)
|
||||
ProcedureReturn eax_result
|
||||
|
|
@ -24,7 +31,7 @@ hHeap=HeapCreate_(#HEAP_CREATE_ENABLE_EXECUTE,?ecode-?scode,?ecode-?scode)
|
|||
EndProcedure
|
||||
|
||||
rv=MachineCodeHeapCreate(7,12)
|
||||
MessageRequester("MachineCodeHeapCreate",str(rv)+space(50),#PB_MessageRequester_Ok)
|
||||
MessageRequester("MachineCodeHeapCreate",Str(rv)+Space(50),#PB_MessageRequester_Ok)
|
||||
End
|
||||
|
||||
; 8B442404 mov eax,[esp+4]
|
||||
|
|
@ -33,6 +40,6 @@ End
|
|||
|
||||
DataSection
|
||||
scode:
|
||||
Data.c $8B,$44,$24,$04,$03,$44,$24,$08,$C2,$08,$00
|
||||
Data.a $8B,$44,$24,$04,$03,$44,$24,$08,$C2,$08,$00
|
||||
ecode:
|
||||
EndDataSection
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue