Create an object at a given address: Difference between revisions
Create an object at a given address (view source)
Revision as of 03:05, 14 November 2021
, 2 years ago→{{header|Z80 Assembly}}: formatting of code blocks
Puppydrum64 (talk | contribs) |
Puppydrum64 (talk | contribs) m (→{{header|Z80 Assembly}}: formatting of code blocks) |
||
Line 1,114:
Loading a value into a register from memory only loads a copy; the original value at that memory location isn't altered, nor is the memory location of that value. Assume this code is executed immediately after the above example:
<lang z80>LD HL,(&C000) ;load &FFFF into HL
LD BC,(&C000) ;load &FFFF into BC.</lang>
In order to change a value at a memory location, it either needs to be loaded into a register and stored back after altering that register in some way, or by using certain indirect addressing modes, like so:
▲ld hl,&C000 ;get the address of our variable.
▲inc (hl) ;increment the low byte.
▲ld hl,(&C000) ;load &FF00 into HL.</lang>
If you're not familiar with the Z80's syntax, this can be a bit confusing. The brackets are like the dereference operator in C, and not having brackets is like the unary <code>&</code> operator in C. The Z80's ability to do 16-bit operations is limited; it can load from two consecutive memory locations into a 16-bit register pair, however when using <code>(hl)</code> as an operand it is only operating on the lower 8 bits. When learning Z80 Assembly, it is very helpful to view a hex editor while learning the instruction set.
|