The .byte directive places one or more literal byte values into assembled program data. It is useful for fixed NES data such as palettes and screen text stored in the RODATA segment. section 5.8
Use .byte in several practical forms:
- Write hexadecimal values separated by commas, such as .byte $0F,$15,$26,$37, to define palette entries. section 5.8
- Write characters or quoted text, such as .byte 'W','E','L','C','O','M','E',0, to create a sequence of individual bytes. section 5.8 section 6.7
- Append a zero byte when a routine needs an explicit end marker for text. section 6.7
Palette and welcome text
Place fixed data in RODATA, then label it so game code can refer to it: .byte $0F,$15,$26,$37 defines four palette bytes, while .byte 'W','E','L','C','O','M','E',0 defines text ending in zero. section 5.8
Listing 5.8 RODATA code segment (example.s)
;***************************************************************** ; Our default palette table has 16 entries for tiles ; and 16 entries for sprites ;***************************************************************** .segment "RODATA" default_palette: .byte $0F,$15,$26,$37 #1 .byte $0F,$09,$19,$29 #2 .byte $0F,$01,$11,$21 #3 .byte $0F,$00,$10,$30 #4 .byte $0F,$18,$28,$38 #5 .byte $0F,$14,$24,$34 #6 .byte $0F,$1B,$2B,$3B #7 .byte $0F,$12,$22,$32 #8 welcome_txt: .byte 'W','E','L','C', 'O', 'M', 'E', 0
Inspect the complete RODATA listing showing eight palette rows and a zero-terminated welcome message. section 5.8
