Advertisement
tepples

6502 golf: Parity calculation

Nov 28th, 2014
408
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ; 6502 parity calculation by Damian Yerrick
  2. ; licensed under creative commons zero
  3. .proc parity_by_adding
  4. bytetosend = 0
  5.   lda bytetosend
  6.   lsr a
  7.   eor bytetosend
  8.   ; diverge starts here
  9.   and #%01010101  ; ,6.4.2.0
  10.   ; Possible nibbles: 0, 1, 4, or 5.
  11.   ; If we add 3, we get 3, 4, 7, or 8, whose bit 2
  12.   ; is the nibble's parity.
  13.   clc
  14.   adc #%00110011  ; combine 0 into 2 and 4 into 6
  15.   and #%01000100  ; .6...2..
  16.   ; now possible bytes are $00, $04, $40, or $44
  17.   adc #%00111100  ; combine bit 2 into bit 6
  18.   and #%01000000
  19.   ; At this point, bit 6 is parity and bit 7 is 1.
  20.   ; Therefore we can AND #%01000000 if we want to BNE,
  21.   ; ASL A if we want to BMI, or if we want to BCS:
  22.   cmp #1
  23.   ; 18 bytes 22 cycles so far
  24.   rts
  25. .endproc
  26.  
  27. ; 6502 parity calculation by Kevin Horton
  28. ; from http://pastebin.com/eRibRP6G
  29. .proc parity_by_shifting
  30. bytetosend = 0
  31.   lda bytetosend
  32.   lsr a
  33.   eor bytetosend
  34.   sta bytetosend
  35.   lsr a
  36.   lsr a
  37.   eor bytetosend
  38.   sta bytetosend
  39.   lsr a
  40.   lsr a
  41.   lsr a
  42.   lsr a
  43.   eor bytetosend
  44.   lsr a
  45.   ; 20 bytes 34 cycles so far
  46.   rts
  47. .endproc
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement