3

I'm learning assembly for the NES, and I have wrote this program:

    .org $8000 ; set code to start of rom
Start:         ; make a label called start
    lda #$ff   ; set acc to 0xff
    sta $0000  ; store address 0x0000 to acc which is 0xff
    jmp Start  ; jump to label start

I compile the program with NESASM3 it compiles successfully, then run it in my emulator, when I goto the memory viewer in the emulator, have a look at address $0000, it is 01, not FF, like I programed it to be.

Michael
  • 57,169
  • 9
  • 80
  • 125
TheRealSuicune
  • 369
  • 3
  • 10
  • 3
    Is that the full source code? Where are the iNES header directives (`.inesmap`, `.inesprg`, etc)? Are you sure that the code really is being executed (did you step through it in the emulator's debugger)? – Michael Feb 26 '19 at 12:27
  • 1
    Aside: `LDA #$ff` should assemble to the bytes `A9 FF` as `LDA #` has opcode `A9`. So you'd expect to see `A9` as your first byte, not `FF`, and since you've set `.org` to `$8000` you'd expect to see it at address `$8000`, not at zero. Otherwise, see Michael's answer re: setting up the NMI, start and IRQ vectors so that the 6502 knows where to begin execution from, as well as the NES-specific fields necessary to guarantee a certain memory arrangement. – Tommy Feb 27 '19 at 14:51

1 Answers1

7

Your code is missing a bunch of information that's necessary for the emulator to know what kind of ROM this is, and for the NES to know where it should start executing.

A working example could look something like this (tested in FCEU):

   ; ROM header
   .inesprg    2        ; Two 16k PRG-ROM banks
   .ineschr    1        ; One 8k CHR-ROM bank
   .inesmir    1        ; Vertical mirroring
   .inesmap    0        ; Mapper 0 (none)

   .bank 0
   .org $8000 ; set code to start of rom
Start:         ; make a label called start
    lda #$ff   ; set acc to 0xff
    sta $0000  ; store address 0x0000 to acc which is 0xff
    jmp Start  ; jump to label start

; Dummy interrupt handlers 
nmi: 
irq:
    rti

; Specify reset and interrupt vectors

    .bank 3       ; The .bank directive uses 8kB granularity, so bank 3
                  ; is final 8kB chunk of our 32kB PRG-ROM.
 .org  $fffa
    .dw   nmi
    .dw   Start
    .dw   irq   
Michael
  • 57,169
  • 9
  • 80
  • 125