6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Sun Nov 10, 2024 4:06 pm

All times are UTC




Post new topic Reply to topic  [ 28 posts ]  Go to page 1, 2  Next
Author Message
PostPosted: Sun Aug 18, 2013 6:18 pm 
Offline
User avatar

Joined: Thu May 28, 2009 9:46 pm
Posts: 8479
Location: Midwestern USA
I'm working on a 65C816 interrupt sequel to Garth's interrupt primer and in one of the code examples I use PEA to illustrate how to construct a stack frame. For reasons that completely elude me, I started thinking about PEA and whether or not it should be considered an immediate mode instruction.

For the edification of anyone who is not familiar with the 65C816-specific instructions, PEA is used as follows:


Code:
          pea operand

where OPERAND is a 16-bit value. Despite PEA meaning Push Effective Address, OPERAND can have whatever significance the programmer wants—the '816 doesn't evaluate it for any kind of meaning. All PEA does is push OPERAND to the stack, most significant byte, followed by least significant byte, the same as doing:

Code:
         rep #%00100000        ;16 bit accumulator
         lda #operand
         pha

So here I am thinking that PEA is really an immediate mode instruction, as the data upon which it acts is OPERAND, and really should be coded as:

Code:
          pea #operand

So, is it is, or is it ain't?

_________________
x86?  We ain't got no x86.  We don't NEED no stinking x86!


Top
 Profile  
Reply with quote  
PostPosted: Sun Aug 18, 2013 7:13 pm 
Offline
User avatar

Joined: Mon Apr 23, 2012 12:28 am
Posts: 760
Location: Huntsville, AL
BDD:

Just my two cents.

I would like to write it as JMP OPERAND if operand referred to a label to a variable or subroutine. In this case, I would expect that the assembler inserts into the output is the address of the variable or subroutine. On the other hand, if operand refers to a constant, I would like to write it as JMP #OPERAND.

I agree that instruction is the same in either case. However, I believe that the programmer should be able to convey the intent, pushing an address or pushing a constant, by being able to use either the syntax for absolute direct addresses or immediate operands.

_________________
Michael A.


Top
 Profile  
Reply with quote  
PostPosted: Sun Aug 18, 2013 7:15 pm 
Offline
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8538
Location: Southern California
I always thought that was strange too. I suppose that if the A, I, and R in PEA, PEI, and PER stand for "absolute," "indirect," and "relative," they used "absolute" instead of "immediate" so the I wouldn't conflict with "indirect."

Quote:
All PEA does is push OPERAND to the stack, most significant byte, followed by least significant byte, the same as doing:
Code:
         rep #%00100000        ;16 bit accumulator
         lda #operand
         pha

except that PEA does not affect A or P.

_________________
http://WilsonMinesCo.com/ lots of 6502 resources
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?


Top
 Profile  
Reply with quote  
PostPosted: Sun Aug 18, 2013 7:19 pm 
Offline
User avatar

Joined: Fri Aug 30, 2002 9:02 pm
Posts: 1746
Location: Sacramento, CA
Hi BDD,

I agree PEA acts on the operand as an immediate value. However, it is always a 16 bit value and using the # symbol might lead to confusion depending upon the M flag being in 16-bit mode or 8-bit mode. Since PEA only has one type of addressing mode, I would just leave it as "PEA operand". Just my opinion.

Daryl

_________________
Please visit my website -> https://sbc.rictor.org/


Top
 Profile  
Reply with quote  
PostPosted: Sun Aug 18, 2013 7:45 pm 
Offline
User avatar

Joined: Thu May 28, 2009 9:46 pm
Posts: 8479
Location: Midwestern USA
GARTHWILSON wrote:
Quote:
All PEA does is push OPERAND to the stack, most significant byte, followed by least significant byte, the same as doing:
Code:
         rep #%00100000        ;16 bit accumulator
         lda #operand
         pha

except that PEA does not affect A or P.

True, as is the case with all of the push instructions. Speaking about affecting the status register, I find it a bit annoying that PLB and PLD affect both N and Z.

_________________
x86?  We ain't got no x86.  We don't NEED no stinking x86!


Top
 Profile  
Reply with quote  
PostPosted: Mon Aug 19, 2013 1:55 pm 
Offline

Joined: Sun Nov 08, 2009 1:56 am
Posts: 410
Location: Minnesota
I noticed this as well - probably along with every other writer of 65816 assemblers. The official syntax of PEA and PEI does seem inconsistent with what they actually do, given the syntax of the original 6502 instructions. I resolved it by providing both the official syntax and alternate address modes which are consistent with what they do. Quite simple because it amounts to just a couple of extra table entries that generate the same opcodes.

So in HXA it's possible to write

Code:
 PEA $1234  ; absolute (standard)
 PEA #$1234 ; immediate (unofficial)
 PEI ($12)  ; direct indirect (standard)
 PEI $12    ; direct (unofficial)


The usual caveat that the unofficial address modes are not portable, of course.

In a way this is somewhat like the "to 'A' or not" question with regard to accumulator address mode.


Top
 Profile  
Reply with quote  
PostPosted: Mon Aug 19, 2013 5:56 pm 
Offline

Joined: Tue Apr 20, 2010 4:02 pm
Posts: 34
Alhough on 65816 there does not seem to be such instruction, on some other CPUs is LEA instruction (Leave Effective Address), which calculates the address and stores it in some register. PEA is then alternative, that pushes it the same address directly on the stack.

The logic seems same on 65816, even if it does not have the LEA instruction.

I would probably leave the PEA as it is and add some version of push instruction instead (PHW - PusH Word).


Top
 Profile  
Reply with quote  
PostPosted: Mon Aug 19, 2013 7:12 pm 
Offline
User avatar

Joined: Thu May 28, 2009 9:46 pm
Posts: 8479
Location: Midwestern USA
rudla.kudla wrote:
Alhough on 65816 there does not seem to be such instruction, on some other CPUs is LEA instruction (Leave Effective Address), which calculates the address and stores it in some register. PEA is then alternative, that pushes it the same address directly on the stack.

The logic seems same on 65816, even if it does not have the LEA instruction.

I would probably leave the PEA as it is and add some version of push instruction instead (PHW - PusH Word).

PHW would make more sense, to me at least, than PEA, since PEA's operand can be anything that will resolve to 16 bits. Of course, there is no PLW to reverse the process... :?


teamtempest wrote:
Code:
         PEI $12               ;direct (unofficial)


That actually makes more sense than:

Code:
         PEI ($12)             ;indirect (official)

since the instruction pushes the word stored at $12-$13, and not the content of an address stored at $12-$13.

_________________
x86?  We ain't got no x86.  We don't NEED no stinking x86!


Top
 Profile  
Reply with quote  
PostPosted: Mon Aug 19, 2013 9:12 pm 
Offline
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8538
Location: Southern California
The 6809 uses LEA for "Load Effective Address," and then adds a letter to tell where. Anyway, PHA, PHX, and PHY push words if you have them in 16-bit mode; so PHW could be rather ambiguous.

The programming manual says,
Quote:
The 65802 and the 65816 provide three instructions which push, not registers, but absolute, indirect, and relative addresses straight onto the stack. These three instructions are PEA, PEI, and PER, the push effective address instructions.

[emphasis added] meaning the "A" stands for "absolute," not "address," and, as the manual further says, it could be anything. If 65-family mnemonics had four letters, all three of these would add an "A" at the end for "address."

Quote:
teamtempest wrote:
Code:
         PEI $12               ;direct (unofficial)


That actually makes more sense than:

Code:
         PEI ($12)             ;indirect (official)

since the instruction pushes the word stored at $12-$13, and not the content of an address stored at $12-$13.

I would say that pushing the content of an address stored at $12-$13 would make it a double indirect. I think the PEI as an indirect makes perfect sense because it is indeed that-- an indirect. It does not push a $12, but rather gets its data to push by reading the contents of address $12 & 13.

_________________
http://WilsonMinesCo.com/ lots of 6502 resources
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?


Top
 Profile  
Reply with quote  
PostPosted: Tue Aug 20, 2013 2:45 am 
Offline

Joined: Sun Nov 08, 2009 1:56 am
Posts: 410
Location: Minnesota
Quote:
I would say that pushing the content of an address stored at $12-$13 would make it a double indirect. I think the PEI as an indirect makes perfect sense because it is indeed that-- an indirect. It does not push a $12, but rather gets its data to push by reading the contents of address $12 & 13.


Isn't that rather like claiming "LDA $12" is also an indirect address mode, since it get its data by reading the contents of $12?


Top
 Profile  
Reply with quote  
PostPosted: Tue Aug 20, 2013 4:34 am 
Offline
User avatar

Joined: Thu May 28, 2009 9:46 pm
Posts: 8479
Location: Midwestern USA
teamtempest wrote:
Quote:
I would say that pushing the content of an address stored at $12-$13 would make it a double indirect. I think the PEI as an indirect makes perfect sense because it is indeed that-- an indirect. It does not push a $12, but rather gets its data to push by reading the contents of address $12 & 13.

Isn't that rather like claiming "LDA $12" is also an indirect address mode, since it get its data by reading the contents of $12?

Lessee...LDA $12 is zero page (or direct page) addressing (page 298 in the WDC programming manual). LDA ($12) on a 65C02 or 65C816 is called "Direct Page Indirect Addressing" in the WDC programming manual (page 302). Double indirection would imply that the value that is pointed to by a pointer that is pointed to by a pointer is being read, but DP indirect addressing is only one level of indirection, since the address on the DP location points to the actual data. :? :? :?

It would seem to make sense to say PEI ($12) would be indirect if the 16 bit value pushed to the stack were in fact read from an address stored at $12-$13, but that isn't what the instruction does—it reads the value stored at $12-$13 and pushes it, nothing more. So using the terminology in the manual, PEI appears to use direct page addressing and perhaps should be coded as PEI $12.

If the previous is true, perhaps PEA $1234 should really be written PEA #$1234. :? :? :?

_________________
x86?  We ain't got no x86.  We don't NEED no stinking x86!


Top
 Profile  
Reply with quote  
PostPosted: Tue Aug 20, 2013 5:17 am 
Offline
User avatar

Joined: Sun Jun 30, 2013 10:26 pm
Posts: 1948
Location: Sacramento, CA, USA
BigDumbDinosaur wrote:
[snip] ... If the previous is true, perhaps PEA $1234 should really be written PEA #$1234. :? :? :?


This is how my 65m32 handles operands that are to be used at "face-value", regardless of the value's intended future use. I originally wanted to call the equivalent to the 6502's immediate mode "direct" for the 65m32, and the equivalent to the 6502's absolute mode "indirect" for the 65m32, because to me they state the nature of the operand more accurately. A direct operand value is to be used "directly", and an "indirect" operand value is to be used as a pointer to the direct value. I decided to keep the 6502 nomenclature, to avoid the inevitable confusion that would be caused, because the "direct" and "indirect" terms are already defined as something with an additional level of indirection in the 6502 world.

Treating the instruction pointer as "just another" register that happens to be used by the instruction fetch mechanism allows the native 65m32 instruction ldn #$4321 to be the equivalent of the 6502's jmp $4321, and ldn $5432,x to be the equivalent of the 65c02's jmp ($5432,x). Out of respect for the 6502's influence on my design, I would like to allow both forms of these instructions in my assembler ... if I ever find the time to write it!

Mike


Top
 Profile  
Reply with quote  
PostPosted: Tue Aug 20, 2013 5:22 am 
Offline

Joined: Sat Oct 20, 2012 8:41 pm
Posts: 87
Location: San Diego
Here is how WDC explains it.
Taken from the programming manual:

PEA
Although the mnemonic suggests that the sixteen-bit value pushed on the stack be considered an
address, the instruction may also be considered a “push sixteen-bit immediate data” instruction, although the
syntax of immediate addressing is not used. The assembler syntax is that of the absolute addressing mode, that
is, a label or sixteen-bit value in the operand field. Unlike all other instructions that use this assembler syntax,
the effective address itself, rather than the data stored at the effective address, is what is accessed (and in this
case, pushed onto the stack).

PEI
The assembler syntax is that of direct page indirect; however, unlike other instructions which
use this assembler syntax, the effective indirect address, rather than the data stored at that address, is
what is accessed and pushed onto the stack.


Top
 Profile  
Reply with quote  
PostPosted: Tue Aug 20, 2013 5:42 am 
Offline
User avatar

Joined: Thu May 28, 2009 9:46 pm
Posts: 8479
Location: Midwestern USA
clockpulse wrote:
Here is how WDC explains it.
Taken from the programming manual:

PEA
Although the mnemonic suggests that the sixteen-bit value pushed on the stack be considered an
address, the instruction may also be considered a “push sixteen-bit immediate data” instruction, although the
syntax of immediate addressing is not used. The assembler syntax is that of the absolute addressing mode, that
is, a label or sixteen-bit value in the operand field. Unlike all other instructions that use this assembler syntax,
the effective address itself, rather than the data stored at the effective address, is what is accessed (and in this
case, pushed onto the stack).

PEI
The assembler syntax is that of direct page indirect; however, unlike other instructions which
use this assembler syntax, the effective indirect address, rather than the data stored at that address, is
what is accessed and pushed onto the stack.

Yeppers, and effectively supporting my notion that PEA $1234 should really be PEA #$1234, and PEI ($12) should really be PEI $12. :lol:

I guess it all falls on the heads of the folks who write the assemblers...

_________________
x86?  We ain't got no x86.  We don't NEED no stinking x86!


Top
 Profile  
Reply with quote  
PostPosted: Tue Aug 20, 2013 5:42 am 
Offline
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8538
Location: Southern California
Quote:
If the previous is true, perhaps PEA $1234 should really be written PEA #$1234. :? :? :?

I think so, but there's the matter of going against what's already established being something that will cause confusion and require more changes to go from one assembler to another. <sigh>

Quote:
Here is how WDC explains it.
Taken from the programming manual:

PEA
Although the mnemonic suggests that the sixteen-bit value pushed on the stack be considered an
address, the instruction may also be considered a “push sixteen-bit immediate data” instruction, although the
syntax of immediate addressing is not used. The assembler syntax is that of the absolute addressing mode, that
is, a label or sixteen-bit value in the operand field.

and I could see that earlier in the manual and it sort of makes sense (because "absolute" is always 16 bits regardless of selected register size); but it's still something you just have to remember.

Quote:
I would like to allow both forms of these instructions in my assembler ... if I ever find the time to write it!

I would probably put both in the Forth assembler in my Forth kernel, but I won't be able to write that until there's a regular assembler. Although it won't be free, what you could do to save a lot of time and end up with a nice macro assembler is to get Cross-32 from Data Sync Engineering for $99. It comes with the tables for 50 different processors and the info you need to make up your own for a new processor.

_________________
http://WilsonMinesCo.com/ lots of 6502 resources
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 28 posts ]  Go to page 1, 2  Next

All times are UTC


Who is online

Users browsing this forum: No registered users and 14 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: