Enforced immutability: Difference between revisions
Content added Content deleted
Puppydrum64 (talk | contribs) |
Puppydrum64 (talk | contribs) (→{{header|6502 Assembly}}: revised entry) |
||
Line 11: | Line 11: | ||
=={{header|6502 Assembly}}== |
=={{header|6502 Assembly}}== |
||
{{trans|Z80 Assembly}} |
|||
Most assemblers allow you to define labels which can refer to constant values for clarity. |
|||
The 6502 has no hardware means of write-protecting areas of memory. Code and/or data are only immutable if they exist in ROM. Typically, a program run from floppy disk or CD-ROM is copied to the hardware's RAM and executed from there, while ROM cartridges (such as those on the NES) are often mapped directly into the 6502's address space and executed as ROM. |
|||
⚫ | |||
bit6 equ %01000000 |
|||
⚫ | |||
lda #$FF |
|||
byte $01,$02,$03,$04,$05</lang> |
|||
AND #bit7 |
|||
;accumulator contains #$80</lang> |
|||
Labeled constants are also immutable, as the assembler replaces them with their equivalent values during the assembly process. The 6502 isn't aware those labels ever existed. |
|||
When the program is being assembled, the assembler dereferences the labels and replaces them in-line with the labeled constants. They cannot be altered at runtime (except with self-modifying code). |
|||
<lang 6502asm>bit_7 equ $80 ;every instance of "bit_7" in your source code is swapped with hexadecimal 80 during assembly</lang> |
|||
=={{header|68000 Assembly}}== |
=={{header|68000 Assembly}}== |