[Coco] Pop PC with empty stack?

Phill Harvey-Smith afra at aurigae.demon.co.uk
Tue Apr 6 02:35:23 EDT 2010


Lothan wrote:
> I'm hoping someone can help refresh my memory on the internals of
> OS-9. Specifically, I'm seeing this code:
> 
> PSHS Y ... 
 > PSHS X ...
 > More code here :)
 > PULS X
 > PULS Y,PC
> 
> That it's popping X and Y from the stack makes perfect sense because
> those two registers were pushed onto the stack previously. At this
> point the stack should be empty, so what happens when it attempts to
> pop PC from the stack? Is this effectively the same as OS9 F$Exit?

Asuming that your routine was entered with JSR or (L)BSR, then before 
your routine is entered the return address is pushed onto the stack. So 
pulling the PC at the end is the same as doing an rts at the end of the 
routine. However since with the 6809, multiple registers can be 
pushed/popped in one instruction, then using the PULS to return saves 
one byte of code.

The code above could actually be further optimized by PULS X,Y,PC.

Cheers.

Phill.

-- 
Phill Harvey-Smith, Programmer, Hardware hacker, and general eccentric !

"You can twist perceptions, but reality won't budge" -- Rush.



More information about the Coco mailing list