
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


.model small                             ;specify memory model to use
.stack 1024                              ;set up stack
 
.data                                    ;data segment
 
UserRam BYTE 256 DUP (0)                 ;allocate 256 bytes of user RAM, initialized to zero.
 
tempByte equ UserRam                     ;define a few labels for clarity
tempWord equ UserRam+2
tempLong_LoWord equ UserRam+4
tempLong_HiWord equ UserRam+6          
 
.code                                    ;code segment
 
mov ax, @data
mov ds, ax                  
 
mov ax, @code
mov es, ax                               ;load segment registers with the appropriate segments.
 
; now there is no need to use "mov ax, seg UserRam" since we've already loaded the data segment into DS
 
 
;store an integer value into memory
 
mov ax, 1000h                            ;load the value 0x1000 into AX
mov word ptr [ds:tempLong_LoWord],ax     ;store 0x1000 into tempLong_LoWord
mov ax, 0040h                            ;the 8086 is 16-bit so we have to load the pieces separately.
mov word ptr [ds:tempLong_HiWord],ax     ;store 0x0040 into tempLong_HiWord
 
;get the address of a variable
mov ax, tempLong_LoWord                  ;without "word ptr" and brackets, the assembler interprets a label as a constant.