I figured one of y’all would just know seeing how ubiquitous the 6502 is. I’m not following any tutorial at the moment and it has been too long since I last mucked around in assembly. I have the programming manual but it is convoluted between the 6502 and 65C816 stuff.

I’m messing with the little Easy 6502 emulator (Flatpak/FlatHub). I want to nest a couple of loops. I should probably just use the stack, but I went down this rabbit hole and damn it I want to find the rabbit!

I want something like (crude):

define lineL $1000
define lineH $1001

LDA $00
STA $lineL
LDA $02
STA $lineH

Hopefully I have that endian right… So now I have a 2 byte word starting at address 0×1000 and loaded with 0x0200. I want to increment this value as a 16 bit variable up to 0x05FF. What I am struggling with is which addressing mode indexes like this or if this must be manually implemented (– which does not seem right to me).

I’ll figure it out on my own in the next couple of hours regardless. It is more fun to chat and see the spectrum of knowledge here, or maybe not, either way, ya don’t know if ya don’t try. Skool me Woz

  • FigMcLargeHuge@sh.itjust.works
    link
    fedilink
    English
    arrow-up
    7
    ·
    edit-2
    5 days ago

    It has been a while for me, but I think you are going to have to do this all manually. The 6502 is 8bit and you can’t load a 16bit word into the accumulator. Load A $lineL, increment A, store A, then compare it to 0 and beq a routine to increment $lineH, and then also compare that to your ending number. If you are wanting to end in 0x05FF you might also have to put in a compare when $lineL gets to 05 to see if $lineH is FF. I would have to find my atari books, or do some googling.

    Edit: see my reply.

    • FigMcLargeHuge@sh.itjust.works
      link
      fedilink
      English
      arrow-up
      3
      ·
      5 days ago

      Just going to reply to myself here. I think I am completely wrong on my original reply. You should use ADC. If the byte overflows the carry bit will be set, and then you can test with BCC or BCS.

      http://www.6502.org/users/obelisk/6502/reference.html#ADC

      "ADC - Add with Carry

      This instruction adds the contents of a memory location to the accumulator together with the carry bit. If overflow occurs the carry bit is set, this enables multiple byte addition to be performed."

        • FigMcLargeHuge@sh.itjust.works
          link
          fedilink
          English
          arrow-up
          4
          ·
          5 days ago

          I was thinking about it, and since you want to count to 05FF, it might be better to load 05FF into the two bytes and use SBC and count down until you hit 0000. Then the 05 isn’t causing more code to test for.