
Basic Data Operation

This is a basic data operation. It represents a fundamental action on a basic data type.
You may see other such operations in the Basic Data Operations category, or:


Integer Operations
Arithmetic |
Comparison
Boolean Operations
Bitwise |
Logical
String Operations
Concatenation |
Interpolation |
Comparison |
Matching
Memory Operations
Pointers & references |
Addresses




In systems programing it is sometimes required to place language objects at specific memory locations, like I/O registers, hardware interrupt vectors etc.



Task

Show how language objects can be allocated at a specific machine addresses.

Since most OSes prohibit access to the physical memory if it is not mapped by the application, as an example, rather than a physical address, take the address of some existing object (using suitable address operations if necessary).



For example:

   create an integer object
   print the machine address of the object
   take the address of the object and create another integer object at this address
   print the value of this object to verify that it is same as one of the origin
   change the value of the origin and verify it again


 
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
 