News: 11 March 2016 - Forum Rules

Author Topic: Branching out of range.  (Read 4309 times)

Pikachumanson

  • Hero Member
  • *****
  • Posts: 607
    • View Profile
Branching out of range.
« on: November 29, 2012, 10:16:04 am »
Ok, all I want to do this subroutine into the an nes rom using ASM6.
It's KingMike's Y's 3 DTE code. But... when I run it through the assembler by itself I get branch out of range errors on lines 3, 7, 13 and 27. I know it won't work with my rom and and that's ok because I am just experimenting trying to learn how things work in 6502. I'll do the necessary changes later when I got the actual data into the rom. So basically what I did was take a blank asm file put the the routine below into it and got these error. I'd like to know what exactly am I doing wrong and how I should go about fixing it. Then, I'd like to know once I do get it to assemble into a bin how would go about putting this data into the rom? Do I need to put the offsets when I am doing the patching(I think...) process? Also when I disassemble code do I need to get rid of the offsets so I won't get any invalid opcode errors or is it cool to just leave them there. I'm sorry guys, I know I ask a lot of questions but, I'm trying really hard to get this assembly stuff down pat and it's frustrating because I feel like I can't even get my foot in the door with this stuff. Well maybe I did, because I did assemble my first 6502 program last night but that's not rom related it was just adding addresses together.

Code: [Select]
LDA $CF
CMP #$00
BNE $1F
LDY #$00
LDA ($9B),Y
CMP #$14
BPL $03
LDA ($9B),Y
RTS

LDA ($9B),Y
CMP #$7F
BPL $F7
INC $CF
LDA ($9B),Y
SEC
SBC #$15
ASL A
TAX
LDA $9700,X
RTS

DEC $CF
DEC $9B
LDA $9B
CMP #$FF
BNE $02
DEC $9C
LDY #$00
LDA ($9B),Y
SEC
SBC #$15
ASL A
TAX
LDA $9701,X
RTS

KingMike

  • Forum Moderator
  • Hero Member
  • *****
  • Posts: 7313
  • *sigh* A changed avatar. Big deal.
    • View Profile
Re: Branching out of range.
« Reply #1 on: November 29, 2012, 12:40:28 pm »
Tried making labels for the lines you're trying to branch to?
Code: [Select]
Label:
...
bne Label
Or maybe the assembler expects it as an immediate value (#$F7 instead of $F7).
"My watch says 30 chickens" Google, 2018

Pikachumanson

  • Hero Member
  • *****
  • Posts: 607
    • View Profile
Re: Branching out of range.
« Reply #2 on: November 29, 2012, 01:25:29 pm »
Labels are like variable names in C right? Anyway i tried both methods and still got errors. With the labels I get to tge 1st pass and now the first three lines of code are illegal instructions

snarfblam

  • Submission Reviewer
  • Hero Member
  • *****
  • Posts: 595
  • CANT HACK METROID
    • View Profile
    • snarfblam
Re: Branching out of range.
« Reply #3 on: November 29, 2012, 05:49:25 pm »
Maybe you should post the new code. Otherwise it's kinda hard to debug. As far as branching goes, you absolutely want to use labels. Some assemblers might accept a relative offset as a literal operand, but that's rarely useful. Nobody likes manually recalculating all his branches when he inserts an instruction.

Pikachumanson

  • Hero Member
  • *****
  • Posts: 607
    • View Profile
Re: Branching out of range.
« Reply #4 on: December 01, 2012, 02:43:15 pm »
I am using ASM6 and I am using the easy 6502 website to learn along with a book written Rodney Zachs i dled from here. What syntax do I use for labels so it would be acceptable to be compiled by ASM6?