Jump to content



0

Question about 'plp' and 'php'


10 replies to this topic

#1 vdub_bobby OFFLINE  

vdub_bobby

    Quadrunner

  • 5,831 posts
  • Boom bam.
  • Location:Seattle, WA

Posted Thu Jan 13, 2005 2:18 PM

What, exactly, do php and plp do?

Would this code...
php

pla

sta ZP
Put the entire processor status register in a zero-page memory location?

And would this...
lda ZP

pha

plp
Set the processor status register to whatever was in the zero-page memory location?

#2 Robert M OFFLINE  

Robert M

    Stargunner

  • 1,481 posts
  • Rootbeer!
  • Location:Western NY state

Posted Thu Jan 13, 2005 3:30 PM

Yes, you are correct in both cases.

#3 Thomas Jentzsch OFFLINE  

Thomas Jentzsch

    Thrust, Jammed, SWOOPS!

  • 16,745 posts
  • Always left from right here!
  • Location:Düsseldorf, Germany

Posted Thu Jan 13, 2005 3:32 PM

Almost, but the zero-flag will be always set after PLA.

But you can do this:
ldx #ZP

txs

...

php

and later:
ldx #ZP   

txs    ; optional

plp


#4 Thomas Jentzsch OFFLINE  

Thomas Jentzsch

    Thrust, Jammed, SWOOPS!

  • 16,745 posts
  • Always left from right here!
  • Location:Düsseldorf, Germany

Posted Thu Jan 13, 2005 3:35 PM

Correction: the Z-flag will be never set.

#5 vdub_bobby OFFLINE  

vdub_bobby

    Quadrunner

  • 5,831 posts
  • Boom bam.
  • Location:Seattle, WA

Posted Thu Jan 13, 2005 3:57 PM

Thomas Jentzsch said:

Almost, but the zero-flag will be always set after PLA.

But you can do this:
ldx #ZP

txs

...

php

and later:
ldx #ZP   

txs    ; optional

plp

That makes sense...I think.

Are you saying that after this:
php

pla

sta ZP

The processor status register stored in ZP may or may not match the actual processor status register because the 'pla' modifies the processor status register?

Is that because 'pla' sets the zero-flag based on what value is pulled into A? (Does 'pla' also modify the sign flag?) And the processor status register will never be zero?

But what if you did this...
lda #0

pha

plp

php

pla

Wouldn't the zero flag then be...um...set? I think?

#6 Thomas Jentzsch OFFLINE  

Thomas Jentzsch

    Thrust, Jammed, SWOOPS!

  • 16,745 posts
  • Always left from right here!
  • Location:Düsseldorf, Germany

Posted Thu Jan 13, 2005 4:16 PM

vdub_bobby said:

Is that because 'pla' sets the zero-flag based on what value is pulled into A?  (Does 'pla' also modify the sign flag?)  And the processor status register will never be zero?
Even if it might be zero, then the zero-flag wasn't set before and the result is wrong again.

There is no problem with the sign-flag, because it is stored in bit7, which sets the flag when the flag was set before. :)

Quote

But what if you did this...
lda #0

pha

plp

php

pla

Wouldn't the zero flag then be...um...set?  I think?
Hm, according to my tests with z26, the result is $30. So the unused flag in bit5 is always set, and the break flag (bit4) seems to be set too.

Therefore the answer is no.

#7 vdub_bobby OFFLINE  

vdub_bobby

    Quadrunner

  • 5,831 posts
  • Boom bam.
  • Location:Seattle, WA

Posted Thu Jan 13, 2005 4:21 PM

Thanks.

#8 Nukey Shay ONLINE  

Nukey Shay

    Sheik Yerbouti

  • 20,458 posts
  • Location:The land of Gorch

Posted Thu Jan 13, 2005 8:32 PM

Why would you want to store the processor status in a zero page location? It would be better to just php, and plp later when you need it (or reorganize the routine so that it's not needed at all).

Have an example of what you are attempting?

#9 Bruce Tomlin OFFLINE  

Bruce Tomlin

    River Patroller

  • 3,531 posts
  • CD C9 01
  • Location:Austin, TX

Posted Thu Jan 13, 2005 11:21 PM

Thomas Jentzsch said:

Correction: the Z-flag will be never set.
For those who don't do Zen, this is because one of the bits of the P register is always set to 1. PLA sets the Z and N flags based on what value is read into A. Since this value is never zero, the Z flag will never be set after this particular code.

(The B flag should be set too, as it's only pushed as 0 in response to an interrupt.)

#10 vdub_bobby OFFLINE  

vdub_bobby

    Quadrunner

  • 5,831 posts
  • Boom bam.
  • Location:Seattle, WA

Posted Fri Jan 14, 2005 11:57 AM

Nukey Shay said:

Why would you want to store the processor status in a zero page location?  It would be better to just php, and plp later when you need it (or reorganize the routine so that it's not needed at all).

Have an example of what you are attempting?

Not attempting anything...I haven't even thought of a situation where I might need to do this. Just curious, that's all :)

Bruce Tomlin said:

(The B flag should be set too, as it's only pushed as 0 in response to an interrupt.)

Thomas Jentzsch said:

Hm, according to my tests with z26, the result is $30. So the unused flag in bit5 is always set, and the break flag (bit4) seems to be set too.
This is what I don't understand. So you can't manually clear the break flag (with a plp)?

#11 Bruce Tomlin OFFLINE  

Bruce Tomlin

    River Patroller

  • 3,531 posts
  • CD C9 01
  • Location:Austin, TX

Posted Fri Jan 14, 2005 5:08 PM

The B flag in the P register is meaningless. Only the stacked value of the P register matters. Whenever it is written to the stack, the value written is entirely dependent upon whether a BRK instruction was executed or not. In fact, there might not even actually be a B flag in the P register itself.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users