Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.sys.apple2.programmer > #4742
| From | Jan Poulsen <jpo@tiggr.dk> |
|---|---|
| Newsgroups | comp.sys.apple2.programmer |
| Subject | Efficient print of binary value |
| Date | 2018-09-05 15:07 +0200 |
| Organization | A noiseless patient Spider |
| Message-ID | <pmokev$c9j$1@dont-email.me> (permalink) |
Hi all, As part of debugging and trying to understand how some code is working, I have a need of printing bytes in binary format. I've googled around to see if anyone had already come up with something, but there doesn't seem to have been a need for printing binary values. So, I've written the code below, but hope someone has a smarter/faster way of doing it. The value to be printed in binary should be in the accumulator before calling the routine. PRHEX .EQ $FDE3 RESTOR .EQ $FF3F SAVE .EQ $FF4A PRBIN JSR SAVE ; save registers and processor status LDY #8 ; 8 bits to process .1 ASL ; drop high bit in carry and 0 in low bit TAX ; save A for next iteration ROL ; move carry to low bit AND #1 ; mask out all but the low bit JSR PRHEX ; print lower nibble of A (high bit) TXA ; restore A DEY ; decrease counter BNE .1 ; more bits to print? JMP RESTOR ; restore regs & status As this is used for debugging I'm saving the state of the machine before doing anything else, and restoring it upon exit. I could probably get away with the following code to save a few cycles instead of calling SAVE and RESTORE as I am not using X and Y in the code I am trying to understand. PHP PHA ... PLA PLP Any ideas for more efficient code or code that only uses A so I don't have to save X and Y for other types of debugging, will be much appreciated. -- Jan Poulsen
Back to comp.sys.apple2.programmer | Previous | Next — Next in thread | Find similar | Unroll thread
Efficient print of binary value Jan Poulsen <jpo@tiggr.dk> - 2018-09-05 15:07 +0200
Re: Efficient print of binary value Marco Verpelli <mverpelli@libero.it> - 2018-09-05 07:23 -0700
Re: Efficient print of binary value Jan Poulsen <jpo@tiggr.dk> - 2018-09-05 17:05 +0200
Re: Efficient print of binary value Michael J. Mahon <mjmahon@aol.com> - 2018-09-05 11:01 -0500
Re: Efficient print of binary value qkumba <peter.ferrie@gmail.com> - 2018-09-05 11:13 -0700
Re: Efficient print of binary value Michael J. Mahon <mjmahon@aol.com> - 2018-09-05 14:18 -0500
Re: Efficient print of binary value Marco Verpelli <mverpelli@libero.it> - 2018-09-05 12:32 -0700
Re: Efficient print of binary value Michael J. Mahon <mjmahon@aol.com> - 2018-09-05 22:21 -0500
Re: Efficient print of binary value awanderin <awanderin@gmail.com> - 2018-09-05 23:53 -0600
Re: Efficient print of binary value Jan Poulsen <jpo@tiggr.dk> - 2018-09-06 13:04 +0200
Re: Efficient print of binary value Michael Barry <barrym95838@yahoo.com> - 2018-09-06 23:54 -0700
Re: Efficient print of binary value awanderin <awanderin@gmail.com> - 2018-09-07 09:01 -0600
csiph-web