Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.sys.apple2.programmer > #4742 > unrolled thread
| Started by | Jan Poulsen <jpo@tiggr.dk> |
|---|---|
| First post | 2018-09-05 15:07 +0200 |
| Last post | 2018-09-07 09:01 -0600 |
| Articles | 12 — 6 participants |
Back to article view | Back to comp.sys.apple2.programmer
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
| From | Jan Poulsen <jpo@tiggr.dk> |
|---|---|
| Date | 2018-09-05 15:07 +0200 |
| Subject | Efficient print of binary value |
| Message-ID | <pmokev$c9j$1@dont-email.me> |
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
[toc] | [next] | [standalone]
| From | Marco Verpelli <mverpelli@libero.it> |
|---|---|
| Date | 2018-09-05 07:23 -0700 |
| Message-ID | <045a4a1c-c5b5-4701-b4fb-e7cd8055cd31@googlegroups.com> |
| In reply to | #4742 |
; Merlin
COUT EQU $FDED
ORG $2000
LDA #%10000000
STA MASK
LAB1 LDA MASK
AND VALUE
BEQ LAB2
LDA #"1
HEX 2C
LAB2 LDA #"0
JSR COUT
LSR MASK
BNE LAB1
RTS
VALUE DS 1
MASK DS 1
waiting qkumba for a half-length version :)
Marco
[toc] | [prev] | [next] | [standalone]
| From | Jan Poulsen <jpo@tiggr.dk> |
|---|---|
| Date | 2018-09-05 17:05 +0200 |
| Message-ID | <pmoras$q2u$1@dont-email.me> |
| In reply to | #4743 |
On 05/09/2018 16.23, Marco Verpelli wrote: > ; Merlin > COUT EQU $FDED > > ORG $2000 > > LDA #%10000000 > STA MASK > > LAB1 LDA MASK > AND VALUE > BEQ LAB2 > LDA #"1 > HEX 2C > LAB2 LDA #"0 > JSR COUT > LSR MASK > BNE LAB1 > > RTS > > VALUE DS 1 > MASK DS 1 > > waiting qkumba for a half-length version :) > > Marco > Perfect. This is what I was aiming for, I just couldn't remember the BIT (HEX 2C) trick. Thanks! :-) -- -- Jan Poulsen
[toc] | [prev] | [next] | [standalone]
| From | Michael J. Mahon <mjmahon@aol.com> |
|---|---|
| Date | 2018-09-05 11:01 -0500 |
| Message-ID | <EuWdnZk5ntxaYBLGnZ2dnUU7-QHNnZ2d@giganews.com> |
| In reply to | #4744 |
Jan Poulsen <jpo@tiggr.dk> wrote: > On 05/09/2018 16.23, Marco Verpelli wrote: >> ; Merlin >> COUT EQU $FDED >> >> ORG $2000 >> >> LDA #%10000000 >> STA MASK >> >> LAB1 LDA MASK >> AND VALUE >> BEQ LAB2 >> LDA #"1 >> HEX 2C >> LAB2 LDA #"0 >> JSR COUT >> LSR MASK >> BNE LAB1 >> >> RTS >> >> VALUE DS 1 >> MASK DS 1 >> >> waiting qkumba for a half-length version :) >> >> Marco >> > > Perfect. This is what I was aiming for, I just couldn't remember the > BIT (HEX 2C) trick. Thanks! :-) > Well, if you don’t need the trick for space, BNE works just fine. ;-) -- -michael - NadaNet 3.1 and AppleCrate II: http://michaeljmahon.com
[toc] | [prev] | [next] | [standalone]
| From | qkumba <peter.ferrie@gmail.com> |
|---|---|
| Date | 2018-09-05 11:13 -0700 |
| Message-ID | <3e97b12c-8d58-43ea-b780-1ac58a313ac8@googlegroups.com> |
| In reply to | #4745 |
Not even close to half-length, but not branching:
LDA #%10000000
STA MASK
LAB1 LDA MASK
AND VALUE
CMP #1
LDA #"0
ADC #0
JSR COUT
LSR MASK
BNE LAB1
[toc] | [prev] | [next] | [standalone]
| From | Michael J. Mahon <mjmahon@aol.com> |
|---|---|
| Date | 2018-09-05 14:18 -0500 |
| Message-ID | <9vmdnS4CtNqdsQ3GnZ2dnUU7-Y3NnZ2d@giganews.com> |
| In reply to | #4746 |
qkumba <peter.ferrie@gmail.com> wrote: > Not even close to half-length, but not branching: > > LDA #%10000000 > STA MASK > > LAB1 LDA MASK > AND VALUE > CMP #1 > LDA #"0 > ADC #0 > JSR COUT > LSR MASK > BNE LAB1 > Woot! ;-) -- -michael - NadaNet 3.1 and AppleCrate II: http://michaeljmahon.com
[toc] | [prev] | [next] | [standalone]
| From | Marco Verpelli <mverpelli@libero.it> |
|---|---|
| Date | 2018-09-05 12:32 -0700 |
| Message-ID | <88265bde-7beb-4a85-ba2f-884fb3f9f434@googlegroups.com> |
| In reply to | #4746 |
On Wednesday, September 5, 2018 at 8:13:44 PM UTC+2, qkumba wrote: > Not even close to half-length, but not branching: > > LDA #%10000000 > STA MASK > > LAB1 LDA MASK > AND VALUE > CMP #1 > LDA #"0 > ADC #0 > JSR COUT > LSR MASK > BNE LAB1 After many (too many) years of EBCDIC I have learned not to assume that "1" comes after "0" Marco
[toc] | [prev] | [next] | [standalone]
| From | Michael J. Mahon <mjmahon@aol.com> |
|---|---|
| Date | 2018-09-05 22:21 -0500 |
| Message-ID | <HeydnY3Sp6PWAA3GnZ2dnUU7-bvNnZ2d@giganews.com> |
| In reply to | #4748 |
Marco Verpelli <mverpelli@libero.it> wrote: > On Wednesday, September 5, 2018 at 8:13:44 PM UTC+2, qkumba wrote: >> Not even close to half-length, but not branching: >> >> LDA #%10000000 >> STA MASK >> >> LAB1 LDA MASK >> AND VALUE >> CMP #1 >> LDA #"0 >> ADC #0 >> JSR COUT >> LSR MASK >> BNE LAB1 > > After many (too many) years of EBCDIC I have learned not to assume that "1" comes after "0" > > Marco > But the digits are consecutive in EBCDIC as well, and are in almost every computer encoding. -- -michael - NadaNet 3.1 and AppleCrate II: http://michaeljmahon.com
[toc] | [prev] | [next] | [standalone]
| From | awanderin <awanderin@gmail.com> |
|---|---|
| Date | 2018-09-05 23:53 -0600 |
| Message-ID | <yubftynrx1v.fsf@gmail.com> |
| In reply to | #4746 |
qkumba <peter.ferrie@gmail.com> writes:
> Not even close to half-length, but not branching:
>
> LDA #%10000000
> STA MASK
>
> LAB1 LDA MASK
> AND VALUE
> CMP #1
> LDA #"0
> ADC #0
> JSR COUT
> LSR MASK
> BNE LAB1
How about this?
sec ; force all 8 bits to print
lab1 rol value
beq :done
lda #$58 ; high-ascii "0" right-shifted one bit
rol ; now it's "0" or "1"
jsr cout
clc ; now shift in zeros until done
bcc lab1
:done
--
--
Jerry awanderin at gmail dot com
[toc] | [prev] | [next] | [standalone]
| From | Jan Poulsen <jpo@tiggr.dk> |
|---|---|
| Date | 2018-09-06 13:04 +0200 |
| Message-ID | <pmr1jb$ttu$1@dont-email.me> |
| In reply to | #4751 |
On 06/09/2018 07.53, awanderin wrote: > qkumba <peter.ferrie@gmail.com> writes: > >> Not even close to half-length, but not branching: >> >> LDA #%10000000 >> STA MASK >> >> LAB1 LDA MASK >> AND VALUE >> CMP #1 >> LDA #"0 >> ADC #0 >> JSR COUT >> LSR MASK >> BNE LAB1 > > > How about this? > > sec ; force all 8 bits to print > lab1 rol value > beq :done > lda #$58 ; high-ascii "0" right-shifted one bit > rol ; now it's "0" or "1" > jsr cout > clc ; now shift in zeros until done > bcc lab1 > :done > Very nice use of the carry bit in both these examples, and only 15 bytes for the last example :-) It's been 35 years since I last code 6502 assembler, and there is so much I have forgotten :-( So, thanks to everyone for all these great examples of what the 6502 can do with an experienced person behind the programming !! -- Jan Poulsen
[toc] | [prev] | [next] | [standalone]
| From | Michael Barry <barrym95838@yahoo.com> |
|---|---|
| Date | 2018-09-06 23:54 -0700 |
| Message-ID | <056fd503-9d49-4a25-b70a-bd77faadb46b@googlegroups.com> |
| In reply to | #4751 |
On Wednesday, September 5, 2018 at 10:53:49 PM UTC-7, awanderin wrote:
> How about this?
>
> sec ; force all 8 bits to print
> lab1 rol value
> beq :done
> lda #$58 ; high-ascii "0" right-shifted one bit
> rol ; now it's "0" or "1"
> jsr cout
> clc ; now shift in zeros until done
> bcc lab1
> :done
>
> --
> --
> Jerry awanderin at gmail dot com
I like it, Jerry! If we know we're always going to jsr to it, we
could shave one more byte like so, right?
lab1:
lda #$58 ; high-ascii "0" right-shifted one bit
rol ; now it's "0" or "1"
jsr cout
clc ; now shift in zeros until done
.db $b0 ; bcs op-code
prbin:
sec ; force all 8 bits to print
rol value
bne lab1
rts
[toc] | [prev] | [next] | [standalone]
| From | awanderin <awanderin@gmail.com> |
|---|---|
| Date | 2018-09-07 09:01 -0600 |
| Message-ID | <yubbm99s66n.fsf@gmail.com> |
| In reply to | #4757 |
Michael Barry <barrym95838@yahoo.com> writes: > On Wednesday, September 5, 2018 at 10:53:49 PM UTC-7, awanderin wrote: >> How about this? >> >> sec ; force all 8 bits to print >> lab1 rol value >> beq :done >> lda #$58 ; high-ascii "0" right-shifted one bit >> rol ; now it's "0" or "1" >> jsr cout >> clc ; now shift in zeros until done >> bcc lab1 >> :done >> >> -- >> -- >> Jerry awanderin at gmail dot com > > I like it, Jerry! If we know we're always going to jsr to it, we > could shave one more byte like so, right? > > lab1: > lda #$58 ; high-ascii "0" right-shifted one bit > rol ; now it's "0" or "1" > jsr cout > clc ; now shift in zeros until done > .db $b0 ; bcs op-code > prbin: > sec ; force all 8 bits to print > rol value > bne lab1 > rts Sure, that works. Nice! -- Jerry awanderin at gmail dot com
[toc] | [prev] | [standalone]
Back to top | Article view | comp.sys.apple2.programmer
csiph-web