<< Click to Display Table of Contents >> Navigation: ThinBASIC Core Language > Machine Code > MC_Exec |
Description
Execute a machine code string created with MC_Eval$ function.
Syntax
Ret = MC_Exec(MachineCodeString)
Returns
Number.
Parameters
Name |
Type |
Optional |
Meaning |
MachineCodeString |
String |
No |
Machine code string to execute |
Remarks
Restrictions
See also
Examples
' Using Machine Code with ThinBasic
'---------------------------------------------------------------------------
'---Reference:
' Intel x86 Architecture Ref Manual Vol 2
'---http://developer.intel.com/design/pentiumii/manuals/243191.htm
'---------------------------------------------------------------------------
' Syntax rules:
' #Variable patches in long address of Variable (4 bytes)
' NLn patches in long decimal value n (4 bytes)
' comments are indicated by a quote mark '
' all other words are read as hexadecimal bytes.
' An error during MC_Eval$ will produce a string containing &hc3 (ret) only.
'----------------------------------------------
' arithmentic on the Floating Point Processor (FPU)
'
' (vv1+vv2) / (vv3+vv4)
'
' 23 bytes
'----------------------------------------------
Dim vv(8) As Double
Dim sMC As String
sMC = MC_EVAL$ "
b8 #vv ' vv base address
dd 40 00 ' fld qword ptr [eax+00] ' ( vv1
dc 40 08 ' fadd qword ptr [eax+08] ' + vv2
dd 40 10 ' fld qword ptr [eax+16] ' ) ( vv3
dc 40 18 ' fadd qword ptr [eax+24] ' +vv4
'de c9 ' fmulp st(1) '
de f9 ' fdivp st(1) ' ) /
dd 58 38 ' fstp qword ptr [eax+56] ' = vv8
c3 ' ret '
"
'-------------------------------'
vv(1) = 1.5
vv(2) = 2
vv(3) = 2.5
vv(4) = 3
' (vv1+vv2) / (vv3+vv4)
' = 0.636363...
MC_Exec sMC
MSGBOX 0, vv(8) ' result