[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Stack Pointer Problem on 65816



On Sun, 15 Jun 2003 19:33:31 +0000, Bryan Parkoff wrote:

> I use processor status register to convert into base 2 binary.
> Here is my sample code.

<sample code snipped>

> After reviewing my code, I suspect that Stack is not in
> proper balance.

I suspect you're right.
On top of that your code seems to do a lot of unnecessary work.
I wrote a new version for you. Try comparing it with your code.

> Please make any corrections for me.  Thanks...

  lda #$c1    ;I assume this is just a sample byte for testing
  php
  ldy #7      ;going to print 7+1 = 8 characters
c pla         ;retrieve old P from stack
  asl         ;shift out the high bit
  pha         ;put the shifted P back on stack
  bcc a       ;if high bit is 0, go load a '0' into A
  lda #$b1    ; otherwise load a '1' into A
  bne b
a lda #$b0    ;load a '0' into A
b jsr $fded   ;print the '0' or '1'
  dey         ;count how many bits have been printed
  bpl c       ;if < 8, do another
  pla         ;remove fully shifted P from stack; important!!!
  rts

-Sheldon