6502 Assembly language

Discussion in 'Mac Programming' started by Ardvaark, May 11, 2009.

  1. Ardvaark macrumors newbie

    May 11, 2009
  2. iSee macrumors 68040


    Oct 25, 2004
    Wow, this is a weird question.
    Well, I found an online 6502 disassembler and pasted your opcode in to get this result:
                      * = 0300
    0300   A0 00      LDY #$00
    0302   B9 11 03   LDA $0311,Y
    0305   F0 09      BEQ $0310
    0307   20 ED FD   JSR $FDED
    030A   C8         INY
    030B   E8         INX
    030C   C8         INY
    030D   4C 02 03   JMP $0302
    0310   60         RTS
    0311   B3         ???
    0312   B8         CLV
    0313   B2         ???
    0314   B3         ???
    0315   B0 CA      BCS $02E1
    0317   CE D3 D7   DEC $D7D3
    031A   B2         ???
    031B   B6 B5      LDX $B5,Y
    031D   B9 B9 B4   LDA $B4B9,Y
    0320   AE C0 B6   LDX $B6C0
    0323   B9 B0 B9   LDA $B9B0,Y
    0326   B2         ???
    0327   B1 B6      LDA ($B6),Y
    0329   B4 B2      LDY $B2,X
    032B   B3         ???
    032C   AC AE B9   LDY $B9AE
    032F   B1 B1      LDA ($B1),Y
    0331   B9 B1 B5   LDA $B5B1,Y
    0334   B4 B2      LDY $B2,X
    0336   B2         ???
    0337   D1 D7      CMP ($D7),Y
    0339   C5 D3      CMP $D3
    033B   B0 B1      BCS $02EE
    033D   B4 B0      LDY $B0,X
    033F   B0 B8      BCS $02F9
    0341   AE AE B5   LDX $B5AE
    0344   B1 B3      LDA ($B3),Y
    0346   B4 B7      LDY $B7,X
    0348   B6 B5      LDX $B5,Y
    034A   B3         ???
    034B   B0 B9      BCS $0306
    034D   AC B2 B3   LDY $B3B2
    0350   C2         ???
    0351   D3         ???
    0352   C4 C1      CPY $C1
    0354   D7         ???
    0355   C5 C3      CMP $C3
    0357   C2         ???
    0358   D6 CB      DEC $CB,X
    035A   CC CC A0   CPY $A0CC
    035D   B4 CE      LDY $CE,X
    035F   D0 C1      BNE $0322
    0361   D2         ???
    0362   C1 D5      CMP ($D5,X)
    0364   D9 D4 C3   CMP $C3D4,Y
    0367   C6 C9      DEC $C9
    0369   AC B9 CF   LDY $CFB9
    036C   00         BRK
    036D   00         BRK
    036E   00         BRK
    036F   00         BRK
    0370              .END
    So, from very rusty memory:

    0300 A0 00 LDY #$00 --> loads the Y register (8 bits) with 0
    0302 B9 11 03 LDA $0311,Y --> load the accumulator (8 bits) with the byte at address (0311 + Y). Since Y is zero right now, it loads the accumulator with the value B3.

    0305 F0 09 BEQ $0310 --> if the acculator is zero, jump to address 0310. 0310 just has an RTS opcode, which is "return".
    0307 20 ED FD JSR $FDED --> This is calling a routine at FDED. I don't know what it does. Let's say it outputs the value of the accumulator???

    030A C8 INY --> increment Y register
    030B E8 INX --> increment X register !!! not previously used !!!
    030C C8 INY --> increment Y register
    030D 4C 02 03 JMP $0302 --> jump to 302

    So this is a loop that processes every other byte starting at address 0311. It terminates when a zero is encountered.

    I guess the "bug" in the program is that 030B should be another INY (INX doesn't make any sense since the x register is not used elsewhere, though it's a complete guess on my part that it is supposed to be another INY). So maybe this is supposed to process every third byte.

    Edit: Oh, actually, that's what the puzzle says -- replace the INX (increment X) with INY (increment Y) So it does process every third byte starting at address 0311
  3. Ardvaark thread starter macrumors newbie

    May 11, 2009
    Hmmmm. I still don't get what I am supposed to do with this. Is there a way to run the corrected program (without having the original oldie Apple computer??
  4. MisterMe macrumors G4


    Jul 17, 2002
    Well, you could try an emulator.
  5. Ardvaark thread starter macrumors newbie

    May 11, 2009
    Thanks all! I used the corrected code and I emulated and got the answer I needed!!!!!! You rock!!!!

Share This Page