26
dudeking
13d

Writing clean and efficient code 101 presented by yours truly, dudeking

Comments
  • 5
    This deserves waaay more likes.
  • 0
    Your code is correct if you're saving CPU cycles, yes... BUT!

    To save space:

    setup-lsr:
    txs
    ldx #$07
    loop-lsr:
    lsr a
    dex
    cpx #$00
    bne loop-lsr
    continue:
    tsx
    eor #%00000001
    sta $0201
    setup-rol:
    txs
    ldx #$07
    loop-rol:
    rol a
    cpx #$00
    bne loop-rol
    end:
    tsx
    ; continue doing whatever

    (this was thrown together after only a cursory glance at 6502 docs, there's probably an even better way of doing it, but you get the point.)

    i'm gonna be so mad if the original post was a joke

    edit: fun fact: this may have been a huge waste of time as it might be exactly the same length space-wise, i'm not sure though as a lot of opcodes don't have a listed length -_-
  • 3
    @Parzi original post wasnt a joke. Also, as you mentioned it's both slower and takes up the same amount of space. Via rough calculation I found it takes like twice the number of cycles (80 on mine and 190 on yours) to complete yours. Also your code is about the same size. It's not gonna work.
  • 1
    @dudeking i'm used to the GBx's modified Z80 processor, and timings are a lot more... *forgiving* on there. (Plus we don't have 3-byte opcodes except like 5 or 6 exceptions lol)
  • 1
    One word: nostalgia....
  • 1
    Disliked, not enough LOCK CMPXCHG16B
  • 1
    @12bitfloat it's 6502 Assembly, there is no lock command
  • 2
    @dudeking Not with that attitude
  • 3
Your Job Suck?
Get a Better Job
Add Comment