First off: sorry if this is a dupe! I have searched a bit and have not found a resource which satisfactorily explains this.
n00bish question here!
I am trying to understand what the .byte
directive does. Different sources say different things, the gist of which is something like :
.db, DB, .byte, etc. lay down the exact bytes you specify, as data and not as instructions (http://forum.6502.org/viewtopic.php?f=2&t=2374)
The cc65 manual gives a similarly vague:
.byte: Define byte sized data. Must be followed by a sequence of (byte ranged) expressions or strings.
Example:
.byte "Hello " .byt "world", $0D, $00
I don't know what that means. I thought that all operations related to defining data were variations on reading and writing memory addresses. So something like this (from a tut on NES development)
; Number of PRG-ROM blocks
.byte $01
; Number of CHR-ROM blocks
.byte $01
; ROM control bytes: Horizontal mirroring, no SRAM
; or trainer, Mapper #0
.byte $00, $00
What is it doing exactly? Can it all be explained in terms of opcodes, or is it doing something fancier? To me, it looks like it is maybe writing sequential data, starting from the zero page, something like this??:
LDA #$01
STA $00
LDA #$01
STA $01
LDA #$00
STA $02
LDA #$00
STA $03
Am I way off here? I have been reading 6502 Software Design by Leo Scanlon and I have seen no reference to that ( or any ) directive. I am learning 6502 for the purpose of NES development and all example code is riddled with .byte
, .ascii
, and several other directives. I really wanted to try and get a solid foundation in 6502 from an academic text like the Scanlon book before trying to navigate the world of user-contributed NES tutorials, but this is becoming a road block to my understanding of NES 6502.
LDA #1
is the same as.byte $A9, $01
. – Raymond Chen.byte
directives. That's what an assembler does. it takes opcodes and converts them into bytes. – Raymond Chen