[Coco] Linville's ramblings on assembly vs machine code

Robert Gault robert.gault at att.net
Mon Jul 10 17:34:01 EDT 2017


Dave Philipsen wrote:
><snip>
> I was talking with someone once about pushing and pulling registers to/from the stack on the 6809.
> He had a concern about how one particular disassembler represented the order in which a list of
> registers would be pushed or pulled.  From the point of view of someone who worked purely with
> assembly mnemonics and never even bothered to look at the machine codes that had been assembled,
> this might be a valid question.  Does it matter how you order the registers when you push or pull
> them? (i.e. is pshs  a,b,x,y different than pshs y,x,b,a ?)
> If when you learned assembler you at least got a taste of how it relates to machine code you would
> know right away that it matters not because each of the registers to be pushed or pulled is
> represented by a single bit in a post code byte that follows the opcode.  The processor will always
> push or pull the registers in the same order regardless of how you write it in assembler.  So to
> answer the question: no, pshs a,b,x,y is not any different than pshs y,x,b,a.
>
><snip>

Well, here is at least one exception that proves the rule. :)

It makes a very big difference what order the stacking process takes place! You can easily find 
examples in the Coco code where a stack has been pushed and depending on the following code, the 
contents of the stack was changed and then eventually pulled.
If you don't know where a particular register was placed on the stack, then you won't know where 
that value is located so it can be changed.

One example of this issue occurs when you replace a 6809 with a 6309 and try to work in native mode. 
The NMI routine in DOS1.1 is
DNMISV	LDA	NMIFLAG
	BEQ	LD7BB
	LDX	DNMIVC
	STX	10,S
	CLR	NMIFLG
LD7BB	RTI

The above works with a 6809 or a 6309 in emulation mode. With a 6309 in native mode, the code needs 
to be
	STX	12,S
as the stacking is changed.

Robert




More information about the Coco mailing list