Create an object at a given address: Difference between revisions
Content added Content deleted
(Scala contribution added) |
No edit summary |
||
Line 459: | Line 459: | ||
Value is 52, address is 26431776 |
Value is 52, address is 26431776 |
||
</pre> |
</pre> |
||
=={{header|M2000 Interpreter}}== |
|||
In M2000 we can create two kind of buffers, one for data, and one for code. Buffer for code is immutable at execution time. We can execute code by using an offset. Buffer for data is always mutable, but can't execute code. |
|||
There is no assembler x86 for M2000 yet, so we have to write code using a reference book and some subs for help |
|||
Memory addresses are nit the physical address, it's from virtual space. |
|||
<lang M2000 Interpreter> |
|||
Module CheckIt { |
|||
structure alfa { |
|||
val as long |
|||
} |
|||
Buffer Clear Beta as alfa*2 |
|||
Print Beta(0) ' return address |
|||
Return Beta, 0!val:=500 ' unsigned integer 32 bit |
|||
Print Eval(Beta, 0!val)=500 |
|||
Return Beta, 0!val:=0xFFFFFFFF |
|||
Print Eval(Beta, 0!val)=4294967295 |
|||
Buffer Code ExecMem as byte*1024 |
|||
Offset=0 |
|||
EmbLong(0xb8, 5000) ' mov eax,5100 |
|||
EmbByteLong(0x3,0x5, Beta(0)) ' add eax, [Beta(0)] |
|||
EmbLong(0xa3, Beta(1)) ' mov [Beta(1)], eax |
|||
EmbByte(0x31, 0xC0) ' xor eax, eax |
|||
Ret() ' Return |
|||
Execute Code ExecMem, 0 |
|||
Print eval(Beta, 1!val)=4999 |
|||
Sub Ret() |
|||
Return ExecMem, Offset:=0xC3 |
|||
Offset++ |
|||
End Sub |
|||
Sub EmbByte() |
|||
Return ExecMem, Offset:=Number, Offset+1:=Number |
|||
Offset+=2 |
|||
End Sub |
|||
Sub EmbLong() |
|||
Return ExecMem, Offset:=Number, Offset+1:=Number as Long |
|||
Offset+=5 |
|||
End Sub |
|||
Sub EmbByteLong() |
|||
Return ExecMem, Offset:=Number, Offset+1:=Number, Offset+2:=Number as Long |
|||
Offset+=6 |
|||
End Sub |
|||
} |
|||
Checkit |
|||
</lang> |
|||
=={{header|Pascal}}== |
=={{header|Pascal}}== |