Create an object at a given address: Difference between revisions

no edit summary
No edit summary
Line 9:
Since most [[OS]]es 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|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.
 
 
=={{Header|6502 Assembly}}==
In [[6502 Assembly]] memory is represented by either an 8-bit or a 16-bit address (i.e. $0000 - $FFFF). 8-bit address are reserved for the memory from $00 to $FF - known as zero page; access to this memory takes one less byte in the opcode and one less cycle to execute.
 
Data can be stored, one byte at a time, through the store instructions, for example to store data at $1900:
<lang 6502asm> sta $1900
stx $1901
sty $1902</lang>
 
Storage can be indexed through the use of the X or Y registers:
<lang 6502asm> ldx #54
.loop sta $1900,X
dex
bne loop</lang>
 
It can also be stored via indirect indexed addressing (i.e. memory points to an address), using the Y register:
<lang 6502asm> lda #0
sta $70
lda #$20
sta $71
ldy #0
sta ($70),Y</lang>
 
Finally, it can be stored via indexed indirect addressing (i.e. read the address of memory from the table stored at the parameter), using the X register:
<lang 6502asm> lda #0
sta $70
lda #$20
sta $71
ldx #0
sta ($70,X)</lang>
 
It should be noted that on the 6502 processor hardware is normally memory mapped, so this is often used for manipulating hardware.
 
=={{Header|Ada}}==
Anonymous user