Count in octal: Difference between revisions

m
Line 153:
 
INY
CPY #$40
CPY #$40 ;alternatively you can store a size variable and check that here instead.
BCC loop
BRK
 
foo:
sta temp ;store input temporarily
sta temp
asl ;bit shift, this places the top bit of the right nibble in the bottom of the left nibble.
asl
pha ;back this value up
pha
lda temp
and #$07 ;take the original input and remove everything except the bottom 3 bits.
and #$07
sta temp ;store it for later. What used to be stored here is no longer needed.
sta temp
pla ;get the pushed value back.
pla
and #$F0 ;clear the bottom 4 bits.
and #$F0
ora temp ;put the bottom 3 bits of the original input back.
ora temp
and #$7F ;clear bit 7.
rts</lang>
 
1,489

edits