define StringRam $1200 ;not actually used in the code, but it's here for clarity. define z_BC $00 ;fake Z80-style register for pseudo-16-bit operations. define z_C $00 ;6502 uses the low byte as the reference point for indirect lookups. define z_B $01 ;high byte define tempMath $02 ;temp storage of input define tempBitMask $03 ;temp storage of the bit filter lda #$12 sta z_B lda #$00 sta z_C ;load address $1200 into zero page memory for an indirect lookup. lda #$0F ;test value LDY #0 ;initialize offset to zero jsr Hex2BinAscii brk ;on easy6502 this terminates the program. Hex2BinAscii: sta tempMath ;store our input, in this case #$0F lda #%10000000 sta tempBitMask loop_Hex2BinAscii: lda tempMath ;load input into accumulator. and tempBitMask ;filter out all bits except the one we are checking this pass of the loop bne bitIsOne lda #$30 ;ascii for zero bne StoreBit bitIsOne: lda #$31 ;ascii for one StoreBit: sta (z_BC),y ;store in StringRam+Y loopOverhead: iny ;y++ lsr tempBitMask ;shift to next bit in sequence beq loop_Hex2BinAscii ;if mask is zero, we are done. BCC would have worked here as well. lda #$00 ;load the null terminator sta (z_BC),y ;store the null terminator after the string rts