PDA

View Full Version : Subroutines usind direct call



Charles Pegge
08-03-2008, 18:04
I will bombard you with examples until you tell me to stop :)

Subroutines

Direct calls, E8 .. and direct long jumps E9 ... use relative addressing. You have to work out the distance between where you are at the end of this instruction and where you want to go.



' Using Machine Code with ThinBasic
'---------------------------------------------------------------------------
'---Reference:
'---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.

'----------------------------------------------
' Machine code Subroutines using direct call
' Demonstrating relative addressing:
'
' start counting from the byte immediately
' following the whole call instruction: 0 1 2 3 etc
' then patch this value in hexadecimal into the call instruction.
'----------------------------------------------
dim sMC as string = MC_Eval$ "
e8 NL6 ' call AA
e8 NL7 ' call BB
c3 ' ret
'-----------------------'
' AA '
b8 NL1 ' mov eax,1
c3 ' ret
'-----------------------'
' BB '
05 NL2 ' add eax,2
C3 ' ret
"
'----------------------------------------------
' ---Invoke the machine code string
dim RetVal as long = MC_Exec(sMC)
MsgBox 0, RetVal
'----------------------------------------------